1
0
Fork 0
mirror of https://github.com/RobotechLille/cdf2018-principal synced 2024-11-16 21:36:04 +01:00
cdf2018-principal/chef/src/ihm.c

209 lines
5.4 KiB
C
Raw Normal View History

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-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);
pthread_join(tIHM, NULL);
}
// t1 - t2
void diffTimespec(const struct timespec* t1, const struct timespec* t2, struct timespec* td)
{
if ((t1->tv_nsec - t2->tv_nsec) < 0) {
td->tv_sec = t1->tv_sec - t2->tv_sec - 1;
td->tv_nsec = t1->tv_nsec - t2->tv_nsec + 1000000000UL;
} else {
td->tv_sec = t1->tv_sec - t2->tv_sec;
td->tv_nsec = t1->tv_nsec - t2->tv_nsec;
}
}
bool isDebug = false;
bool isOrange = true;
bool annuler = false;
clock_t lastCalibrage = 0;
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
}
void* TaskIHM(void* pdata)
{
(void)pdata;
enum boutons bout;
for (;;) {
// Debug
for (;;) {
clearLCD();
2018-04-30 22:40:20 +02:00
printfToLCD(LCD_LINE_1, "Debug : %s", isDebug ? "On" : "Off");
2018-04-30 16:15:47 +02:00
if (isDebug) {
2018-04-30 22:40:20 +02:00
printToLCD(LCD_LINE_2, "192.168.0.0 TODO");
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) {
isDebug = !isDebug;
} else if (bout == jaune) {
break;
}
}
// 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();
if (lastCalibrage != 0) {
2018-04-30 22:40:20 +02:00
printToLCD(LCD_LINE_1, "Calibre il y a");
printfToLCD(LCD_LINE_2, "%ld secondes", (clock() - lastCalibrage) / CLOCKS_PER_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
lastCalibrage = clock(); // TODO struct timespec
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-04-30 22:40:20 +02:00
printToLCD(LCD_LINE_1, "Diagnostics...");
2018-04-30 16:15:47 +02:00
delay(3000); // TODO
} 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()
{
clearLCD();
2018-04-30 22:40:20 +02:00
printToLCD(LCD_LINE_1, "Bye bye!");
2018-04-30 16:15:47 +02:00
}