# @name Clock_XL # @desc Big pixel clock HH:MM with 12/24h format, day/night mode, brightness and rotation control # @author Avemer # @version 1.3 # @config blink_colon bool "Blink colon" default=true # @config hour_format select "Hour format" default=24 options=24,12 # @config clock_color color "Day clock color" default=#FFFFFF # @config day_brightness slider "Day brightness" default=127 min=1 max=255 # @config day_auto_brightness bool "Day auto brightness" default=false # @config night_mode bool "Night mode" default=true # @config night_start text "Night start" default="23:00" maxlen=5 # @config night_end text "Night end" default="08:00" maxlen=5 # @config night_color color "Night clock color" default=#FF0000 # @config night_brightness slider "Night brightness" default=1 min=0 max=255 # @config night_auto_brightness bool "Night auto brightness" default=false # @config night_rotation bool "Disable rotation at night" default=true class BigClock var BLINK_COLON var HOUR_FORMAT var CLOCK_COLOR var NIGHT_MODE_ENABLED var NIGHT_START var NIGHT_END var NIGHT_CLOCK_COLOR var DAY_BRIGHTNESS var NIGHT_BRIGHTNESS var DAY_AUTO_BRIGHTNESS var NIGHT_AUTO_BRIGHTNESS var NIGHT_ROTATION_ENABLED var night_start_m var night_end_m var night_mode var last_night_mode # INITIALIZATION def init() self.BLINK_COLON = store.get("blink_colon") # Keep hour format as string. # The select config returns "12" or "24". self.HOUR_FORMAT = str(store.get("hour_format")) # Fallback if the saved value is invalid. if self.HOUR_FORMAT != "12" && self.HOUR_FORMAT != "24" self.HOUR_FORMAT = "24" end self.CLOCK_COLOR = store.get("clock_color") self.DAY_BRIGHTNESS = store.get("day_brightness") self.DAY_AUTO_BRIGHTNESS = store.get("day_auto_brightness") self.NIGHT_MODE_ENABLED = store.get("night_mode") self.NIGHT_START = store.get("night_start") self.NIGHT_END = store.get("night_end") self.NIGHT_CLOCK_COLOR = store.get("night_color") self.NIGHT_BRIGHTNESS = store.get("night_brightness") self.NIGHT_AUTO_BRIGHTNESS = store.get("night_auto_brightness") self.NIGHT_ROTATION_ENABLED = store.get("night_rotation") self.night_start_m = self.parse_min( self.NIGHT_START, 23 * 60 ) self.night_end_m = self.parse_min( self.NIGHT_END, 8 * 60 ) self.night_mode = 0 self.last_night_mode = -1 end # CONVERT HH:MM TO MINUTES def parse_min(txt, dflt) var m = re.search( "(\\d\\d?):(\\d\\d)", str(txt) ) if m == nil return dflt end var v = num(m[1], 0) * 60 + num(m[2], 0) if v >= 0 && v < 1440 return v end return dflt end # UPDATE NIGHT MODE def update_night_mode() var night = false if self.NIGHT_MODE_ENABLED var hr = num(hour(), -1) var mi = num(minute(), -1) if hr < 0 || mi < 0 return end var now = hr * 60 + mi # Same start and end disables Night Mode. if self.night_start_m == self.night_end_m night = false # Normal interval. elif self.night_start_m < self.night_end_m if now >= self.night_start_m && now < self.night_end_m night = true end # Interval crosses midnight. else if now >= self.night_start_m || now < self.night_end_m night = true end end end var new_mode = 0 if night new_mode = 1 end # APPLY SETTINGS ONLY WHEN MODE CHANGES if new_mode != self.last_night_mode self.last_night_mode = new_mode self.night_mode = new_mode # NIGHT MODE if self.night_mode == 1 settings.set( "brightness", self.NIGHT_BRIGHTNESS ) settings.set( "autoBrightness", self.NIGHT_AUTO_BRIGHTNESS ) if self.NIGHT_ROTATION_ENABLED rotation.show() end # DAY MODE else settings.set( "brightness", self.DAY_BRIGHTNESS ) settings.set( "autoBrightness", self.DAY_AUTO_BRIGHTNESS ) if self.NIGHT_ROTATION_ENABLED rotation.resume() end end else self.night_mode = new_mode end # KEEP ROTATION DISABLED DURING NIGHT if self.night_mode if self.NIGHT_ROTATION_ENABLED rotation.pause() end end end # MAIN LOOP def loop() self.update_night_mode() end # DRAW ONE PIXEL def p(x, y) var c = self.CLOCK_COLOR if self.night_mode c = self.NIGHT_CLOCK_COLOR end pixel( x, y + 1, c ) end # DRAW DIGIT def digit(x, n) # 0 if n == 0 self.p(x+1,0) self.p(x+2,0) self.p(x+3,0) self.p(x+4,0) self.p(x,1) self.p(x+5,1) self.p(x,2) self.p(x+5,2) self.p(x,3) self.p(x+5,3) self.p(x,4) self.p(x+5,4) self.p(x,5) self.p(x+5,5) self.p(x+1,6) self.p(x+2,6) self.p(x+3,6) self.p(x+4,6) # 1 elif n == 1 self.p(x+1,1) self.p(x+2,0) self.p(x+2,1) self.p(x+2,2) self.p(x+2,3) self.p(x+2,4) self.p(x+2,5) self.p(x+3,0) self.p(x+3,1) self.p(x+3,2) self.p(x+3,3) self.p(x+3,4) self.p(x+3,5) self.p(x,6) self.p(x+1,6) self.p(x+2,6) self.p(x+3,6) self.p(x+4,6) self.p(x+5,6) # 2 elif n == 2 self.p(x,1) self.p(x+1,0) self.p(x+2,0) self.p(x+3,0) self.p(x+4,0) self.p(x+5,1) self.p(x+5,2) self.p(x+1,3) self.p(x+2,3) self.p(x+3,3) self.p(x+4,3) self.p(x,4) self.p(x,5) self.p(x,6) self.p(x+1,6) self.p(x+2,6) self.p(x+3,6) self.p(x+4,6) self.p(x+5,6) # 3 elif n == 3 self.p(x,1) self.p(x+1,0) self.p(x+2,0) self.p(x+3,0) self.p(x+4,0) self.p(x+5,1) self.p(x+5,2) self.p(x+1,3) self.p(x+2,3) self.p(x+3,3) self.p(x+4,3) self.p(x+5,4) self.p(x+5,5) self.p(x,5) self.p(x+1,6) self.p(x+2,6) self.p(x+3,6) self.p(x+4,6) # 4 elif n == 4 self.p(x,3) self.p(x+1,2) self.p(x+2,1) self.p(x+3,0) self.p(x,4) self.p(x+1,4) self.p(x+2,4) self.p(x+3,4) self.p(x+4,4) self.p(x+5,4) self.p(x+4,0) self.p(x+4,1) self.p(x+4,2) self.p(x+4,3) self.p(x+4,4) self.p(x+4,5) self.p(x+4,6) # 5 elif n == 5 self.p(x,0) self.p(x+1,0) self.p(x+2,0) self.p(x+3,0) self.p(x+4,0) self.p(x+5,0) self.p(x,1) self.p(x,2) self.p(x+1,3) self.p(x+2,3) self.p(x+3,3) self.p(x+4,3) self.p(x+5,4) self.p(x+5,5) self.p(x,6) self.p(x+1,6) self.p(x+2,6) self.p(x+3,6) self.p(x+4,6) # 6 elif n == 6 self.p(x+1,0) self.p(x+2,0) self.p(x+3,0) self.p(x+4,0) self.p(x+5,1) self.p(x,1) self.p(x,2) self.p(x,3) self.p(x,4) self.p(x,5) self.p(x+1,3) self.p(x+2,3) self.p(x+3,3) self.p(x+4,3) self.p(x+5,4) self.p(x+5,5) self.p(x+1,6) self.p(x+2,6) self.p(x+3,6) self.p(x+4,6) # 7 elif n == 7 self.p(x,0) self.p(x+1,0) self.p(x+2,0) self.p(x+3,0) self.p(x+4,0) self.p(x+5,0) self.p(x+5,1) self.p(x+5,2) self.p(x+4,3) self.p(x+3,4) self.p(x+3,5) self.p(x+3,6) # 8 elif n == 8 self.p(x+1,0) self.p(x+2,0) self.p(x+3,0) self.p(x+4,0) self.p(x,1) self.p(x+5,1) self.p(x,2) self.p(x+5,2) self.p(x+1,3) self.p(x+2,3) self.p(x+3,3) self.p(x+4,3) self.p(x,4) self.p(x+5,4) self.p(x,5) self.p(x+5,5) self.p(x+1,6) self.p(x+2,6) self.p(x+3,6) self.p(x+4,6) # 9 elif n == 9 self.p(x+1,0) self.p(x+2,0) self.p(x+3,0) self.p(x+4,0) self.p(x,1) self.p(x+5,1) self.p(x,2) self.p(x+5,2) self.p(x+1,3) self.p(x+2,3) self.p(x+3,3) self.p(x+4,3) self.p(x+5,4) self.p(x+5,5) self.p(x,5) self.p(x+1,6) self.p(x+2,6) self.p(x+3,6) self.p(x+4,6) end end # DRAW COLON def colon(x) var show_colon = true if self.BLINK_COLON if second() % 2 == 1 show_colon = false end end if show_colon self.p(x,1) self.p(x+1,1) self.p(x,2) self.p(x+1,2) self.p(x,4) self.p(x+1,4) self.p(x,5) self.p(x+1,5) end end # MAIN CLOCK DRAWING def draw() clear() var h = hour() var m = minute() # 12 / 24 HOUR FORMAT if self.HOUR_FORMAT == "12" h = h % 12 if h == 0 h = 12 end end # SPLIT HOURS var h1 = int(h / 10) var h2 = h % 10 # SPLIT MINUTES var m1 = int(m / 10) var m2 = m % 10 # DRAW HOURS self.digit(0, h1) self.digit(7, h2) # DRAW COLON self.colon(15) # DRAW MINUTES self.digit(19, m1) self.digit(26, m2) end # BUTTON def on_button(btn) end end return BigClock()