Skip to content

Commit

Permalink
wip main: last fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
thegabriele97 committed Dec 21, 2021
1 parent f6cd688 commit 040d633
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 24 deletions.
2 changes: 1 addition & 1 deletion include/i2c_lcd.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ void lcd_send_two_string (char *str1, char * str2);

void lcd_set_text_downloading();

void lcd_set_number_people(int n_people);
void lcd_set_number_people(int n_people, int max_people);
31 changes: 20 additions & 11 deletions serialInterface.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,35 @@
#!/usr/bin/python3.9

from os import times
import serial
from sys import argv
from datetime import datetime
import time
import socket


if __name__ == "__main__":
ser = serial.Serial(port= argv[1], baudrate=argv[2])
print(ser.name)

ser.write(bytearray("get\r".encode()))
entry = ser.read(5)
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(("127.0.0.1", 1234))
s.settimeout(1)

s.send("\r".encode('utf-8'))
time.sleep(1)
s.recv(1024)

s.send("get\r".encode('utf-8'))
time.sleep(1)
s.recv(5)

totb = 0
time.sleep(1)
while ser.inWaiting() > 5:
entry = ser.read(6)
totb += 6
# print(entry.hex())
while True:
try:
entry = s.recv(6)
except:
exit(0)

timestamp = int.from_bytes(entry[0:4], "little")
cnt = int.from_bytes(entry[4:6], "little")

print(f"{datetime.utcfromtimestamp(timestamp).strftime('%d/%m/%Y %H/%M/%S')} -- {cnt} -- tot: {totb}")
print(f"{datetime.utcfromtimestamp(timestamp).strftime('%d/%m/%Y %H/%M/%S')} -- {cnt}")

9 changes: 8 additions & 1 deletion src/comm.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ static void rxCpltCback(UART_HandleTypeDef *huart) {
bool cvrted;
uint8_t *pbuf;
uint16_t n;
uint32_t tmpNewValue;

GAL_UART_Transmit(buf + buf_cnt + len, 0x1); // echo back

Expand Down Expand Up @@ -88,8 +89,14 @@ static void rxCpltCback(UART_HandleTypeDef *huart) {
for (cvrted = false, i = 4; i < buf_cnt && (buf[i] >= '0' && buf[i] <= '9'); i++) {

if (!cvrted) {

tmpNewValue = atoi((char *)buf + 4);
if (tmpNewValue > 0xffff) {
break;
}

cvrted = true;
setValue = atol((char *)buf + 4);
setValue = tmpNewValue;
INVOKE_CB(phcomm->Callback.newValueSet, setValue);
}

Expand Down
6 changes: 3 additions & 3 deletions src/i2c_lcd.c
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,9 @@ void lcd_set_text_downloading(){
lcd_send_string(" ");
}

void lcd_set_number_people(int n_people){
char num_char[15];
sprintf(num_char, "%d", n_people);
void lcd_set_number_people(int n_people, int max_people){
char num_char[16];
sprintf(num_char, "%d/%d", n_people, max_people);

lcd_go_home();
lcd_send_string("Number of people");
Expand Down
6 changes: 3 additions & 3 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ static void update_interface(){
turn_off_green_led();
}

lcd_set_number_people(number_people);
lcd_set_number_people(number_people, number_people_max);
}

/**
Expand All @@ -215,12 +215,12 @@ void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin) {
case IR_1_PIN:
// Manage counter, increase
if(setup_phase > 1 && number_people < number_people_max)
log_update_number(&hrtc, &gTime, &gDate, number_people++, &hcomm);
log_update_number(&hrtc, &gTime, &gDate, ++number_people, &hcomm);
break;
case IR_2_PIN:
// Manage counter, decrease
if(setup_phase > 1 && number_people > 0)
log_update_number(&hrtc, &gTime, &gDate, number_people--, &hcomm);
log_update_number(&hrtc, &gTime, &gDate, --number_people, &hcomm);
break;
}

Expand Down
10 changes: 5 additions & 5 deletions stm32f4_discovery_modified.resc
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ machine LoadPlatformDescription @./peripherals/ext_peripheral.repl

cpu PerformanceInMips 125

:emulation CreateServerSocketTerminal 1234 "externalUART" false
:connector Connect uart4 externalUART
:showAnalyzer uart4

emulation CreateUartPtyTerminal "externalUART" "/tmp/uart4" true
emulation CreateServerSocketTerminal 1234 "externalUART" False
connector Connect uart4 externalUART
showAnalyzer uart4

:emulation CreateUartPtyTerminal "externalUART" "/tmp/uart4" true
:connector Connect uart4 externalUART
:showAnalyzer uart4

macro reset
"""
sysbus LoadELF @.pio/build/disco_f407vg/firmware.elf
Expand Down

0 comments on commit 040d633

Please sign in to comment.