Merge branch 'working_calculator'

This commit is contained in:
tofasthacker 2023-09-23 23:04:13 -04:00
commit 990ad0c87e
8 changed files with 27 additions and 23 deletions

View File

@ -393,7 +393,7 @@ list(APPEND SOURCE_FILES
displayapp/screens/ApplicationList.cpp
displayapp/screens/Notifications.cpp
displayapp/screens/Twos.cpp
displayapp/screens/TestApp.cpp
displayapp/screens/Calculator.cpp
displayapp/screens/HeartRate.cpp
displayapp/screens/Motion.cpp
displayapp/screens/FlashLight.cpp

View File

@ -38,7 +38,7 @@ namespace Pinetime {
SettingShakeThreshold,
SettingBluetooth,
Error,
TestApp
Calculator
};
}
}

View File

@ -32,7 +32,7 @@
#include "displayapp/screens/Weather.h"
// My New Apps
#include "displayapp/screens/TestApp.h"
#include "displayapp/screens/Calculator.h"
#include "drivers/Cst816s.h"
#include "drivers/St7789.h"
@ -555,8 +555,8 @@ void DisplayApp::LoadScreen(Apps app, DisplayApp::FullRefreshDirections directio
currentScreen = std::make_unique<Screens::Steps>(motionController, settingsController);
break;
// My Apps
case Apps::TestApp:
currentScreen = std::make_unique<Screens::TestApp>();
case Apps::Calculator:
currentScreen = std::make_unique<Screens::Calculator>();
break;
}
currentApp = app;

View File

@ -7,7 +7,7 @@
},
{
"file": "FontAwesome5-Solid+Brands+Regular.woff",
"range": "0xf294, 0xf242, 0xf54b, 0xf21e, 0xf1e6, 0xf017, 0xf129, 0xf03a, 0xf185, 0xf560, 0xf001, 0xf3fd, 0xf1fc, 0xf45d, 0xf59f, 0xf5a0, 0xf027, 0xf028, 0xf6a9, 0xf04b, 0xf04c, 0xf048, 0xf051, 0xf095, 0xf3dd, 0xf04d, 0xf2f2, 0xf024, 0xf252, 0xf569, 0xf06e, 0xf015, 0xf00c"
"range": "0xf294, 0xf242, 0xf54b, 0xf21e, 0xf1e6, 0xf017, 0xf129, 0xf03a, 0xf185, 0xf560, 0xf001, 0xf3fd, 0xf1fc, 0xf45d, 0xf59f, 0xf5a0, 0xf027, 0xf028, 0xf6a9, 0xf04b, 0xf04c, 0xf048, 0xf051, 0xf095, 0xf3dd, 0xf04d, 0xf2f2, 0xf024, 0xf252, 0xf569, 0xf06e, 0xf015, 0xf00c, 0xf1ec, 0xf55a"
}
],
"bpp": 1,

View File

