blob: 4dd8dcdf9febb21ae4034ebab9599067a9c80d99 (
plain)
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
|
#include <new>
#include <string>
#include <array>
#include "hardware/i2c.h"
#include "pico/time.h"
#include "LCD_I2C.hpp"
#include "keypad.hpp"
#include "include/calculator.hpp"
#include "include/tokenizer.hpp"
Calculator::Calculator() {
display = new LCD_I2C(I2C_ADDRESS, LCD_COLUMNS, LCD_ROWS,
PICO_DEFAULT_I2C_INSTANCE,
PICO_DEFAULT_I2C_SDA_PIN,
PICO_DEFAULT_I2C_SCL_PIN);
default_keypad = new Keypad(keypad_row_pins, keypad_col_pins,
default_keypad_chars);
display->BacklightOn();
}
Calculator::~Calculator() {
delete display;
delete default_keypad;
}
void Calculator::run() {
while(true) {
display->Clear();
char pressed_key = default_keypad->getKey();
if(pressed_key == '\0')
continue;
processInputs();
}
void Calculator::processInputs() {
char pressed_key;
short str_len = 0;
std::string input;
while(str_len <= 15) {
pressed_key = default_keypad->getKey();
if(pressed_key != '\0' && pressed_key != '=') {
display->PrintChar(pressed_key);
input += pressed_key;
str_len += 1;
}
if(pressed_key == '=') {
tokens = tokenizer.tokenize(input);
break;
}
busy_wait_ms(170);
}
}
}
|