def dayNightToggle(buttonRef): if ci.fcmode < ci.FCMODE_NIXIE: ci.fcmode = ci.fcmode + 1 else: ci.fcmode = ci.FCMODE_CLOCK print 'Agggg' print ci.fcmode # if (ci.fcmode == ci.FCMODE_CLOCK): # ....ci.fcmode = ci.FCMODE_NIGHT # elif (ci.fcmode == ci.FCMODE_NIGHT): # ....ci.fcmode = ci.FCMODE_CLOCK # redraw the clock interface ci_clock.clock() # Store this setting (our default clock mode) in the preferences ci_config.preferences['theme'] = ci.fcmode # Save the updated configuration ci_config.savePrefs()
def setMilitaryTime(buttonRef): # print "Set military time" # print buttonRef.currentValue ci_config.preferences['militaryTime'] = buttonRef.currentValue # Save the updated configuration ci_config.savePrefs() # Re-draw the alarm mode initializeScreen()
def setMood(buttonRef): if ci_config.preferences['mood'] < 5: ci_config.preferences['mood'] = ci_config.preferences['mood'] \ + 1 else: ci_config.preferences['mood'] = 0 # # Set N810 LED if present ci_alarm.setLED(*ci.moods[ci_config.preferences['mood']]['color']) # Refresh to redraw the screen initializeScreen() # # Save preferences ci_config.savePrefs()
def disableAlarm(alarmIndex): # Try to grab the alarm in question success = 0 if len(ci_config.alarms) >= alarmIndex: # error check thisAlarm = ci_config.alarms[alarmIndex] if ci_config.preferences['useAlarmD'] == 1: # We want to use AlarmD to manage alarms if int(thisAlarm['alarm_cookie']) > 0: result = clearFlipAlarm(int(thisAlarm['alarm_cookie'])) if result: print 'cleared ok' ci_config.alarms[alarmIndex]['alarm_cookie'] = 0 ci_config.alarms[alarmIndex]['enabled'] = 0 # save the config ci_config.savePrefs() success = 1 else: print 'No alarm for that index found!' # Update "next alarm" incase things have changed ci_alarm.nextAlarmUpToDate(1) return success
def updateCurrentAlarm(showBusy=1, forceUpdate=0): # Enable or disable the alarm # did we succeed? success = 0 # Store the user's prefs in the global alarms array.... # Get the current time for the alarm from the buttons hour1 = screens[ci.FCMODE_ALARM_CONTROL]['buttons']['hours' ].firstDigit.currentValue hour2 = screens[ci.FCMODE_ALARM_CONTROL]['buttons']['hours' ].secondDigit.currentValue min1 = screens[ci.FCMODE_ALARM_CONTROL]['buttons']['minute1' ].currentValue min2 = screens[ci.FCMODE_ALARM_CONTROL]['buttons']['minute2' ].currentValue # Here's the tricky bit... get the timestamp that represents the next time this day of the week will come up, and this time # on that day... # start by getting the current timestamp now = myTime.time() # $today = mktime(0,0,0,date("n", $today), date("j", $today), date("Y", $today)); # dayOnly = myTime.mktime((time.strftime("%Y", now), time # or we could just not care, since we're repeating... # let's get the time, for say, # 1236488400 is Sunday, March 8, 2009 @00:00:00, so let's try that as a base # whoops, sorry should be 1236470400 (Sunday, March 8, 2009 @00:00:00 UTC) + time.timezone (timezone offset of UTC in seconds) # so first, which day of the week are we? Sunday, + current alarm (0-7) times seconds in a day (86400) targetTime = 1236470400 + myTime.timezone + ci.currentAlarmNum \ * 86400 # OKAY WRONG AGAIN! You have to calculate the actual time of the event (i.e. what day it's actually scheduled for) so that # the dst can be accurately determined! # so, try once more... todayTest = myTime.gmtime(myTime.time()) # find out what day of the week it is (where 0 is Monday, Sunday is 6) todayDay = todayTest.tm_wday # modify the struct to point to 00:00:00 today todayTest = ( todayTest.tm_year, todayTest.tm_mon, todayTest.tm_mday, 0, 0, 0, todayTest.tm_wday, todayTest.tm_yday, todayTest.tm_isdst, ) # generate the time at the beginnig of today startToday = calendar.timegm(todayTest) if todayDay == 6: # If it's sunday, then our reference time is dayOffset = 0 else: # otherwise, day offset is whatever day it is dayOffset = todayDay + 1 targetDay = ci.currentAlarmNum - dayOffset if targetDay < 0: # target day is behind us in the week, so we need to jump to next week instead targetTime = startToday + (7 - dayOffset + ci.currentAlarmNum) \ * 86400 else: # target day is ahead of or current day, so we're good targetTime = startToday + targetDay * 86400 targetTime = targetTime + myTime.timezone # now, we add the current time specified # Minutes are always the same, just multiply by 60 seconds extra = (min1 * 10 + min2) * 60 # Get the hours as an int hoursTotal = hour1 * 10 + hour2 # isAMPM.. AM == 1, PM == 0 isAMPM = 1 # now add the hours, which are either am/pm, or 24 hour... let's pretend for the moment there always 24 # don't forget, 3600 seconds in an hour... if ci_config.preferences['militaryTime']: extra = extra + hoursTotal * 3600 # Convert to 12 hour time to store in array if hoursTotal == 0: hoursStr = '12' isAMPM = 1 elif 0 < hoursTotal < 10: hoursStr = '0' + str(hoursTotal) isAMPM = 1 elif 9 < hoursTotal < 13: hoursStr = str(hoursTotal) isAMPM = 1 else: hoursStr = str(hoursTotal) isAMPM = 0 else: # Get the AM/PM setting... AM == 1, PM ==0 ampm = screens[ci.FCMODE_ALARM_CONTROL]['buttons']['ampmSwitch' ].currentValue isAMPM = ampm if hoursTotal == 12 and ampm == 1: # 12 am = 00 hoursTotal = 0 elif hoursTotal == 12 and ampm == 0: # 12pm = 12.. gotta do something, so... hoursTotal = hoursTotal elif ampm == 0: # pm value hoursTotal = 12 + hoursTotal extra = extra + hoursTotal * 3600 # string to store the hours (Always stored in 12 hour format) hoursStr = str(hour1) + str(hour2) # so finally, our target time is targetTime = targetTime + extra # check for DST if myTime.localtime(targetTime).tm_isdst == 1: # DST is active, so adjust time accordingly adjustment = myTime.timezone - myTime.altzone # If DST, subtract the difference of the zones.. targetTime = targetTime - adjustment # original alarm time originalAlarmTime = \ ci_config.alarms[ci.currentAlarmNum]['alarm_time'] # set the alarm propeties ci_config.alarms[ci.currentAlarmNum]['alarm_time'] = targetTime ci_config.alarms[ci.currentAlarmNum]['alarm_hhmm'] = hoursStr \ + str(min1) + str(min2) ci_config.alarms[ci.currentAlarmNum]['ampm'] = isAMPM # what action needs to be taken? action = '' # #Check if update was forced if forceUpdate: if screens[ci.FCMODE_ALARM_CONTROL]['buttons']['alarmSwitch' ].currentValue == 1: action = 'enable' elif screens[ci.FCMODE_ALARM_CONTROL]['buttons']['alarmSwitch' ].currentValue == 0: action = 'disable' if originalAlarmTime != targetTime \ and screens[ci.FCMODE_ALARM_CONTROL]['buttons']['alarmSwitch' ].currentValue == 1: # Alarm should be on, but time has changed so update it! # print "updating alarm" runScreenState('setBusy') action = 'enable' elif screens[ci.FCMODE_ALARM_CONTROL]['buttons']['alarmSwitch' ].currentValue == 1 \ and ci_config.alarms[ci.currentAlarmNum]['enabled'] != 1: # success = ci_alarmD.enableAlarm(ci.currentAlarmNum) # Alarm has been set to enabled, so apply the current settings runScreenState('setBusy') # print "setting alarm req" # enable alarm # success = ci_alarmD.enableAlarm(ci.currentAlarmNum) action = 'enable' elif screens[ci.FCMODE_ALARM_CONTROL]['buttons']['alarmSwitch' ].currentValue == 0 \ and ci_config.alarms[ci.currentAlarmNum]['enabled'] != 0: # disable alarm # print "unsetting alarm req" # runScreenState("setBusy") # success = ci_alarmD.disableAlarm(ci.currentAlarmNum) action = 'disable' if action == 'enable': if showBusy: # show the busy screen runScreenState('setBusy') # Now do the update success = ci_alarmD.enableAlarm(ci.currentAlarmNum) elif action == 'disable': if showBusy: # show the busy screen runScreenState('setBusy') # Now do the update success = ci_alarmD.disableAlarm(ci.currentAlarmNum) else: # No action is required, so assume we succeeded success = 1 if success != 1: # Failed for some reason osso_c = osso.Context('osso_test_note', '0.0.1', False) note = osso.SystemNote(osso_c) result = \ note.system_note_dialog('Failed while attempting to set alarm' , type='notice') screens[ci.FCMODE_ALARM_CONTROL]['buttons']['alarmSwitch' ].currentValue = success screens[ci.FCMODE_ALARM_CONTROL]['buttons']['alarmSwitch' ].drawButton() # handled by enable/disable alarm calls # update the config file since alarm state has changed ci_config.savePrefs() print 'Done alarm update' if showBusy: runScreenState('clearBusy') return success
def enableAlarm(alarmIndex): # Try to grab the alarm in question success = 0 if len(ci_config.alarms) >= alarmIndex: # error check thisAlarm = ci_config.alarms[alarmIndex] if int(thisAlarm['alarm_time']) > 0: if ci_config.preferences['useAlarmD'] == 1: # We want to use alarmD to manage alarms # dispatch alarm to alarmD # first, check to see if this alarm has been set in the past if int(thisAlarm['alarm_cookie']) > 0: clearFlipAlarm(int(thisAlarm['alarm_cookie'])) # Now we set the new alarm returnedCookie = setFlipAlarm(thisAlarm) if returnedCookie < 1: # Failed! print 'Failed to set alarm with alarmD!' else: ci_config.alarms[alarmIndex]['alarm_cookie'] = \ int(returnedCookie) # and now update the prefs array of alarms # ci_config.alarms[alarmIndex]["alarm_cookie"] = returnedCookie ci_config.alarms[alarmIndex]['enabled'] = 1 # save the config ci_config.savePrefs() success = 1 else: # We want to manage alarms internally only (Ciro...this is you buddy) ci_config.alarms[alarmIndex]['enabled'] = 1 # save the config ci_config.savePrefs() success = 1 else: print 'Invalid alarm time, unable to set' else: print 'No alarm for that index found!' # Update "next alarm" incase things have changed ci_alarm.nextAlarmUpToDate(1) return success