summaryrefslogtreecommitdiff
path: root/src/calculator.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/calculator.cpp')
-rw-r--r--src/calculator.cpp54
1 files changed, 54 insertions, 0 deletions
diff --git a/src/calculator.cpp b/src/calculator.cpp
new file mode 100644
index 0000000..5de706b
--- /dev/null
+++ b/src/calculator.cpp
@@ -0,0 +1,54 @@
+#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();
+ std::string input;
+ short str_len = 0;
+ char pressed_key = default_keypad->getKey();
+
+ if(pressed_key == '\0')
+ continue;
+
+ 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 == '=') {
+ std::array tokens = tokenizer.tokenize(input);
+ break;
+ }
+
+ busy_wait_ms(170);
+ }
+ }
+}