Skip to content

Commit b48aeb7

Browse files
committed
write to UI
1 parent c06c4d3 commit b48aeb7

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

weight_predict/weight_predict.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ def main():
122122

123123
mac_address_to_shelves = dict()
124124

125-
# Set up uart port
125+
# Set up uart ports
126126
esp_uart_port = serial.Serial(
127127
port="/dev/ttyTHS1",
128128
baudrate=115200,
@@ -131,7 +131,14 @@ def main():
131131
stopbits=serial.STOPBITS_ONE,
132132
timeout=1
133133
)
134-
134+
pi_uart_port = serial.Serial(
135+
port="/dev/ttyTHS0",
136+
baudrate=9600,
137+
bytesize=serial.EIGHTBITS,
138+
parity=serial.PARITY_NONE,
139+
stopbits=serial.STOPBITS_ONE,
140+
timeout=1
141+
)
135142

136143
while True:
137144

@@ -161,6 +168,15 @@ def main():
161168
for i, new_weight in enumerate(json_data['slot_weights_g']):
162169
item_changes = shelf.slots[i].predict_most_likely_item(new_weight)
163170
for item_change in item_changes:
171+
# Construct out JSON
172+
json_data = {
173+
'id': item_change.item_id,
174+
'quantity': item_change.quantity
175+
}
176+
json_str = json.dumps(json_data) + "\n"
177+
178+
# Send it to pi
179+
pi_uart_port.write(json_str.encode('utf-8'))
164180

165181
time_str = time.strftime("%H:%M:%S.") + f"{int((time.time() * 1000) % 1000):03d}"
166182
if item_change.quantity > 0:

0 commit comments

Comments
 (0)