From 10ecf4d95194a273cc6aab89c3a1bcf739a194cd Mon Sep 17 00:00:00 2001 From: HombreLaser Date: Sat, 22 Jun 2024 11:01:41 -0600 Subject: Add tokenizer --- src/calculator.cpp | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 src/calculator.cpp (limited to 'src/calculator.cpp') 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 +#include +#include +#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); + } + } +} -- cgit v1.2.3