diff options
author | HombreLaser <buran@silosneeded.com> | 2024-06-22 11:01:41 -0600 |
---|---|---|
committer | HombreLaser <buran@silosneeded.com> | 2024-06-22 11:01:41 -0600 |
commit | 10ecf4d95194a273cc6aab89c3a1bcf739a194cd (patch) | |
tree | 9163b606ef00f7e0e147bb240a85032cea6026e2 /src/calculator.cpp | |
parent | 0ef2b4da78f51002bdf45ab632c97195ece9a8b7 (diff) |
Add tokenizer
Diffstat (limited to 'src/calculator.cpp')
-rw-r--r-- | src/calculator.cpp | 54 |
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); + } + } +} |