#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(); 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); } } }