Selaa lähdekoodia

Add 'CARDPUTER CircuitPython/projects/ReachTruckApp/code.py'

almost usable, (maybe not practical) - downtime is not currently saved or loaded to a file but i have a headache rn. the file should be a simple log.txt saved to the sd card ("/sd/log.txt") where the entire list is saved to and loaded from at the start and with every edit. on the "view log" page, the system should only show entries that match today's date.  THEN there needs to be another page for viewing the entire log and scrolling through it properly.

also, the rt scanner cant scan barcodes on this screen as i discovered recently. FML. Maybe just tape them to the fucking back of the cardputer hahaha
cube 1 kuukausi sitten
vanhempi
commit
7b9c98a9b3
1 muutettua tiedostoa jossa 359 lisäystä ja 0 poistoa
  1. 359
    0
      CARDPUTER CircuitPython/projects/ReachTruckApp/code.py

+ 359
- 0
CARDPUTER CircuitPython/projects/ReachTruckApp/code.py Näytä tiedosto

@@ -0,0 +1,359 @@
1
+from keyb import Keyboard # type: ignore
2
+import time, os, rtc, json # type: ignore
3
+import board, busio, sdcardio, storage, terminalio, displayio # type: ignore
4
+from adafruit_display_text import label # type: ignore
5
+from adafruit_display_shapes.rect import Rect # type: ignore
6
+
7
+### PAGE FUNCTIONS # # # # # # # # # #
8
+def home():
9
+    title_label.text = "Home"
10
+    title_label.x = 95
11
+    title_label.y = 14
12
+
13
+    page_label.text = """
14
+ESC = DOWNTIME       TAB = SET CLOCK
15
+BACKSP = HERA        SP = RT17
16
+
17
+ENTER NUMBER FOR CHECK DIGITS
18
+    """
19
+    page_label.x = 5
20
+    page_label.y = 30
21
+
22
+    time_label.text = strf_time()
23
+
24
+    input_label.text = ""
25
+    input_label.x = 100
26
+    input_label.y = 120
27
+
28
+# # # # # # # # # # # # # # # # # # 
29
+
30
+
31
+
32
+
33
+
34
+def strf_time():
35
+    r = rtc.RTC()
36
+    current_time = r.datetime
37
+    hour = current_time.tm_hour
38
+    mint = current_time.tm_min
39
+    return str(hour) + ":" + str(mint)
40
+    
41
+def strf_date():
42
+    current_time = r.datetime
43
+    day = current_time.tm_mday
44
+    month = current_time.tm_mon
45
+    year = current_time.tm_year
46
+    return str(day) + "/" + str(month) + "/" + str(year)
47
+    
48
+
49
+
50
+def set_datetime():
51
+    numbers = ["0","1","2","3","4","5","6","7","8","9"]
52
+    cancel = False
53
+    
54
+    title_label.text = "Set Clock"
55
+    title_label.x = 75
56
+    page_label.text = "Enter Hour\n"
57
+    page_label.y = 45
58
+    hour = ""
59
+    while not cancel:
60
+        key = keyb.scan()
61
+        if key in numbers:
62
+            hour += key
63
+            page_label.text += key
64
+        elif key == "\n":
65
+            break
66
+        elif key == "ESC":
67
+            cancel = True
68
+
69
+    page_label.text += "\nEnter Minute\n"
70
+    minute = ""
71
+    while not cancel:
72
+        key = keyb.scan()
73
+        if key in numbers:
74
+            minute += key
75
+            page_label.text += key
76
+        elif key == "\n":
77
+            break
78
+        elif key == "ESC":
79
+            cancel = True
80
+
81
+    page_label.text = "Enter Day\n"
82
+    day = ""
83
+    while not cancel:
84
+        key = keyb.scan()
85
+        if key in numbers:
86
+            day += key
87
+            page_label.text += key
88
+        elif key == "\n":
89
+            break
90
+        elif key == "ESC":
91
+            cancel = True
92
+
93
+    page_label.text = "Enter Month\n"
94
+    month = ""
95
+    while not cancel:
96
+        key = keyb.scan()
97
+        if key in numbers:
98
+            month += key
99
+            page_label.text += key
100
+        elif key == "\n":
101
+            break
102
+        elif key == "ESC":
103
+            cancel = True
104
+
105
+    page_label.text = "Enter Year\n"
106
+    year = ""
107
+    while not cancel:
108
+        key = keyb.scan()
109
+        if key in numbers:
110
+            year += key
111
+            page_label.text += key
112
+        elif key == "\n":
113
+            break
114
+        elif key == "ESC":
115
+            cancel = True
116
+
117
+    if not cancel:
118
+        h = int(hour)
119
+        m = int(minute)
120
+        d = int(day)
121
+        mo = int(month)
122
+        y = int(year)
123
+        r.datetime = time.struct_time((y, mo, d, h, m, 0, 0, -1, -1))
124
+        
125
+    page_label.text = strf_time() + " @ " + strf_date() + "\n(Tab to return)"
126
+
127
+    while True:
128
+        key = keyb.scan()
129
+        if key == "    ":
130
+            home()
131
+            break
132
+
133
+
134
+def get_digits(number):
135
+    cd = "NULL"
136
+
137
+    codes = {"3":"ZMZ",
138
+             "5":"HYT",
139
+             "6":"MRC",
140
+             "9":"DAH",
141
+             "10":"ITQ",
142
+             "14":"PIZ",
143
+             "15":"OIO",
144
+             "16":"GIH",
145
+             "18":"HDS",
146
+             "19":"AIA",
147
+             "20":"ZIJ",
148
+             "21":"FGE",
149
+             "23":"DTX",
150
+             "24":"QQK",
151
+             "26":"KQG",
152
+             "27":"VKW",
153
+             "28":"VZJ",
154
+             "29":"CTK",
155
+             "30":"WMD",
156
+             "32":"ZOR",
157
+             "33":"RQR",
158
+             "34":"LRR",
159
+             "35":"SBA",
160
+             "36":"XVQ",
161
+             "38":"NRX",
162
+             "39":"HCM",
163
+             "40":"MQG"}
164
+    if number in codes:
165
+        cd = codes[number]
166
+
167
+        title_label.text = cd
168
+        title_label.x = 75
169
+        page_label.text = "Check Digits for " + number
170
+        page_label.y = 45
171
+        input_label.text=""
172
+
173
+        while True:
174
+            key = keyb.scan()
175
+            if key == "ESC":
176
+                home()
177
+                break
178
+    else:
179
+        home()
180
+
181
+def show_barcodes(code):
182
+    if code == "RT17":
183
+        bmp = displayio.OnDiskBitmap("/barcodes/RT17.bmp")
184
+    else:
185
+        bmp = displayio.OnDiskBitmap("/barcodes/HERA.bmp")
186
+
187
+    title_label.text = ""
188
+    page_label.text = ""
189
+    tile_grid = displayio.TileGrid(bmp, pixel_shader=bmp.pixel_shader)
190
+    tile_grid.x = 30
191
+    tile_grid.y = 15
192
+    display_group.append(tile_grid)
193
+
194
+    while True:
195
+        key = keyb.scan()
196
+        if key == "ESC":
197
+            display_group.remove(tile_grid)
198
+            home()
199
+            break
200
+
201
+def downtime_page():
202
+    title_label.text = "Downtime"
203
+    title_label.x = 75
204
+    default_page_text = """
205
+ESC = QUIT      OK = VIEW LOG
206
+1) WAITING | 2) PROBLEM | 3) COMFORT
207
+4) OTHER
208
+    """
209
+    default_page_y = 30
210
+
211
+    page_label.text = default_page_text
212
+    page_label.y = default_page_y
213
+
214
+    while True:
215
+        key = keyb.scan()
216
+        if key == "ESC":
217
+            home()
218
+            break
219
+        elif key == "\n":
220
+            page_label.text = ""
221
+            page_label.y = 40
222
+            for entry in downtime:
223
+                dt = entry[0]
224
+                hour = dt.tm_hour
225
+                mint = dt.tm_min
226
+                dt_time = str(hour) + ":" + str(mint)
227
+
228
+                reason = entry[1]
229
+                page_label.text += dt_time + " - " + reason + "\n"
230
+            while True:
231
+                key = keyb.scan()
232
+                if key == "ESC":
233
+                    page_label.text = default_page_text
234
+                    page_label.y = default_page_y
235
+                    break
236
+        elif key == "1" or key == "2" or key == "3":
237
+            if key == "1":
238
+                reason = "WAITING"
239
+            elif key == "2":
240
+                reason = "PROBLEM"
241
+            elif key == "3":
242
+                reason = "COMFORT"
243
+            dt = current_time = r.datetime
244
+            entry = [dt, reason]
245
+            downtime.append(entry)
246
+            page_label.text += "\n\nDowntime Recorded"
247
+            time.sleep(3)
248
+            page_label.text = default_page_text
249
+
250
+
251
+# SET UP SD CARD
252
+spi = busio.SPI(board.SD_SCK, MOSI=board.SD_MOSI, MISO=board.SD_MISO)
253
+cs = board.SD_CS
254
+
255
+try:
256
+    sdcard = sdcardio.SDCard(spi, cs)
257
+    vfs = storage.VfsFat(sdcard)
258
+
259
+    storage.mount(vfs, "/sd") # access files on sd card here
260
+except OSError:
261
+    pass # SD card not inserted/found
262
+
263
+
264
+# SET UP DISPLAY
265
+display = board.DISPLAY
266
+display_group = displayio.Group()
267
+display.root_group = display_group
268
+
269
+# Header Bar
270
+rect = Rect(0, 0, 238, 30, fill=0x1f4476)
271
+display.root_group.append(rect)
272
+
273
+# Page Title
274
+title_font = terminalio.FONT
275
+title_color = 0xffffff
276
+title_label = label.Label(title_font, text="Home", color=title_color, scale=2)
277
+display.root_group.append(title_label)
278
+
279
+# Time Label
280
+time_font = terminalio.FONT
281
+time_color = 0x89a0a8
282
+time_label = label.Label(time_font, text="00:00", color=time_color, scale=1)
283
+time_label.x = 200
284
+time_label.y = 24
285
+display.root_group.append(time_label)
286
+
287
+# IP Label
288
+# ip_font = terminalio.FONT
289
+# ip_color = 0x89a0a8
290
+# ip_label = label.Label(ip_font, text="0.0.0.0", color=ip_color, scale=1)
291
+# ip_label.x = 10
292
+# ip_label.y = 24
293
+# display.root_group.append(ip_label)
294
+
295
+
296
+# Page Text
297
+page_font = terminalio.FONT
298
+page_color = 0xffffff
299
+page_label = label.Label(page_font, text="page_text", color=page_color, scale=1)
300
+display.root_group.append(page_label)
301
+
302
+# Numbers Input Text
303
+input_font = terminalio.FONT
304
+input_color = 0xffffff
305
+input_label = label.Label(input_font, text="", color=input_color, scale=2)
306
+display.root_group.append(input_label)
307
+
308
+home()
309
+
310
+
311
+keyb = Keyboard()
312
+
313
+
314
+
315
+downtime = []
316
+
317
+r = rtc.RTC()
318
+#r.datetime = time.struct_time((2025, 10, 7, 23, 39, 0, 0, -1, -1)) # THIS LINE SETS THE RTC, first is year, then month, then day, then hour, then minute, (rest is unimportant)
319
+#current_time = r.datetime
320
+last_time = "00:00"
321
+
322
+
323
+## PROGRAM MAIN LOOP (WORKS FROM HOME PAGE IF OTHER PAGES HAVE THEIR OWN LOOPS)
324
+numbers = ["0","1","2","3","4","5","6","7","8","9"]
325
+ninput = ""
326
+while True:
327
+    time_label.text = strf_time()
328
+    key = keyb.scan()
329
+    if key == "    ":
330
+        set_datetime()
331
+    elif key == "BACKSP":
332
+        show_barcodes("HERA")
333
+    elif key == " ":
334
+        show_barcodes("RT17")
335
+    elif key in numbers:
336
+        input_label.text += key
337
+        ninput += key
338
+    elif key == "\n":
339
+        get_digits(ninput)
340
+        ninput = ""
341
+    elif key == "ESC":
342
+        downtime_page()
343
+        
344
+    # Homepage Clock
345
+    # current_time = strf_time()
346
+    # if last_time != current_time:
347
+    #     time_label.text = current_time
348
+    #     last_time = current_time
349
+    #time_label.text = strf_time()
350
+
351
+
352
+# IDEA
353
+#
354
+#
355
+#  current move -> move start time, array of intermediate move times like when replenning, end move time (last part of move like pallet store)
356
+# OR just button for every scan with time idk (strf and also actual time format so it can be calculated. )
357
+# then display diff between times in a menu
358
+#
359
+#