]> git.gir.st - hardpass.git/blob - oled/oled_passwd.cpp
Merge branch 'master' of https://github.com/girst/hardpass-passwordmanager
[hardpass.git] / oled / oled_passwd.cpp
1 #include "ArduiPi_OLED_lib.h"
2 #include "Adafruit_GFX.h"
3 #include "ArduiPi_OLED.h"
4
5 #include <getopt.h>
6 #include <stdio.h>
7
8 #define ERR_FAIL 0
9 //yes, this is irritating to unix users, but a return val >= 1 will mean nth item selected
10 ArduiPi_OLED display; // Instantiate the display
11
12 // Config Option
13 struct s_opts {
14 int oled;
15 int verbose;
16 } ;
17
18 // default options values
19 s_opts opts = {
20 3, // my .96" oled
21 false // Not verbose
22 };
23
24 void testdrawchar(void) {
25 display.setTextSize(1);
26 display.setTextColor(WHITE);
27 display.setCursor(0,0);
28
29 for (uint8_t i=0; i < 168; i++) {
30 if (i == '\n') continue;
31 display.write(i);
32 //if ((i > 0) && (i % 21 == 0))
33 //display.print("\n");
34 }
35 display.display();
36 }
37
38
39 void disp_login (char* title, int ast_n) {
40 display.clearDisplay();
41 display.setTextSize(1);
42 display.setTextColor(WHITE);
43 display.setCursor(0,0);
44 display.print (title);
45 display.drawLine(0, 8, display.width()-1, 8, WHITE);
46
47 display.setCursor(0,10);
48 display.printf ("Enter GPG Passphrase:\n");
49 for (int i = 0; i < ast_n; i++) {
50 display.printf ("*");
51 }
52
53 display.display();
54 }
55
56 int the_login (char* title) {
57 int asterisks_num = 0;
58 system ("/bin/stty raw");//send keystrokes immediately, not just after enter key
59 while (1) {
60 disp_login (title, asterisks_num);
61
62 switch (getchar()) {
63 case 'j':
64 asterisks_num--;
65 break;
66 case 'k':
67 asterisks_num++;
68 break;
69 case ' ':
70 system ("/bin/stty cooked");//return to normal mode
71 return asterisks_num;
72 break;
73 }
74 }
75 }
76
77
78 int main(int argc, char **argv)
79 {
80 if ( !display.init(OLED_I2C_RESET,opts.oled) ) {
81 return ERR_FAIL;
82 }
83
84 display.begin();
85
86 //display.clearDisplay(); // clears the screen buffer
87 //display.display(); // display it (clear display)
88
89 display.clearDisplay();
90
91 // draw the first ~12 characters in the font
92 //testdrawchar();
93 //display.display();
94 //sleep(2);
95 //display.clearDisplay();
96
97 //#####mystuff
98
99 return the_login ("Hardpass");
100 //############
101
102 display.close(); // Free PI GPIO ports
103 }
104
105
Imprint / Impressum