Skip to content

Commit

Permalink
Add M5Stack Basic Eth
Browse files Browse the repository at this point in the history
  • Loading branch information
s-hadinger committed Feb 12, 2024
1 parent 04f3739 commit 3cf3b99
Show file tree
Hide file tree
Showing 4 changed files with 134 additions and 0 deletions.
3 changes: 3 additions & 0 deletions raw/esp32/M5Stack_Basic_ETH/autoexec.be
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# import virtual Touch Screen with 3 buttons
import lv_touch_3_buttons

34 changes: 34 additions & 0 deletions raw/esp32/M5Stack_Basic_ETH/display.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
:H,ILI9341,320,240,16,SPI,1,*,*,*,*,*,*,*,40
:B,30,1
:I
EF,3,03,80,02
CF,3,00,C1,30
ED,4,64,03,12,81
E8,3,85,00,78
CB,5,39,2C,00,34,02
F7,1,20
EA,2,00,00
C0,1,23
C1,1,10
C5,2,3e,28
C7,1,86
36,1,48
37,1,00
3A,1,55
B1,2,00,18
B6,3,08,82,27
F2,1,00
26,1,01
E0,0F,0F,31,2B,0C,0E,08,4E,F1,37,07,10,03,0E,09,00
E1,0F,00,0E,14,03,11,07,31,C1,48,08,0F,0C,31,36,0F
11,80
29,80
:o,28
:O,29
:A,2A,2B,2C
:R,36
:0,08,00,00,00
:1,68,00,00,01
:2,C8,00,00,02
:3,A8,00,00,03
#
4 changes: 4 additions & 0 deletions raw/esp32/M5Stack_Basic_ETH/init.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Template {"NAME":"M5stack Basic Eth","GPIO":[6210,1,1,1,6720,1,1,1,1,5536,768,1,1,1,736,672,0,640,608,704,0,3872,5568,800,0,0,0,0,992,1024,5600,0,0,7650,7649,7648],"FLAG":0,"BASE":1}
Module 0
EthType 8

93 changes: 93 additions & 0 deletions raw/esp32/M5Stack_Basic_ETH/lv_touch_3_buttons.be
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
# 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.GPIO_INPUT, 0), gpio.pin(gpio.GPIO_INPUT, 1), gpio.pin(gpio.GPIO_INPUT, 2)`
#
# Pre-condition:
# LVGL must be already started
def init(btn1, btn2, btn3, active_low)
import global
if !global.contains("lv") return end # abort if LVGL is not there
lv.start() # make sure LVGL is started, or things can go really wrong

# 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]

# add self to drivers
tasmota.add_driver(self)
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(gpio.pin(gpio.GPIO_INPUT, 0), gpio.pin(gpio.GPIO_INPUT, 1), gpio.pin(gpio.GPIO_INPUT, 2), true)

#-
lv_btn3 = lv_touch_3_buttons(gpio.pin(gpio.GPIO_INPUT, 0), gpio.pin(gpio.GPIO_INPUT, 1), gpio.pin(gpio.GPIO_INPUT, 2), lv_touch_3_buttons.ACTIVE_LOW)
tasmota.add_driver(lv_btn3)
-#

0 comments on commit 3cf3b99

Please sign in to comment.