-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
231 lines (200 loc) · 4.51 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
import time
import utime
import uselect
import machine
import sys
from sys import stdin, stdout
from machine import I2C, Pin, UART
from lcd_api import LcdApi
from pico_i2c_lcd import I2cLcd
I2C_ADDR = 39
I2C_NUM_ROWS = 2
I2C_NUM_COLS = 16
i2c = I2C(0, sda=machine.Pin(0), scl=machine.Pin(1), freq=400000)
lcd = I2cLcd(i2c, I2C_ADDR, I2C_NUM_ROWS, I2C_NUM_COLS)
resetLetterAddress = 0
nextRowCol = 0
curMenu = 0
curTask = 0
#taskDisplayMode is of the types LOOP, MANUAL, and AUTO
taskDisplayMode = 'LOOP'
button1 = Pin(16, Pin.IN, Pin.PULL_UP)
builtInLed = Pin(25, Pin.OUT)
tasks = []
def displayIntro():
lcd.clear()
lcd.move_to(2,0)
lcd.putstr('Google Tasks')
lcd.move_to(6,1)
lcd.putstr('Pico')
lcd.move_to(15,1)
lcd.putchar(chr(6))
def displayGettingTasks():
lcd.clear()
lcd.move_to(0,0)
lcd.putstr('Getting Tasks')
lcd.move_to(0,1)
lcd.putstr('Please Wait...')
def displayTasks(tasks):
lcd.clear()
lcd.move_to(0,0)
lcd.putstr('Tasks: ' + str(curTask + 1) + ' of ' + str(len(tasks)))
lcd.move_to(0,1)
lcd.putstr(tasks[0])
def displayNextTask(tasks,curTask):
lcd.clear()
lcd.move_to(0,0)
lcd.putstr('Tasks: ' + str(curTask + 1) + ' of ' + str(len(tasks)))
lcd.move_to(0,1)
lcd.putstr(tasks[curTask])
def read_until_end():
builtInLed.toggle()
received_lines = []
while True:
line = sys.stdin.readline() # Read a line from stdin
if not line:
continue # If no line is received, continue the loop
line = line.strip() # Remove leading and trailing whitespace
if line == "end":
break # Stop reading if 'end' is encountered
received_lines.append(line)
builtInLed.toggle()
return received_lines
def getTasks():
#read the task list title form the stdin
#first by writing the command to the stdin to retreive tasks
print('getTasks')
#wait for the response from the pico
time.sleep(1)
print('finished sleep')
print("Ready")
#read the response from the pico
# while there are lines in the std in read all the lines from the stdin
tasks = []
#read the tasks from the pico
tasks = read_until_end()
# select_result = uselect.select([stdin], [], [], 0)
# if(select_result != None):
# while select_result[0]:
# input_character = stdin.readline().rstrip()
# print(input_character)
# #also print the character back to the stdout
print("over here")
if(tasks == []):
tasks = ['No Tasks']
return tasks
#return ['Task 1', 'Task 2', 'Task 3', 'Task 4', 'Task 5']
def customcharacter():
#character
lcd.custom_char(0, bytearray([
0x0E,
0x0E,
0x04,
0x1F,
0x04,
0x0E,
0x0A,
0x0A
]))
#character2
lcd.custom_char(1, bytearray([
0x1F,
0x15,
0x1F,
0x1F,
0x1F,
0x0A,
0x0A,
0x1B
]))
#smiley
lcd.custom_char(2, bytearray([
0x00,
0x00,
0x0A,
0x00,
0x15,
0x11,
0x0E,
0x00
]))
#heart
lcd.custom_char(3, bytearray([
0x00,
0x00,
0x0A,
0x15,
0x11,
0x0A,
0x04,
0x00
]))
#note
lcd.custom_char(4, bytearray([
0x01,
0x03,
0x05,
0x09,
0x09,
0x0B,
0x1B,
0x18
]))
#celcius
lcd.custom_char(5, bytearray([
0x07,
0x05,
0x07,
0x00,
0x00,
0x00,
0x00,
0x00
]))
#Checkmark
lcd.custom_char(6, bytearray([
0x08,
0x0C,
0x0E,
0x0F,
0x0F,
0x0E,
0x0C,
0x08
]))
def navUI(irq):
global curMenu
global curTask
global tasks
print('tasks: ' + str(tasks))
if(tasks == []):
displayGettingTasks()
tasks = getTasks()
displayTasks(tasks)
curMenu = 1
return
#tasks = ['Task 1', 'Task 2', 'Task 3', 'Task 4', 'Task 5']
# if the button1 is pressed then
# ............. move right in the menus
if(irq == button1):
if(curMenu == 0):
curMenu = 1
displayTasks(tasks)
elif(curMenu == 1):
if(curTask < len(tasks)):
displayNextTask(tasks,curTask)
if(curTask < len(tasks)):
curTask += 1
else:
curTask = 0
print('button1 pressed')
time.sleep(0.3)
displayIntro()
def main():
customcharacter()
#if(curMenu == 0):
while True:
button1.irq(trigger=Pin.IRQ_FALLING, handler=navUI)
##execute main
if __name__ == '__main__':
main()