2018-04-30 16:15:47 +02:00
|
|
|
#include <pthread.h>
|
|
|
|
#include <signal.h>
|
|
|
|
#include <time.h>
|
|
|
|
|
|
|
|
#include "ihm.h"
|
|
|
|
#include "movement.h"
|
|
|
|
#include "parcours.h"
|
|
|
|
#include "points.h"
|
2018-05-01 08:45:02 +02:00
|
|
|
#include "lcd.h"
|
|
|
|
#include "buttons.h"
|
2018-05-01 14:51:41 +02:00
|
|
|
#include "diagnostics.h"
|
2018-04-30 16:15:47 +02:00
|
|
|
|
|
|
|
// Globales
|
|
|
|
pthread_t tIHM;
|
|
|
|
|
|
|
|
// Fonctions
|
|
|
|
void configureIHM()
|
|
|
|
{
|
|
|
|
initLCD();
|
2018-04-30 22:40:20 +02:00
|
|
|
printToLCD(LCD_LINE_1, "Demarrage");
|
2018-04-30 16:15:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void startIHM()
|
|
|
|
{
|
2018-05-01 08:45:02 +02:00
|
|
|
configureButtons();
|
2018-04-30 16:15:47 +02:00
|
|
|
pthread_create(&tIHM, NULL, TaskIHM, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isDebug = false;
|
|
|
|
bool isOrange = true;
|
|
|
|
bool annuler = false;
|
|
|
|
pthread_t tParcours;
|
|
|
|
|
2018-04-30 22:40:20 +02:00
|
|
|
char* orangeStr = "Orange";
|
|
|
|
char* vertStr = "Vert";
|
|
|
|
|
|
|
|
char* getCouleur()
|
2018-04-30 16:15:47 +02:00
|
|
|
{
|
2018-04-30 22:40:20 +02:00
|
|
|
return isOrange ? orangeStr : vertStr;
|
2018-04-30 16:15:47 +02:00
|
|
|
}
|
|
|
|
|
2018-05-01 13:34:05 +02:00
|
|
|
struct timespec calibrageLast = {0, 0};
|
|
|
|
struct timespec calibrageNow;
|
|
|
|
struct timespec calibrageEcoule;
|
|
|
|
|
2018-04-30 16:15:47 +02:00
|
|
|
void* TaskIHM(void* pdata)
|
|
|
|
{
|
|
|
|
(void)pdata;
|
|
|
|
|
|
|
|
enum boutons bout;
|
|
|
|
for (;;) {
|
|
|
|
|
2018-05-01 13:34:05 +02:00
|
|
|
/* // Debug */
|
|
|
|
/* for (;;) { */
|
|
|
|
/* clearLCD(); */
|
|
|
|
/* printfToLCD(LCD_LINE_1, "Debug : %s", isDebug ? "On" : "Off"); */
|
|
|
|
/* if (isDebug) { */
|
|
|
|
/* printToLCD(LCD_LINE_2, "192.168.0.0 TODO"); */
|
|
|
|
/* } */
|
|
|
|
/* bout = pressedButton(BUT_REFRESH_INTERVAL); */
|
|
|
|
/* */
|
|
|
|
/* if (bout == rouge) { */
|
|
|
|
/* isDebug = !isDebug; */
|
|
|
|
/* } else if (bout == jaune) { */
|
|
|
|
/* break; */
|
|
|
|
/* } */
|
|
|
|
/* } */
|
2018-04-30 16:15:47 +02:00
|
|
|
|
|
|
|
// Couleur
|
|
|
|
for (;;) {
|
|
|
|
clearLCD();
|
2018-04-30 22:40:20 +02:00
|
|
|
printfToLCD(LCD_LINE_1, "Couleur : %s", getCouleur());
|
2018-05-01 08:45:02 +02:00
|
|
|
bout = pressedButton(BUT_BLOCK);
|
2018-04-30 16:15:47 +02:00
|
|
|
|
|
|
|
if (bout == rouge) {
|
|
|
|
isOrange = !isOrange;
|
|
|
|
} else if (bout == jaune) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Calibrage
|
|
|
|
for (;;) {
|
|
|
|
clearLCD();
|
2018-05-01 13:34:05 +02:00
|
|
|
printf("84 %ld\n", calibrageLast.tv_sec);
|
|
|
|
if (calibrageLast.tv_sec > 0) {
|
|
|
|
clock_gettime(CLOCK_REALTIME, &calibrageNow);
|
|
|
|
if ((calibrageNow.tv_nsec - calibrageLast.tv_nsec) > 0) {
|
|
|
|
calibrageEcoule.tv_sec = calibrageNow.tv_sec - calibrageLast.tv_sec - 1;
|
|
|
|
calibrageEcoule.tv_nsec = calibrageNow.tv_nsec - calibrageLast.tv_nsec + 1000000000UL;
|
|
|
|
} else {
|
|
|
|
calibrageEcoule.tv_sec = calibrageNow.tv_sec - calibrageLast.tv_sec;
|
|
|
|
calibrageEcoule.tv_nsec = calibrageNow.tv_nsec - calibrageLast.tv_nsec;
|
|
|
|
}
|
2018-04-30 22:40:20 +02:00
|
|
|
printToLCD(LCD_LINE_1, "Calibre il y a");
|
2018-05-01 13:34:05 +02:00
|
|
|
printfToLCD(LCD_LINE_2, "%ld secondes", calibrageEcoule.tv_sec);
|
2018-04-30 16:15:47 +02:00
|
|
|
} else {
|
2018-04-30 22:40:20 +02:00
|
|
|
printToLCD(LCD_LINE_1, "Calibrer");
|
|
|
|
printfToLCD(LCD_LINE_2, "(%s)", getCouleur());
|
2018-04-30 16:15:47 +02:00
|
|
|
}
|
2018-05-01 08:45:02 +02:00
|
|
|
bout = pressedButton(BUT_REFRESH_INTERVAL);
|
2018-04-30 16:15:47 +02:00
|
|
|
|
|
|
|
if (bout == rouge) {
|
|
|
|
clearLCD();
|
2018-04-30 22:40:20 +02:00
|
|
|
printToLCD(LCD_LINE_1, "Calibrage...");
|
|
|
|
delay(3000); // TODO
|
2018-05-01 13:34:05 +02:00
|
|
|
clock_gettime(CLOCK_REALTIME, &calibrageLast);
|
2018-04-30 16:15:47 +02:00
|
|
|
} else if (bout == jaune) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Diagnostics
|
|
|
|
for (;;) {
|
|
|
|
clearLCD();
|
2018-04-30 22:40:20 +02:00
|
|
|
printToLCD(LCD_LINE_1, "Diagnostiquer");
|
2018-05-01 08:45:02 +02:00
|
|
|
bout = pressedButton(BUT_BLOCK);
|
2018-04-30 16:15:47 +02:00
|
|
|
|
|
|
|
if (bout == rouge) {
|
|
|
|
clearLCD();
|
2018-05-01 14:51:41 +02:00
|
|
|
runDiagnostics();
|
2018-04-30 16:15:47 +02:00
|
|
|
} else if (bout == jaune) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Parcours
|
|
|
|
for (;;) {
|
|
|
|
clearLCD();
|
2018-04-30 22:40:20 +02:00
|
|
|
printToLCD(LCD_LINE_1, "Lancer parcours");
|
|
|
|
printfToLCD(LCD_LINE_2, "(%s)", getCouleur());
|
2018-05-01 08:45:02 +02:00
|
|
|
bout = pressedButton(BUT_BLOCK);
|
2018-04-30 16:15:47 +02:00
|
|
|
if (bout == rouge) {
|
|
|
|
// No tirette
|
|
|
|
annuler = false;
|
|
|
|
while (!tirettePresente()) {
|
|
|
|
clearLCD();
|
2018-04-30 22:40:20 +02:00
|
|
|
printToLCD(LCD_LINE_1, "Inserez tirette");
|
|
|
|
printToLCD(LCD_LINE_2, "(ROUGE: ignorer)");
|
2018-05-01 08:45:02 +02:00
|
|
|
bout = pressedButton(BUT_REFRESH_INTERVAL);
|
2018-04-30 16:15:47 +02:00
|
|
|
if (bout == rouge) {
|
|
|
|
break;
|
|
|
|
} else if (bout == jaune) {
|
|
|
|
annuler = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (annuler) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Go!
|
|
|
|
|
|
|
|
prepareParcours(isOrange);
|
|
|
|
while (tirettePresente()) {
|
2018-05-01 08:45:02 +02:00
|
|
|
bout = pressedButton(BUT_POLLING_INTERVAL);
|
2018-04-30 16:15:47 +02:00
|
|
|
if (bout == jaune) {
|
|
|
|
annuler = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (annuler) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
startParcours(); // TODO On a different thread
|
|
|
|
|
|
|
|
int toWait;
|
|
|
|
while ((toWait = updateParcours()) >= 0) {
|
2018-05-01 08:45:02 +02:00
|
|
|
if (pressedButton(toWait) != none) {
|
2018-04-30 16:15:47 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
stopParcours();
|
|
|
|
|
2018-05-01 08:45:02 +02:00
|
|
|
pressedButton(BUT_BLOCK); // Nécessite 3 appuis pour éviter d'enlever le score par inadvertance
|
|
|
|
pressedButton(BUT_BLOCK);
|
|
|
|
pressedButton(BUT_BLOCK);
|
2018-04-30 16:15:47 +02:00
|
|
|
} else if (bout == jaune) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// RàZ
|
|
|
|
for (;;) {
|
|
|
|
clearLCD();
|
2018-04-30 22:40:20 +02:00
|
|
|
printToLCD(LCD_LINE_1, "Remettre a zero");
|
2018-05-01 08:45:02 +02:00
|
|
|
bout = pressedButton(BUT_BLOCK);
|
2018-04-30 16:15:47 +02:00
|
|
|
|
|
|
|
if (bout == rouge) {
|
|
|
|
clearLCD();
|
2018-04-30 22:40:20 +02:00
|
|
|
printToLCD(LCD_LINE_1, "Remise a zero...");
|
2018-04-30 16:15:47 +02:00
|
|
|
delay(3000); // TODO
|
|
|
|
} else if (bout == jaune) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void deconfigureIHM()
|
|
|
|
{
|
2018-05-01 09:03:33 +02:00
|
|
|
pthread_cancel(tIHM);
|
2018-04-30 16:15:47 +02:00
|
|
|
clearLCD();
|
2018-04-30 22:40:20 +02:00
|
|
|
printToLCD(LCD_LINE_1, "Bye bye!");
|
2018-04-30 16:15:47 +02:00
|
|
|
}
|