working exponent math
This commit is contained in:
parent
c8de75ccd9
commit
86695db883
@ -17,7 +17,7 @@ Calculator::~Calculator() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static const char* buttonMap[] = {
|
static const char* buttonMap[] = {
|
||||||
"7", "8", "9", Symbols::backspace, "\n", "4", "5", "6", "+ -", "\n", "1", "2", "3", "* /", "\n", "0", ".", "(-)", "=", ""};
|
"7", "8", "9", Symbols::backspace, "\n", "4", "5", "6", "+ -", "\n", "1", "2", "3", "* /", "\n", "0", ". ^", "(-)", "=", ""};
|
||||||
|
|
||||||
Calculator::Calculator() {
|
Calculator::Calculator() {
|
||||||
resultLabel = lv_label_create(lv_scr_act(), nullptr);
|
resultLabel = lv_label_create(lv_scr_act(), nullptr);
|
||||||
@ -72,6 +72,7 @@ void Calculator::HandleInput() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// we only compare the first char because it is enough
|
// we only compare the first char because it is enough
|
||||||
|
NRF_LOG_INFO("Operation Start: %c", operation);
|
||||||
switch (*buttonText) {
|
switch (*buttonText) {
|
||||||
case '0':
|
case '0':
|
||||||
case '1':
|
case '1':
|
||||||
@ -113,9 +114,28 @@ void Calculator::HandleInput() {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case '.':
|
case '.':
|
||||||
|
NRF_LOG_INFO("Button Pressed");
|
||||||
|
|
||||||
|
switch (operation) {
|
||||||
|
case ' ':
|
||||||
|
if (value != 0) {
|
||||||
|
Eval();
|
||||||
|
ResetInput();
|
||||||
|
}
|
||||||
|
operation = '^';
|
||||||
|
break;
|
||||||
|
case '^':
|
||||||
|
operation = ' ';
|
||||||
|
break;
|
||||||
|
default:
|
||||||
if (offset == FIXED_POINT_OFFSET) {
|
if (offset == FIXED_POINT_OFFSET) {
|
||||||
offset /= 10;
|
offset /= 10;
|
||||||
}
|
}
|
||||||
|
operation = '.';
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
UpdateOperation();
|
||||||
|
|
||||||
NRF_LOG_INFO(". offset: %" PRId64, offset);
|
NRF_LOG_INFO(". offset: %" PRId64, offset);
|
||||||
NRF_LOG_INFO(". value: %" PRId64, value);
|
NRF_LOG_INFO(". value: %" PRId64, value);
|
||||||
@ -219,7 +239,7 @@ void Calculator::HandleInput() {
|
|||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
NRF_LOG_INFO("Operation End: %c", operation);
|
||||||
UpdateValueLabel();
|
UpdateValueLabel();
|
||||||
UpdateResultLabel();
|
UpdateResultLabel();
|
||||||
}
|
}
|
||||||
@ -250,6 +270,18 @@ void Calculator::UpdateOperation() const {
|
|||||||
lv_obj_set_style_local_bg_grad_color(buttonMatrix, LV_BTNMATRIX_PART_BTN, LV_STATE_CHECKED, Colors::deepOrange);
|
lv_obj_set_style_local_bg_grad_color(buttonMatrix, LV_BTNMATRIX_PART_BTN, LV_STATE_CHECKED, Colors::deepOrange);
|
||||||
lv_btnmatrix_set_btn_ctrl(buttonMatrix, 11, LV_BTNMATRIX_CTRL_CHECK_STATE);
|
lv_btnmatrix_set_btn_ctrl(buttonMatrix, 11, LV_BTNMATRIX_CTRL_CHECK_STATE);
|
||||||
break;
|
break;
|
||||||
|
case '^':
|
||||||
|
lv_obj_set_style_local_bg_grad_dir(buttonMatrix, LV_BTNMATRIX_PART_BTN, LV_STATE_CHECKED, LV_GRAD_DIR_HOR);
|
||||||
|
lv_obj_set_style_local_bg_color(buttonMatrix, LV_BTNMATRIX_PART_BTN, LV_STATE_CHECKED, Colors::bgAlt);
|
||||||
|
lv_obj_set_style_local_bg_grad_color(buttonMatrix, LV_BTNMATRIX_PART_BTN, LV_STATE_CHECKED, Colors::deepOrange);
|
||||||
|
lv_btnmatrix_set_btn_ctrl(buttonMatrix, 13, LV_BTNMATRIX_CTRL_CHECK_STATE);
|
||||||
|
break;
|
||||||
|
case '.':
|
||||||
|
lv_obj_set_style_local_bg_grad_dir(buttonMatrix, LV_BTNMATRIX_PART_BTN, LV_STATE_CHECKED, LV_GRAD_DIR_HOR);
|
||||||
|
lv_obj_set_style_local_bg_color(buttonMatrix, LV_BTNMATRIX_PART_BTN, LV_STATE_CHECKED, Colors::deepOrange);
|
||||||
|
lv_obj_set_style_local_bg_grad_color(buttonMatrix, LV_BTNMATRIX_PART_BTN, LV_STATE_CHECKED, Colors::bgAlt);
|
||||||
|
lv_btnmatrix_set_btn_ctrl(buttonMatrix, 13, LV_BTNMATRIX_CTRL_CHECK_STATE);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
lv_btnmatrix_clear_btn_ctrl_all(buttonMatrix, LV_BTNMATRIX_CTRL_CHECK_STATE);
|
lv_btnmatrix_clear_btn_ctrl_all(buttonMatrix, LV_BTNMATRIX_CTRL_CHECK_STATE);
|
||||||
break;
|
break;
|
||||||
@ -390,6 +422,16 @@ void Calculator::Eval() {
|
|||||||
result *= FIXED_POINT_OFFSET;
|
result *= FIXED_POINT_OFFSET;
|
||||||
result /= value;
|
result /= value;
|
||||||
break;
|
break;
|
||||||
|
case '^':
|
||||||
|
// check for zero division
|
||||||
|
if (value == 0) {
|
||||||
|
error = Error::ZeroDivision;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
result /= FIXED_POINT_OFFSET;
|
||||||
|
result = pow(result, (value*0.0001))*10000;
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
Loading…
Reference in New Issue
Block a user