Пример #1
0
def Sunrise():
    global LampBusy, StartTime, Index, Status, GlobalSleep
    if(SunriseTime == time.strftime("%H:%M") and LampBusy == 0):
        LampBusy = 1
        StartTime = lampio.getTimeMillis()
    if(LampBusy == 1 and lampio.getTimeDifferenceMillis(StartTime) >= (int(SunriseDuration) * 60000)):
        LampBusy = 0
        StartTime = 0
    if(LampBusy == 1 and Status <= 760):
        Index = int(math.floor(Status/255))
        Color[Index] = (Status%255) + 5
        lampio.setLamp(Color)
        Status += 5
        GlobalSleep = float(SunriseDuration)*60/154
Пример #2
0
def Automatic():
    global LampBusy, StartTime, AutoDuration, Scheduled, GlobalSleep
    if(LampBusy == 0):
        for row in Scheduled:
            line = row.split("/")
            if((line[0] == str(datetime.datetime.today().weekday()) or line[0] == "-1") and line[1] == time.strftime("%H:%M")):
                LampBusy = 1
                StartTime = lampio.getTimeMillis()
                AutoDuration = line[2]
                Color = line[3].split(",")
                lampio.setLamp(Color)
    if(LampBusy == 1 and lampio.getTimeDifferenceMillis(StartTime) >= (int(AutoDuration) * 60000)):
        LampBusy = 0
        StartTime = 0
        AutoDuration = 0
        Color = [0,0,0]
        lampio.setLamp(Color)
    GlobalSleep = 0.8
Пример #3
0
def Sunset():
    global LampBusy, StartTime, Index, Status, GlobalSleep
    GlobalSleep = 0
    if(SunsetStart == 1 and LampBusy == 0):
        LampBusy = 1
        StartTime = lampio.getTimeMillis()
        Index = 0
        Status = 0
        Color[0] = 255
        Color[1] = 255
        Color[2] = 255
        lampio.setLamp(Color)
    if(SunsetStart == 1 and LampBusy == 1 and lampio.getTimeDifferenceMillis(StartTime) >= (int(SunsetDuration) * 60000)):
        lampio.writeFile("sunset_start", "0")
        lampio.writeFile("mode", "0")
        LampBusy = 0
        StartTime = 0
        time.sleep(1)
    if(SunsetStart == 1 and LampBusy == 1 and Status <= 760):
        Index = int(2 - math.floor(Status/255))
        Color[Index] = 250 - Status%255
        lampio.setLamp(Color)
        Status += 5
        GlobalSleep = float(SunsetDuration)*60/154
Пример #4
0
FadingIncColor = 1	#Fading control var
FadingDecColor = 0	#Fading control var
TemperatureMeasured = 0	#Measured temperature
Scheduled = []	#Programmed Auto
Index = 0	#Index of colors
Status = 0  #Status of animation
GlobalSleep = 0.1 #Global sleep time

#    Main program

lampio.setLamp(Color)

while True:

    # Check Mode
    if(lampio.getTimeDifferenceMillis(ElapsedCheckModeTime) >= 1000):
        ElapsedCheckModeTime = lampio.getTimeMillis()
        TempRead = int(lampio.readFile("mode"))
        if(TempRead != Mode):
            lampio.writeFile("sunset_start", "0")
            Mode = TempRead
            LampBusy = 0
            StartTime = 0
            AutoDuration = 0
            Index = 0
            Status = 0
            Color = list(StartColor[Mode])
            lampio.setLamp(Color)
        #Check shutdown
        if(int(lampio.readFile("shutdown")) == 1):
            os.system("sudo shutdown -h now")