moment of truth

This commit is contained in:
Steven Tracey 2024-11-27 20:42:45 -05:00
parent 846b038404
commit fa10b2967c
2 changed files with 53 additions and 33 deletions

View File

@ -46,6 +46,18 @@ dtoverlay=i2c-rtc,ds3231
``` ```
Reference [this walk through](https://pimylifeup.com/raspberry-pi-rtc/) for more info Reference [this walk through](https://pimylifeup.com/raspberry-pi-rtc/) for more info
Set GPIO pins
```bash
pinctrl set 6 pd
pinctrl set 12 pd
pinctrl set 13 pd
pinctrl set 16 pd
pinctrl set 19 pd
pinctrl set 20 pd
pinctrl set 22 pd
pinctrl set 27 pd
```
### Configuration ### Configuration
To add a config, create a text file in the ~/.totp directory (if it doesn't exist then create it). The name of the file will be what is populated on the device.<br> To add a config, create a text file in the ~/.totp directory (if it doesn't exist then create it). The name of the file will be what is populated on the device.<br>
Ex: "google.txt" will be displayed as "google"<br><br> Ex: "google.txt" will be displayed as "google"<br><br>

View File

@ -46,12 +46,13 @@ ButtonMap button_map[] = {
#define NUM_BUTTONS 8 #define NUM_BUTTONS 8
struct gpiod_chip *chip; struct gpiod_chip *chip;
struct gpiod_line_bulk lines;
struct gpiod_line *line_pointers[NUM_BUTTONS]; struct gpiod_line *line_pointers[NUM_BUTTONS];
int last_button_state[NUM_BUTTONS] = {0}; int last_button_state[NUM_BUTTONS] = {0};
struct timespec last_press_time[NUM_BUTTONS]; struct timespec last_press_time[NUM_BUTTONS];
int isBlocking = 0;
void closeP2FA() { void closeP2FA() {
EPD_2in13_V4_Init(); EPD_2in13_V4_Init();
EPD_2in13_V4_Clear(); EPD_2in13_V4_Clear();
@ -75,6 +76,10 @@ int computeWidth(char* text, sFONT *font) {
return font->Width * strlen(text); return font->Width * strlen(text);
} }
void setBlocking(int bool) {
isBlocking = bool;
}
int readButtons() { int readButtons() {
for (int i = 0; i < NUM_BUTTONS; i++) { for (int i = 0; i < NUM_BUTTONS; i++) {
int value = gpiod_line_get_value(line_pointers[i]); int value = gpiod_line_get_value(line_pointers[i]);
@ -105,6 +110,9 @@ int readButtons() {
int getBtn() { int getBtn() {
while (1) { while (1) {
int key = readButtons(); int key = readButtons();
if (!isBlocking) {
return key;
}
if (key != -1) { if (key != -1) {
return key; return key;
} }
@ -115,13 +123,14 @@ int getBtn() {
//TODO Put display to sleep after so many refreshes //TODO Put display to sleep after so many refreshes
void code(UWORD *blackImage, char* confName) { void code(UWORD *blackImage, char* confName) {
//int ch; setBlocking(0);
int ch;
while(1) { while(1) {
// ch = getch(); ch = getBtn();
// if (ch != ERR) { if (ch != -1) {
// if (ch == 'q') break; Debug("Key Pressed: %c\n", ch);
// Debug("Key Pressed: %c\n", ch); if (ch == 'q') break;
// } }
Paint_NewImage(blackImage, EPD_2in13_V4_WIDTH, EPD_2in13_V4_HEIGHT, 90, WHITE); Paint_NewImage(blackImage, EPD_2in13_V4_WIDTH, EPD_2in13_V4_HEIGHT, 90, WHITE);
EPD_2in13_V4_Init(); EPD_2in13_V4_Init();
@ -153,10 +162,10 @@ void code(UWORD *blackImage, char* confName) {
int progBarEndIndex; int progBarEndIndex;
int lastI = 30 * 1000; int lastI = 30 * 1000;
for (int i = getTimeRemainingMS(30);; i = getTimeRemainingMS(30)) { for (int i = getTimeRemainingMS(30);; i = getTimeRemainingMS(30)) {
//ch = getch(); ch = getBtn();
//if (ch != ERR) { if (ch != -1) {
// if (ch == 'q') return; if (ch == 'q') return;
//} }
if (i > lastI) break; if (i > lastI) break;
startTime = clock(); startTime = clock();
@ -203,7 +212,12 @@ void config(UWORD *blackImage, char* configName) {
EPD_2in13_V4_Display(blackImage); EPD_2in13_V4_Display(blackImage);
//int ch = getch(); setBlocking(1);
int ch;
while(1) {
ch = getBtn();
if (ch == 'b') break;
}
} }
void drawTotpHome(UWORD *blackImage, char** configNames, int *length) { void drawTotpHome(UWORD *blackImage, char** configNames, int *length) {
@ -239,27 +253,27 @@ void totpHome(UWORD *blackImage) {
int ch; int ch;
while (1) { while (1) {
//timeout(-1); setBlocking(1);
ch = 'q'; //getch(); ch = getBtn();
if (!ch) { if (ch != -1) {
switch(ch) { switch(ch) {
// case KEY_UP: case 'u':
// if (i > 0) i--; if (i > 0) i--;
// Paint_ClearWindows(115, 5 + (i + 1) * 20, 122, 17 + (i + 1) * 20, WHITE); Paint_ClearWindows(115, 5 + (i + 1) * 20, 122, 17 + (i + 1) * 20, WHITE);
// break; break;
// case KEY_DOWN: case 'd':
// if (i < length - 1) i++; if (i < length - 1) i++;
// Paint_ClearWindows(115, 5 + (i - 1) * 20, 122, 17 + (i - 1) * 20, WHITE); Paint_ClearWindows(115, 5 + (i - 1) * 20, 122, 17 + (i - 1) * 20, WHITE);
// break; break;
case '\n': case 's':
code(blackImage, configNames[i]); code(blackImage, configNames[i]);
drawTotpHome(blackImage, configNames, &length); drawTotpHome(blackImage, configNames, &length);
break; break;
case 'c': case 'a':
config(blackImage, configNames[i]); config(blackImage, configNames[i]);
drawTotpHome(blackImage, configNames, &length); drawTotpHome(blackImage, configNames, &length);
break; break;
case 'q': case 'b':
return; return;
} }
} }
@ -316,16 +330,10 @@ int main() {
gpiod_chip_close(chip); gpiod_chip_close(chip);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
gpiod_line_bulk_init(&lines);
} }
// End Init GPIO // End Init GPIO
printf("Monitoring buttons. Press Ctrl+C to exit.\n"); drawLoop();
while (1) {
printf("Button: %c\n", (char)getBtn());
}
//drawLoop();
closeP2FA(); closeP2FA();
return 0; return 0;