lvgl updates and M5Stack Fire button support

This commit is contained in:
Stephan Hadinger 2022-02-16 22:07:18 +01:00
parent 06c33d34ef
commit de925142b2
4 changed files with 93 additions and 9 deletions

View File

@ -13,7 +13,7 @@
extern int be_ntv_display_start(bvm *vm);
extern int be_ntv_display_dimmer(bvm *vm);
extern void be_ntv_display_touch_update(int32_t touches, int32_t raw_x, int32_t raw_y, int32_t gesture);
BE_FUNC_CTYPE_DECLARE(be_ntv_display_touch_update, "", "iiii[ii]")
BE_FUNC_CTYPE_DECLARE(be_ntv_display_touch_update, "", "iiii")
/* @const_object_info_begin
module display (scope: global) {

View File

@ -93,7 +93,7 @@ tasmota.add_driver(ws)
import lv_tasmota_info
var info = lv_tasmota_info(scr)
info.set_pos(0, stat_line.get_height())
info.set_size(hres - 80, 30)
info.set_size(hres - 80 + 1, 40)
tasmota.add_driver(info)
# logs

View File

@ -0,0 +1,86 @@
# lv_touch_3_buttons
#
# Handles a simple case with 3 physical buttons below the screen, like in M5Stack
#
# LVGL must be already started to get the screen coordinates.
# Touches are simulated as actual touch screen:
# x: is spread at coordinates: 1/6, 1/2, 5/6
# y: 10 pixels from botton
class lv_touch_3_buttons
var gpios # (array) physical GPIO numbers for each button, -1 in not assigned
var x_coords # (array) x coordinates for each button
var y_coords # (array) y coordinates for each button
var active_low # (bool) true if button is active low
# prevous values
var touched, x, y # previous values (bool, int, int) to be repeated when not touched
static ACTIVE_HIGH = false
static ACTIVE_LOW = true
# Arguments:
# Physical GPIOs, generally through `gpio.pin(gpio.INPUT, 0), gpio.pin(gpio.INPUT, 1), gpio.pin(gpio.INPUT, 2)`
#
# Pre-condition:
# LVGL must be already started
def init(btn1, btn2, btn3, active_low)
# set current values
self.x = 0
self.y = 0
self.touched = false
#
self.active_low = active_low
self.gpios = [-1, -1, -1]
# store only valid gpios
btn1 = int(btn1)
if btn1 >= 0 self.gpios[0] = btn1 end
btn2 = int(btn2)
if btn2 >= 0 self.gpios[1] = btn2 end
btn3 = int(btn3)
if btn3 >= 0 self.gpios[2] = btn3 end
# compute coordinates
var hres = lv.get_hor_res()
var vres = lv.get_ver_res() # should be 240
self.x_coords = [ hres / 6, hres / 2, hres * 5 / 6]
self.y_coords = [ vres - 10, vres - 10, vres - 10]
end
# scan every 50ms
def every_50ms()
import display
var i = 0
var x, y
var touched = false # is there any button pressed
while i < size(self.gpios)
var gp = self.gpios[i]
if gp >= 0 # skip invalid gpio
var in = bool(gpio.digital_read(gp))
in = self.active_low ? !in : in # invert if active low
if in && !touched # first button touched
x = self.x_coords[i]
y = self.y_coords[i]
end
touched = touched || in
end
i += 1
end
# if touched, change x/y
if touched
self.x = x
self.y = y
end
self.touched = touched
# return values
display.touch_update(self.touched ? 1 : 0, self.x, self.y, 0)
end
end
return lv_touch_3_buttons
#-
lv_btn3 = lv_touch_3_buttons(gpio.pin(gpio.INPUT, 0), gpio.pin(gpio.INPUT, 1), gpio.pin(gpio.INPUT, 2), lv_touch_3_buttons.ACTIVE_LOW)
tasmota.add_driver(lv_btn3)
-#

View File

@ -9,19 +9,17 @@ class lv_tasmota_info : lv.label
self.set_width(parent.get_width())
self.set_pos(0, 0)
# self.set_style_bg_color(lv.color(0x000000), lv.PART_MAIN | lv.STATE_DEFAULT)
self.set_style_bg_opa(0, lv.PART_MAIN | lv.STATE_DEFAULT)
self.set_style_bg_color(lv.color(0x000000), lv.PART_MAIN | lv.STATE_DEFAULT)
self.set_style_bg_opa(100, lv.PART_MAIN | lv.STATE_DEFAULT)
self.move_background()
# self.set_style_border_opa(255, lv.PART_MAIN | lv.STATE_DEFAULT)
self.set_style_border_opa(255, lv.PART_MAIN | lv.STATE_DEFAULT)
self.set_style_radius(0, lv.PART_MAIN | lv.STATE_DEFAULT)
self.set_style_pad_all(2, lv.PART_MAIN | lv.STATE_DEFAULT)
# self.set_style_border_color(lv.color(0x0099EE), lv.PART_MAIN | lv.STATE_DEFAULT)
self.set_style_border_width(0, lv.PART_MAIN | lv.STATE_DEFAULT)
self.set_style_border_color(lv.color(0x0099EE), lv.PART_MAIN | lv.STATE_DEFAULT)
self.set_style_border_width(1, lv.PART_MAIN | lv.STATE_DEFAULT)
self.set_style_text_color(lv.color(0xFFFFFF), lv.PART_MAIN | lv.STATE_DEFAULT)
self.set_long_mode(lv.LABEL_LONG_CLIP)
# var roboto12 = lv.font_robotocondensed_latin1(12)
# self.set_style_text_font(roboto12, lv.PART_MAIN | lv.STATE_DEFAULT)
var lg_font = lv.font_montserrat(14)
self.set_style_text_font(lg_font, lv.PART_MAIN | lv.STATE_DEFAULT)