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