|
@@ -12,6 +12,10 @@ parameters_path = os.path.abspath(os.path.dirname(__file__)) + "/parameters.txt" |
|
|
data_nb = 10 |
|
|
data_nb = 10 |
|
|
captors_path = os.path.abspath(os.path.dirname(__file__)) + "/captors.txt" |
|
|
captors_path = os.path.abspath(os.path.dirname(__file__)) + "/captors.txt" |
|
|
serial_path = fc.read_line_file(parameters_path) |
|
|
serial_path = fc.read_line_file(parameters_path) |
|
|
|
|
|
#si '\n' a l'interieur du lien, peut ne pas fonctionner, donc a enlever |
|
|
|
|
|
bad_path_enter_place = serial_path.find("\n") |
|
|
|
|
|
if(bad_path_enter_place > 0): |
|
|
|
|
|
serial_path = serial_path[0:bad_path_enter_place]+serial_path[bad_path_enter_place+2:] |
|
|
|
|
|
|
|
|
#Variables cachees |
|
|
#Variables cachees |
|
|
|
|
|
|
|
@@ -20,7 +24,20 @@ data_buff_max = 10 |
|
|
data_buff_nb = 0 |
|
|
data_buff_nb = 0 |
|
|
data_buff = "" |
|
|
data_buff = "" |
|
|
pressed_key = '' |
|
|
pressed_key = '' |
|
|
flag_state = 1 # etat neutre |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
flag_erreur_serial = -1 |
|
|
|
|
|
flag_afficher_menu = 1 |
|
|
|
|
|
flag_enregistrer = 2 |
|
|
|
|
|
flag_afficher_ss_menu = 3 |
|
|
|
|
|
flag_choix_menu_principal = 4 |
|
|
|
|
|
flag_choix_ss_menu = 5 |
|
|
|
|
|
flag_init_arduino = 6 |
|
|
|
|
|
|
|
|
|
|
|
flag_state = 6 # etat initialisation, puis etat neutre (1) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#Programme principal |
|
|
#Programme principal |
|
@@ -31,40 +48,49 @@ try: |
|
|
arduino_ser = serial.Serial(serial_path, 9600) #communication avec Arduino |
|
|
arduino_ser = serial.Serial(serial_path, 9600) #communication avec Arduino |
|
|
except serial.serialutil.SerialException: |
|
|
except serial.serialutil.SerialException: |
|
|
print("SerialException : la carte Arduino n'est pas connectee ou est connectee sur au autre port (actuel : "+ serial_path+").") |
|
|
print("SerialException : la carte Arduino n'est pas connectee ou est connectee sur au autre port (actuel : "+ serial_path+").") |
|
|
flag_state = -1 |
|
|
|
|
|
|
|
|
flag_state = flag_erreur_serial |
|
|
exit() |
|
|
exit() |
|
|
else: |
|
|
else: |
|
|
arduino_data = data.Arduino_data() |
|
|
arduino_data = data.Arduino_data() |
|
|
arduino_data.add_captors_from_file(captors_path) |
|
|
arduino_data.add_captors_from_file(captors_path) |
|
|
print("PoDoCor est pret a enregistrer les donnees") |
|
|
|
|
|
|
|
|
print("\nPoDoCor a initialisé la communication avec l'Arduino.") |
|
|
|
|
|
|
|
|
while(flag_state > 0): |
|
|
while(flag_state > 0): |
|
|
if(flag_state == 1): #afficher le menu |
|
|
|
|
|
|
|
|
if(flag_state == flag_init_arduino): #initialisation de l'arduino |
|
|
|
|
|
print("\nInitialisation des capteurs Arduino, veuillez patienter.") |
|
|
|
|
|
arduino_ser.flushInput() |
|
|
|
|
|
arduino_ser.write(bytes('0','utf-8')) |
|
|
|
|
|
time.sleep(5) |
|
|
|
|
|
test = arduino_ser.readline() |
|
|
|
|
|
print("Initialisation terminée, enregistrement possible.") |
|
|
|
|
|
flag_state = flag_afficher_menu |
|
|
|
|
|
arduino_ser.flushInput() |
|
|
|
|
|
if(flag_state == flag_afficher_menu): #afficher le menu |
|
|
print("_________________________________\n\nMAJ + P : Enregistrement des donnees\nMAJ + N : Gerer les capteurs\nMAJ + X : Arrêt du programme (ne fonctionne pas pendant l'enregistrement)\n_________________________________\n") |
|
|
print("_________________________________\n\nMAJ + P : Enregistrement des donnees\nMAJ + N : Gerer les capteurs\nMAJ + X : Arrêt du programme (ne fonctionne pas pendant l'enregistrement)\n_________________________________\n") |
|
|
flag_state = 4 |
|
|
|
|
|
time.sleep(2) # attente de la bonne communication avec Arduino |
|
|
time.sleep(2) # attente de la bonne communication avec Arduino |
|
|
elif(flag_state == 4): # appui clavier pour les choix du menu principal |
|
|
|
|
|
flag_state = fc.press_key('XPN', [0, 2, 3], flag_state) #detection de touche pressee (demarrage procedure acquisition) |
|
|
|
|
|
|
|
|
flag_state = flag_choix_menu_principal |
|
|
|
|
|
elif(flag_state == flag_choix_menu_principal): # appui clavier pour les choix du menu principal |
|
|
|
|
|
flag_state = fc.press_key('XPN', [0, flag_enregistrer, flag_afficher_ss_menu], flag_state) #detection de touche pressee (demarrage procedure acquisition) |
|
|
|
|
|
|
|
|
elif(flag_state == 3): # afficher le ss-menu capteurs |
|
|
|
|
|
|
|
|
elif(flag_state == flag_afficher_ss_menu): # afficher le ss-menu capteurs |
|
|
print(" _________________________________\n MAJ + U : Lister les capteurs\n MAJ + A : Ajouter un capteur\n MAJ + E : Supprimer un capteur\n MAJ + T : Changer l'ordre des capteurs\n MAJ + Q : Menu principal\n _________________________________\n") |
|
|
print(" _________________________________\n MAJ + U : Lister les capteurs\n MAJ + A : Ajouter un capteur\n MAJ + E : Supprimer un capteur\n MAJ + T : Changer l'ordre des capteurs\n MAJ + Q : Menu principal\n _________________________________\n") |
|
|
flag_state = 5 |
|
|
|
|
|
elif(flag_state == 5): # apui clavier pour les choix du ss-enu capteurs |
|
|
|
|
|
flag_state = fc.press_key('AETUQ', [31, 32, 33, 34, 1], flag_state) #detection de touche pressee (demarrage procedure acquisition) |
|
|
|
|
|
|
|
|
flag_state = flag_choix_ss_menu |
|
|
|
|
|
elif(flag_state == flag_choix_ss_menu): # appui clavier pour les choix du ss-enu capteurs |
|
|
|
|
|
flag_state = fc.press_key('AETUQ', [31, 32, 33, 34, flag_afficher_menu], flag_state) #detection de touche pressee (demarrage procedure acquisition) |
|
|
if(flag_state == 31): |
|
|
if(flag_state == 31): |
|
|
arduino_data.add_captor_manually(captors_path) |
|
|
arduino_data.add_captor_manually(captors_path) |
|
|
flag_state = 3 |
|
|
|
|
|
|
|
|
flag_state = flag_afficher_ss_menu |
|
|
elif(flag_state == 32): |
|
|
elif(flag_state == 32): |
|
|
arduino_data.del_captor(captors_path) |
|
|
arduino_data.del_captor(captors_path) |
|
|
flag_state = 3 |
|
|
|
|
|
|
|
|
flag_state = flag_afficher_ss_menu |
|
|
elif(flag_state == 33): |
|
|
elif(flag_state == 33): |
|
|
arduino_data.change_captors_order(captors_path) |
|
|
arduino_data.change_captors_order(captors_path) |
|
|
flag_state = 3 |
|
|
|
|
|
|
|
|
flag_state = flag_afficher_ss_menu |
|
|
elif(flag_state == 34): |
|
|
elif(flag_state == 34): |
|
|
arduino_data.captors_print_list(captors_path) |
|
|
arduino_data.captors_print_list(captors_path) |
|
|
flag_state = 3 |
|
|
|
|
|
|
|
|
flag_state = flag_afficher_ss_menu |
|
|
|
|
|
|
|
|
elif(flag_state == 2): # enregistrement des données |
|
|
|
|
|
|
|
|
elif(flag_state == flag_enregistrer): # enregistrement des données |
|
|
titles_list = [] |
|
|
titles_list = [] |
|
|
for i in range(arduino_data.nb_captor_signals): |
|
|
for i in range(arduino_data.nb_captor_signals): |
|
|
titles_list.append(arduino_data.captors[i].captor_name) |
|
|
titles_list.append(arduino_data.captors[i].captor_name) |
|
@@ -72,8 +98,10 @@ while(flag_state > 0): |
|
|
figures.create_figure(titles_list) |
|
|
figures.create_figure(titles_list) |
|
|
data_buff_nb = 0 |
|
|
data_buff_nb = 0 |
|
|
arduino_data.create_data_file() |
|
|
arduino_data.create_data_file() |
|
|
|
|
|
arduino_ser.flushInput() |
|
|
|
|
|
print("Enregistrement en cours. Arrêtez avec MAJ + P.\n") |
|
|
time_0 = time.time()-1 |
|
|
time_0 = time.time()-1 |
|
|
while(flag_state == 2): #boucle de reception des donnees |
|
|
|
|
|
|
|
|
while(flag_state == flag_enregistrer): #boucle de reception des donnees |
|
|
time_0 = time_0+1 |
|
|
time_0 = time_0+1 |
|
|
time_1 = time_0+0.6 |
|
|
time_1 = time_0+0.6 |
|
|
arduino_ser.write(bytes('1','utf-8')) #envoi de '1' a l'Arduino (acquisition donnees) |
|
|
arduino_ser.write(bytes('1','utf-8')) #envoi de '1' a l'Arduino (acquisition donnees) |
|
@@ -81,15 +109,15 @@ while(flag_state > 0): |
|
|
arduino_ser.write(bytes('2','utf-8')) #envoi de '2' (réception donnees) |
|
|
arduino_ser.write(bytes('2','utf-8')) #envoi de '2' (réception donnees) |
|
|
time.sleep(0.05) |
|
|
time.sleep(0.05) |
|
|
raw_data_txt = arduino_ser.readline() #format des donnees: data1,data2,data3\n |
|
|
raw_data_txt = arduino_ser.readline() #format des donnees: data1,data2,data3\n |
|
|
#print(str(raw_data_txt)[2:-5]) |
|
|
|
|
|
if(raw_data_txt == ''): # si aucune donnée reçue |
|
|
if(raw_data_txt == ''): # si aucune donnée reçue |
|
|
print("Arduino n'envoie aucune donnee, veuillez verifier le code televerse.") |
|
|
print("Arduino n'envoie aucune donnee, veuillez verifier le code televerse.") |
|
|
flag_state = -1 |
|
|
|
|
|
|
|
|
flag_state = flag_erreur_serial |
|
|
data_buff_nb = 0 |
|
|
data_buff_nb = 0 |
|
|
else: |
|
|
else: |
|
|
data_buff_nb +=1 |
|
|
data_buff_nb +=1 |
|
|
data_buff = data_buff + str(raw_data_txt)[2:-5] + "\n" #add 1 data line in buffer |
|
|
data_buff = data_buff + str(raw_data_txt)[2:-5] + "\n" #add 1 data line in buffer |
|
|
#procedure extraction donnees pour affichage |
|
|
#procedure extraction donnees pour affichage |
|
|
|
|
|
#print(str(raw_data_txt)) |
|
|
arduino_data.extract_data_to_array(str(raw_data_txt)[2:-5]) |
|
|
arduino_data.extract_data_to_array(str(raw_data_txt)[2:-5]) |
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -101,7 +129,8 @@ while(flag_state > 0): |
|
|
# plot |
|
|
# plot |
|
|
figures.plot_data(arduino_data.data_array) |
|
|
figures.plot_data(arduino_data.data_array) |
|
|
|
|
|
|
|
|
flag_state = fc.press_key_timeout('P', [1], flag_state) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
flag_state = fc.press_key_timeout('P', [flag_afficher_menu], flag_state) |
|
|
time.sleep(max(time_0+1-time.time(), 0)) |
|
|
time.sleep(max(time_0+1-time.time(), 0)) |
|
|
|
|
|
|
|
|
# while end |
|
|
# while end |
|
|