@ -55,7 +55,7 @@ namespace Pinetime {
{"2", Apps::Twos, true},
{Symbols::drum, Apps::Metronome, true},
{Symbols::map, Apps::Navigation, Applications::Screens::Navigation::IsAvailable(filesystem)},
{"T", Apps::TestApp, true},
{Symbols::calculator, Apps::Calculator, true},
//{Symbols::none, Apps::None, false},
// {"M", Apps::Motion},

View File

@ -1,25 +1,25 @@
#include <cmath>
#include <cinttypes>
#include <libraries/log/nrf_log.h>
#include "TestApp.h"
#include "Calculator.h"
#include "displayapp/InfiniTimeTheme.h"
#include "Symbols.h"
using namespace Pinetime::Applications::Screens;
static void eventHandler(lv_obj_t* obj, lv_event_t event) {
auto app = static_cast<TestApp*>(obj->user_data);
auto app = static_cast<Calculator*>(obj->user_data);
app->OnButtonEvent(obj, event);
}
TestApp::~TestApp() {
Calculator::~Calculator() {
lv_obj_clean(lv_scr_act());
}
static const char* buttonMap[] = {
"7", "8", "9", "B"/*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", ".", "(-)", "=", ""};
TestApp::TestApp() {
Calculator::Calculator() {
resultLabel = lv_label_create(lv_scr_act(), nullptr);
lv_label_set_long_mode(resultLabel, LV_LABEL_LONG_CROP);
lv_label_set_align(resultLabel, LV_LABEL_ALIGN_RIGHT);
@ -53,13 +53,13 @@ TestApp::TestApp() {
lv_obj_set_style_local_bg_main_stop(buttonMatrix, LV_BTNMATRIX_PART_BTN, LV_STATE_CHECKED, 128);
}
void TestApp::OnButtonEvent(lv_obj_t* obj, lv_event_t event) {
void Calculator::OnButtonEvent(lv_obj_t* obj, lv_event_t event) {
if ((obj == buttonMatrix) && (event == LV_EVENT_PRESSED)) {
HandleInput();
}
}
void TestApp::HandleInput() {
void Calculator::HandleInput() {
const char* buttonText = lv_btnmatrix_get_active_btn_text(buttonMatrix);
if (buttonText == nullptr) {
@ -167,7 +167,7 @@ void TestApp::HandleInput() {
break;
// this is a little hacky because it matches only the first char
case 'B':
case Symbols::backspace[0]:
if (value != 0) {
// delete one value digit
if (offset < FIXED_POINT_OFFSET) {
@ -224,7 +224,7 @@ void TestApp::HandleInput() {
UpdateResultLabel();
}
void TestApp::UpdateOperation() const {
void Calculator::UpdateOperation() const {
switch (operation) {
case '+':
lv_obj_set_style_local_bg_grad_dir(buttonMatrix, LV_BTNMATRIX_PART_BTN, LV_STATE_CHECKED, LV_GRAD_DIR_HOR);
@ -256,7 +256,7 @@ void TestApp::UpdateOperation() const {
}
}
void TestApp::ResetInput() {
void Calculator::ResetInput() {
value = 0;
offset = FIXED_POINT_OFFSET;
operation = ' ';
@ -264,7 +264,7 @@ void TestApp::ResetInput() {
error = Error::None;
}
void TestApp::UpdateResultLabel() const {
void Calculator::UpdateResultLabel() const {
int64_t integer = result / FIXED_POINT_OFFSET;
int64_t remainder = result % FIXED_POINT_OFFSET;
bool negative = (remainder < 0);
@ -293,7 +293,7 @@ void TestApp::UpdateResultLabel() const {
}
}
void TestApp::UpdateValueLabel() {
void Calculator::UpdateValueLabel() {
switch (error) {
case Error::TooLarge:
lv_label_set_text_static(valueLabel, "too large");
@ -341,7 +341,7 @@ void TestApp::UpdateValueLabel() {
}
// update the result based on value and operation
void TestApp::Eval() {
void Calculator::Eval() {
switch (operation) {
case ' ':
result = value;

View File

@ -16,11 +16,11 @@ namespace {
namespace Pinetime {
namespace Applications {
namespace Screens {
class TestApp : public Screen {
class Calculator : public Screen {
public:
~TestApp() override;
~Calculator() override;
TestApp();
Calculator();
void OnButtonEvent(lv_obj_t* obj, lv_event_t event);

View File

@ -37,6 +37,10 @@ namespace Pinetime {
static constexpr const char* eye = "\xEF\x81\xAE";
static constexpr const char* home = "\xEF\x80\x95";
static constexpr const char* sleep = "\xEE\xBD\x84";
static constexpr const char* calculator = "\xEF\x87\xAC";
static constexpr const char* backspace = "\xEF\x95\x9A";
// fontawesome_weathericons.c
// static constexpr const char* sun = "\xEF\x86\x85";