2021-09-09 19:32:19 +01:00
|
|
|
#- LVGL lv_clock_icon
|
|
|
|
-
|
|
|
|
--#
|
|
|
|
|
2021-10-15 18:34:37 +01:00
|
|
|
class lv_clock_icon: lv.label
|
2021-09-09 19:32:19 +01:00
|
|
|
var hour, minute, sec
|
|
|
|
|
|
|
|
def init(parent, copy)
|
|
|
|
super(self).init(parent, copy)
|
|
|
|
var f_s7_16 = lv.seg7_font(16)
|
2021-10-02 08:33:59 +01:00
|
|
|
if f_s7_16 != nil self.set_style_text_font(f_s7_16, lv.PART_MAIN | lv.STATE_DEFAULT) end
|
2021-09-09 19:32:19 +01:00
|
|
|
|
|
|
|
if parent != nil
|
|
|
|
var parent_height = parent.get_height()
|
|
|
|
|
|
|
|
self.set_text("--:--")
|
2021-10-02 08:33:59 +01:00
|
|
|
self.refr_size()
|
2021-09-09 19:32:19 +01:00
|
|
|
var w = self.get_width()
|
|
|
|
self.set_y((parent.get_height() - self.get_height()) / 2) # center vertically
|
|
|
|
|
2021-10-02 08:33:59 +01:00
|
|
|
var pad_right = parent.get_style_pad_right(lv.PART_MAIN | lv.STATE_DEFAULT)
|
2021-09-09 19:32:19 +01:00
|
|
|
self.set_x(parent.get_width() - w - pad_right - 3)
|
2021-10-02 08:33:59 +01:00
|
|
|
parent.set_style_pad_right(pad_right + w + 6, lv.PART_MAIN | lv.STATE_DEFAULT)
|
2021-09-09 19:32:19 +01:00
|
|
|
|
2021-10-15 18:34:37 +01:00
|
|
|
self.set_style_bg_color(lv.color(lv.COLOR_BLACK), lv.PART_MAIN | lv.STATE_DEFAULT)
|
2021-09-09 19:32:19 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
tasmota.add_driver(self)
|
|
|
|
end
|
|
|
|
|
|
|
|
def set_time(hour, minute, sec)
|
|
|
|
import string
|
|
|
|
if hour != self.hour || minute != self.minute || sec != self.sec
|
|
|
|
var txt = string.format("%02d%s%02d", hour, sec % 2 ? ":" : " ", minute)
|
|
|
|
self.hour = hour
|
|
|
|
self.minute = minute
|
|
|
|
self.sec = sec
|
|
|
|
#if txt[0] == '0' txt = '!' .. string.split(txt,1)[1] end # replace first char with '!'
|
|
|
|
self.set_text(txt)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def every_second()
|
|
|
|
var now = tasmota.time_dump(tasmota.rtc()['local'])
|
|
|
|
if now['year'] != 1970
|
|
|
|
self.set_time(now['hour'], now['min'], now['sec'])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def del()
|
|
|
|
super(self).del()
|
|
|
|
tasmota.remove_driver(self)
|
|
|
|
end
|
|
|
|
end
|