2121RED = 0xC02020
2222BORDER = 0xFC0000
2323
24+ PAGES = 2
25+
2426IO1 = Pin (1 , Pin .OUT )
2527IO2 = Pin (2 , Pin .OUT )
2628uart1 = UART (1 , baudrate = 115200 , tx = 43 , rx = 44 )
2729uart2 = UART (2 , baudrate = 115200 , tx = 17 , rx = 18 )
2830
31+ BTNA = Button (64 , 248 , 64 , 32 , "A" , lambda : left ())
32+ BTNB = Button (192 , 248 , 64 , 32 , "B" , lambda : right ())
33+
2934B10058399 = Button (32 , 8 , 120 , 48 , "10058399" , lambda : press (IO2 ))
3035B10058400 = Button (32 + 136 , 8 , 120 , 48 , "10058400" , lambda : press (IO1 ))
3136B10058401 = Button (32 , 8 + 64 , 120 , 48 , "10058401" , lambda : swipe (uart1 , "10058401" , None ))
32- C1357 = Button (32 + 136 , 8 + 64 , 120 , 48 , "1357#" , lambda : keypad (uart1 , "1357" ))
33- B10058402 = Button (32 , 8 + 128 , 256 , 48 , "10058402 + 7531#" , lambda : swipe (uart2 , "10058402" , "7531" ))
37+ C1357 = Button (32 + 136 , 8 + 64 , 120 , 48 , "1357#" , lambda : keypad (uart1 , "1357# " ))
38+ B10058402 = Button (32 , 8 + 128 , 256 , 48 , "10058402 + 7531#" , lambda : swipe (uart2 , "10058402" , "7531# " ))
3439LMSG = Label (0 , 216 , 320 , 24 , "" )
3540
41+ KEY1 = Button (20 , 1 , 52 , 44 , "1" , lambda : keypad (uart1 , '1' ))
42+ KEY2 = Button (88 , 1 , 52 , 44 , "2" , lambda : keypad (uart1 , '2' ))
43+ KEY3 = Button (156 , 1 , 52 , 44 , "3" , lambda : keypad (uart1 , '3' ))
44+ KEY4 = Button (20 , 55 , 52 , 44 , "4" , lambda : keypad (uart1 , '4' ))
45+ KEY5 = Button (88 , 55 , 52 , 44 , "5" , lambda : keypad (uart1 , '5' ))
46+ KEY6 = Button (156 , 55 , 52 , 44 , "6" , lambda : keypad (uart1 , '6' ))
47+ KEY7 = Button (20 , 110 , 52 , 44 , "7" , lambda : keypad (uart1 , '7' ))
48+ KEY8 = Button (88 , 110 , 52 , 44 , "8" , lambda : keypad (uart1 , '8' ))
49+ KEY9 = Button (156 , 110 , 52 , 44 , "9" , lambda : keypad (uart1 , '9' ))
50+ STAR = Button (20 , 165 , 52 , 44 , "*" , lambda : keypad (uart1 , '*' ))
51+ KEY0 = Button (88 , 165 , 52 , 44 , "0" , lambda : keypad (uart1 , '0' ))
52+ HASH = Button (156 , 165 , 52 , 44 , "#" , lambda : keypad (uart1 , '#' ))
53+ SWIPE = Button (220 , 16 , 88 , 64 , "SWIPE" ,lambda : swipe (uart1 , "10058400" , None ))
54+
3655touched = None
3756message = None
57+ page = 1
3858
59+ page1 = [ B10058399 , B10058400 , B10058401 , B10058402 , C1357 ]
60+ page2 = [ KEY1 , KEY2 , KEY3 , KEY4 , KEY5 , KEY6 , KEY7 , KEY8 , KEY9 , STAR , KEY0 , HASH , SWIPE ]
3961
4062def setup ():
4163 global IO1 , IO2
@@ -46,20 +68,25 @@ def setup():
4668 # Power.setExtOutput(True)
4769
4870def screen ():
71+ global page
72+
4973 Widgets .setRotation (1 )
5074 Widgets .fillScreen (BLACK )
51- button (B10058399 )
52- button (B10058400 )
53- button (B10058401 )
54- button (B10058402 )
55- button (C1357 )
5675 label (LMSG )
5776
77+ if page == 1 :
78+ for b in page1 :
79+ button (b )
80+
81+ if page == 2 :
82+ for b in page2 :
83+ button (b )
5884
5985def button (b ):
60- offset = int (b .w / 2 - 12 * len (b .label ) / 2 )
86+ xoffset = int (b .w / 2 - 12 * len (b .label ) / 2 )
87+ yoffset = int (b .h / 2 - 6 )
6188 Widgets .Rectangle (b .x , b .y , b .w , b .h , BORDER , BACKGROUND )
62- Widgets .Label (b .label , b .x + offset , b .y + 14 , 1.0 , BLACK , BACKGROUND , Widgets .FONTS .DejaVu18 )
89+ Widgets .Label (b .label , b .x + xoffset , b .y + yoffset , 1.0 , BLACK , BACKGROUND , Widgets .FONTS .DejaVu18 )
6390
6491
6592def label (l ):
@@ -109,7 +136,7 @@ def swipe(uart, card, code):
109136
110137def keypad (uart , code ):
111138 display ("" )
112- uart .write (f"CODE { code } # \n " )
139+ uart .write (f"CODE { code } \n " )
113140
114141 return read (uart )
115142
@@ -146,11 +173,24 @@ def read(uart):
146173 return False
147174
148175
176+ def left ():
177+ global page
178+ print ("LEFT" )
179+ if page > 1 :
180+ page = page - 1
181+ screen ()
182+
183+ def right ():
184+ global page
185+ print ("RIGHT" )
186+ if page < PAGES :
187+ page = page + 1
188+ screen ()
189+
149190def display (msg ):
150191 global message
151192 message .setText (f"%-128s" % f"{ msg } " )
152193
153-
154194def loop ():
155195 global touched
156196
@@ -169,25 +209,40 @@ def loop():
169209 touched = Point (point [0 ], point [1 ], now )
170210
171211 if dt > 250 or abs (dx ) > 10 or abs (dy ) > 10 :
172- if pressed (B10058399 ):
212+ if pressed (BTNA ):
213+ BTNA .pressed ()
214+
215+ if pressed (BTNB ):
216+ BTNB .pressed ()
217+
218+ if page == 1 and pressed (B10058399 ):
173219 if B10058399 .pressed ():
174220 Speaker .tone (784 , 125 ) # G5
175221
176- if pressed (B10058400 ):
222+ if page == 1 and pressed (B10058400 ):
177223 if B10058400 .pressed ():
178224 Speaker .tone (698 , 125 ) # F5
179225
180- if pressed (B10058401 ):
226+ if page == 1 and pressed (B10058401 ):
181227 if B10058401 .pressed ():
182228 Speaker .tone (880 , 125 ) # A5
183229
184- if pressed (B10058402 ):
230+ if page == 1 and pressed (B10058402 ):
185231 if B10058402 .pressed ():
186232 Speaker .tone (1046 , 125 ) # C6'ish
187233
188- if pressed (C1357 ):
234+ if page == 1 and pressed (C1357 ):
189235 if C1357 .pressed ():
190236 Speaker .tone (1174 , 125 ) # D6'ish
237+
238+ if page == 2 :
239+ for b in page2 :
240+ if pressed (b ):
241+ if b .pressed ():
242+ Speaker .tone (784 , 125 ) # G5
243+ break
244+
245+
191246 else :
192247 release ()
193248
0 commit comments