parent
cbe1ae6929
commit
92a1a9f048
@ -0,0 +1,120 @@
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <curses.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
bool buttonLeftPressed=false;
|
||||
void buttonLeft() {
|
||||
buttonLeftPressed=true;
|
||||
}
|
||||
|
||||
bool buttonRightPressed=false;
|
||||
void buttonRight() {
|
||||
buttonRightPressed=true;
|
||||
}
|
||||
|
||||
bool buttonMidPressed=false;
|
||||
void buttonMid() {
|
||||
buttonMidPressed=true;
|
||||
}
|
||||
|
||||
bool turnedLeft=false;
|
||||
void turnLeft() {
|
||||
turnedLeft=true;
|
||||
}
|
||||
|
||||
bool turnedRight=false;
|
||||
void turnRight() {
|
||||
turnedRight=true;
|
||||
}
|
||||
|
||||
bool rotPressed=false;
|
||||
void pressRot() {
|
||||
rotPressed=true;
|
||||
}
|
||||
|
||||
void lcdPut(char* text) {
|
||||
printf("%c[2K", 27);
|
||||
printf("\r%s", text );
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
|
||||
void grind(int time) {
|
||||
lcdPut("grinding...");
|
||||
usleep(time*1000);
|
||||
lcdPut("Fin...");
|
||||
usleep(800000);
|
||||
}
|
||||
|
||||
|
||||
void boilerplate() {
|
||||
int foo = getch();
|
||||
switch(foo) {
|
||||
case 113: // q
|
||||
buttonLeft(); break;
|
||||
case 119: // w
|
||||
buttonMid(); break;
|
||||
case 101: // e
|
||||
buttonRight(); break;
|
||||
case 97: // a
|
||||
turnLeft(); break;
|
||||
case 115: // s
|
||||
pressRot(); break;
|
||||
case 100: //
|
||||
turnRight(); break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int activeTimer=0;
|
||||
int timerLens[3];
|
||||
void loop() {
|
||||
boilerplate();
|
||||
|
||||
char str[16];
|
||||
sprintf(str, "T%1d: %10d", activeTimer, timerLens[activeTimer]);
|
||||
lcdPut(str);
|
||||
|
||||
if(buttonLeftPressed) {
|
||||
buttonLeftPressed=false;
|
||||
activeTimer=0;
|
||||
}
|
||||
if(buttonRightPressed) {
|
||||
buttonRightPressed=false;
|
||||
activeTimer=2;
|
||||
}
|
||||
if(buttonMidPressed) {
|
||||
buttonMidPressed=false;
|
||||
activeTimer=1;
|
||||
}
|
||||
if(turnedLeft) {
|
||||
turnedLeft=false;
|
||||
timerLens[activeTimer] -= 5;
|
||||
}
|
||||
if(turnedRight) {
|
||||
turnedRight=false;
|
||||
timerLens[activeTimer] += 5;
|
||||
}
|
||||
if(rotPressed) {
|
||||
rotPressed=false;
|
||||
grind(timerLens[activeTimer]);
|
||||
}
|
||||
|
||||
usleep(150);
|
||||
}
|
||||
|
||||
int main( int argc, const char* argv[] )
|
||||
{
|
||||
|
||||
timerLens[0] = 1000;
|
||||
timerLens[1] = 250;
|
||||
timerLens[2] = 2500;
|
||||
WINDOW *w = initscr();
|
||||
cbreak();
|
||||
nodelay(w, TRUE);
|
||||
|
||||
while(1) loop();
|
||||
}
|
||||
Loading…
Reference in new issue