-
Notifications
You must be signed in to change notification settings - Fork 4
/
gpio.cpp
135 lines (106 loc) Β· 3.64 KB
/
gpio.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#include "GlobalVARS.h"
#include <EEPROM.h>
#include "gpio.h"
#include "Wire.h"
#include "workflow.h"
#include <TFT_eSPI.h> // Graphics and font library for ST7735 driver chip
/**********************π GLOBAL Vars *******************************/
extern TFT_eSPI tft = TFT_eSPI(); // Invoke library, pins defined in User_Setup.h
extern sWallet myWallet;
extern sButton btnMove;
extern sButton btnSelect;
/***********************π EEPROM DATA ******************************/
void EEPROMsetup(){
EEPROM.begin(EEPROM_SIZE);
/********π READ MNMONIC ************/
String mnemonic="";
if(EEPROM.read(1) == STX){
for(uint16_t i=2; i<400; i++){
uint8_t nm = EEPROM.read(i);
if(nm == ETX) break;
mnemonic = mnemonic + char(nm);
}
}
myWallet.mnemonic = mnemonic;
Serial.print("Current mnemonic: "); Serial.println(mnemonic);
myWallet.preState = rgnSeed;
}
/*****************π TFT WORK *********************/
void Init_TFT(void){
/******** INIT DISPLAY ************/
tft.init();
tft.setRotation(1);
tft.setSwapBytes(true);// Swap the colour byte order when rendering
/******** PRINT INIT SCREEN *****/
tft.fillScreen(TFT_BLACK);
tft.pushImage(20, 23, logoWidth, logoHeight, seeder_logo);
delay(2000);
tft.fillScreen(TFT_BLACK);
tft.pushImage(60, 34, logouBTCWidth, logouBTCHeight, uBitcoinLogo);
tft.pushImage(95, 110, poweredWidth, poweredHeight, powered_logo);
delay(2000);
tft.fillScreen(TFT_BLACK);
tft.pushImage(0, 0, menuHeaderWidth, menuHeaderHeight, menu_header);
//tft.fillRect(0,0,D2_ANCHO,HEADER_HEIGHT, SEEDER_GREEN); //Borramos Texto header
//tft.setTextColor(TFT_BLACK);
//tft.setTextDatum(ML_DATUM); //MIDDLE CENTER - MC_DATUM / TOP CENTER - TC_DATUM
//tft.setTextSize(1);
//tft.setFreeFont(FF22);
//tft.drawString("RGN SEED", 8 , 15, GFXFF);
myWallet.preState = coinSeed;
btnMove.forceClick(); //Forzamos click para que pinte el menu
}
void clrWorkArea(void){
//x1,y1,x2,y2, color
tft.fillRect(0,HEADER_HEIGHT,D_ANCHO,D_ALTO, TFT_BLACK);
}
/*****************π BUTTON DETECTION *********************/
sButton::sButton(byte bPin){ pin = bPin; pinMode(pin, INPUT); } //Constructor
void sButton::init(void){ pinMode(pin, INPUT); } // Init pushbutton pin
int sButton::click(void){ return clickState; }
void sButton::forceClick(void){ clickState = ForcedClick;} //Generates one click loop
void sButton::check(void)
{
const unsigned long ButTimeout = 250;
const unsigned long ButLongClick = 5000;
unsigned long msec = millis();
byte but = digitalRead (pin);
if (antState != but) {
antState = but;
delay (10); // **** debounce
if (LOW == but) { // press
if (msecLst) { // 2nd press
msecLst = 0;
clickState = DoubleClick;
Serial.println("DoubleClick --> ");
return;
}
else
msecLst = 0 == msec ? 1 : msec;
}
}
int elapsed = msec - msecLst;
if (msecLst && (elapsed > ButTimeout) && (elapsed < ButLongClick)) {
if(but != LOW) {
msecLst = 0;
clickState = SingleClick;
Serial.println("SingleClick --> ");
return;
}
}
//LongClick
if(msecLst && (but == antState) && (but == LOW)) {
if(elapsed > ButLongClick) {
msecLst = 0;
clickState = LongClick;
Serial.println("LongClick --> ");
return;
}
}
//ForcedClick
if(clickState == ForcedClick){
clickState = SingleClick;
return;
}
clickState = None;
}