Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calculator App #375

Open
wants to merge 48 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
e20eb85
Hacking around at the calculator
Raupinger Feb 23, 2021
195af10
housekeeping. Removed some leftovers from rebasing on current develop…
Raupinger May 20, 2021
70fd0db
fixed some errors in the Shunting-yard implementation
Raupinger May 22, 2021
b25baea
Added alternative operator row to calculator
Raupinger May 22, 2021
df074b8
added haptic feedback for calculator errors, improved display of floats
Raupinger May 22, 2021
b17a56e
improved calculator back button
Raupinger May 22, 2021
7bc5db4
style improvements
Raupinger May 22, 2021
b21bb9d
decreased .text size by not using std::strtod and setting #pragma GCC…
Raupinger May 23, 2021
a88b5e8
removed some leftover code that was commented out
Raupinger May 26, 2021
397a5ec
Calculator: handling errors during calculation
Jun 2, 2021
4cec9f1
Calculator: use default initializers for stacks
Jun 7, 2021
9a67d86
Calculator: fixed memory leak by using smart pointers and fixed signs
Jun 18, 2021
3635a92
Calculator: handling literals like ".5" as "0.5" and checking bounds …
Jun 18, 2021
48c3941
cleaned up after rebase
Dec 9, 2021
05adc37
added calculator icon, moved motion app to the third settings screen …
Dec 9, 2021
7e0550e
Fixed calculator bug: a+b(c) was interpreted as b+c, not a+b*c.
Dec 9, 2021
de7faa8
added calculator documentation
Dec 9, 2021
ae0782b
Calculator: increased button size
Dec 9, 2021
559aa3d
Calculator: added overflow detection and fixed crash when trying to e…
Dec 10, 2021
0090f59
Calculator: fixed compiler warnings and formatting, reduced fond diff…
Dec 10, 2021
f1fe8f4
Calculator: code cleanup
Dec 10, 2021
8532337
Calculator: code cleanup
Dec 10, 2021
3c5d799
Calculator: Removed points above overflows from doc
Raupinger Dec 16, 2021
2915dcb
Hacking around at the calculator
Raupinger Feb 23, 2021
e9765f1
housekeeping. Removed some leftovers from rebasing on current develop…
Raupinger May 20, 2021
2c78dd0
fixed some errors in the Shunting-yard implementation
Raupinger May 22, 2021
f80684c
Added alternative operator row to calculator
Raupinger May 22, 2021
cfe618f
added haptic feedback for calculator errors, improved display of floats
Raupinger May 22, 2021
aa84c0b
improved calculator back button
Raupinger May 22, 2021
69c3ec9
style improvements
Raupinger May 22, 2021
ebfa399
decreased .text size by not using std::strtod and setting #pragma GCC…
Raupinger May 23, 2021
cb7310a
removed some leftover code that was commented out
Raupinger May 26, 2021
d5871ad
Calculator: handling errors during calculation
Jun 2, 2021
2d41e4f
Calculator: use default initializers for stacks
Jun 7, 2021
0385f1e
Calculator: fixed memory leak by using smart pointers and fixed signs
Jun 18, 2021
05d8e8f
Calculator: handling literals like ".5" as "0.5" and checking bounds …
Jun 18, 2021
1d0d58f
cleaned up after rebase
Dec 9, 2021
c2f4efa
added calculator icon, moved motion app to the third settings screen …
Dec 9, 2021
839d83f
Fixed calculator bug: a+b(c) was interpreted as b+c, not a+b*c.
Dec 9, 2021
c5b7e8a
added calculator documentation
Dec 9, 2021
1045528
Calculator: increased button size
Dec 9, 2021
f2c9484
Calculator: added overflow detection and fixed crash when trying to e…
Dec 10, 2021
2a12cdd
Calculator: fixed compiler warnings and formatting, reduced fond diff…
Dec 10, 2021
d55af65
Calculator: code cleanup
Dec 10, 2021
0782bd8
Calculator: code cleanup
Dec 10, 2021
65f9fa9
Calculator: Removed points above overflows from doc
Raupinger Dec 16, 2021
ff1ea0e
fonts/README: add calculator symbol to font generation documentation
NeroBurner Feb 26, 2022
6ff0f94
Merge remote-tracking branch 'NeroBurner/Calc_rebase' into Calc
Raupinger Feb 26, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions doc/Calculator.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Calculator Manual
This is a simple Calculator with support for the four basic arithmetic operations, parenthesis and exponents.
Here is what you need to know to make full use of it:
- Swipe left to access parenthesis and exponents:
![](./ui/calc2.jpg)
- A long tap on the screen will reset the text field to `0`.
- If the entered term is invalid, the watch will vibrate.
- results are rounded to 4 digits after the decimal point
- **TIP:** you can use `^(1/2)` to calculate square roots
Binary file added doc/ui/calc2.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/ui/calc3.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/ui/calc4.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,7 @@ list(APPEND SOURCE_FILES
displayapp/screens/List.cpp
displayapp/screens/BatteryInfo.cpp
displayapp/screens/Steps.cpp
displayapp/screens/Calculator.cpp
displayapp/screens/Timer.cpp
displayapp/screens/PassKey.cpp
displayapp/screens/Error.cpp
Expand Down Expand Up @@ -643,6 +644,7 @@ set(INCLUDE_FILES
displayapp/screens/HeartRate.h
displayapp/screens/Metronome.h
displayapp/screens/Motion.h
displayapp/screens/Calculator.h
displayapp/screens/Timer.h
displayapp/screens/Alarm.h
displayapp/Colors.h
Expand Down
1 change: 1 addition & 0 deletions src/displayapp/Apps.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ namespace Pinetime {
SettingChimes,
SettingShakeThreshold,
SettingAirplaneMode,
Calculator,
Error
};
}
Expand Down
4 changes: 4 additions & 0 deletions src/displayapp/DisplayApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "displayapp/screens/SystemInfo.h"
#include "displayapp/screens/Tile.h"
#include "displayapp/screens/Twos.h"
#include "displayapp/screens/Calculator.h"
#include "displayapp/screens/FlashLight.h"
#include "displayapp/screens/BatteryInfo.h"
#include "displayapp/screens/Steps.h"
Expand Down Expand Up @@ -482,6 +483,9 @@ void DisplayApp::LoadApp(Apps app, DisplayApp::FullRefreshDirections direction)
case Apps::Steps:
currentScreen = std::make_unique<Screens::Steps>(this, motionController, settingsController);
break;
case Apps::Calculator:
currentScreen = std::make_unique<Screens::Calculator>(this, motorController);
break;
}
currentApp = app;
}
Expand Down
2 changes: 1 addition & 1 deletion src/displayapp/fonts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* Do not enable font compression and horizontal subpixel hinting
* Load the file `JetBrainsMono-Bold.tff` (use the file in this repo to ensure the version matches) and specify the following range : `0x20-0x7f, 0x410-0x44f`
* Add a 2nd font, load the file `FontAwesome5-Solid+Brands+Regular.woff` and specify the following
range : `0xf293, 0xf294, 0xf244, 0xf240, 0xf242, 0xf243, 0xf241, 0xf54b, 0xf21e, 0xf1e6, 0xf54b, 0xf017, 0xf129, 0xf03a, 0xf185, 0xf560, 0xf001, 0xf3fd, 0xf069, 0xf1fc, 0xf45d, 0xf59f, 0xf5a0, 0xf029, 0xf027, 0xf028, 0xf6a9, 0xf04b, 0xf04c, 0xf048, 0xf051, 0xf095, 0xf3dd, 0xf04d, 0xf2f2, 0xf024, 0xf252, 0xf569, 0xf201, 0xf06e, 0xf015, 0xf072`
range : `0xf293, 0xf294, 0xf244, 0xf240, 0xf242, 0xf243, 0xf241, 0xf54b, 0xf21e, 0xf1e6, 0xf54b, 0xf017, 0xf129, 0xf03a, 0xf185, 0xf560, 0xf001, 0xf3fd, 0xf069, 0xf1fc, 0xf45d, 0xf59f, 0xf5a0, 0xf029, 0xf027, 0xf028, 0xf6a9, 0xf04b, 0xf04c, 0xf048, 0xf051, 0xf095, 0xf3dd, 0xf04d, 0xf2f2, 0xf024, 0xf252, 0xf569, 0xf201, 0xf06e, 0xf015, 0xf072, 0xf1ec`
* Click on Convert, and download the file `jetbrains_mono_bold_20.c` and copy it in `src/DisplayApp/Fonts`
* Add the font .c file path to src/CMakeLists.txt
* Add an LV_FONT_DECLARE line in src/libs/lv_conf.h
Expand Down
61 changes: 35 additions & 26 deletions src/displayapp/fonts/jetbrains_mono_bold_20.c
Original file line number Diff line number Diff line change
Expand Up @@ -880,6 +880,14 @@ static LV_ATTRIBUTE_LARGE_CONST const uint8_t glyph_bitmap[] = {
0x83, 0xfe, 0x3, 0xf8, 0x1, 0xc0, 0x3, 0x80,
0x7, 0x0, 0xe, 0x0,

/* U+F1EC "" */
0x7f, 0xff, 0xbf, 0xff, 0xfe, 0x0, 0x1f, 0x80,
0x7, 0xe0, 0x1, 0xf8, 0x0, 0x7e, 0x0, 0x1f,
0xff, 0xff, 0xff, 0xff, 0xf9, 0xce, 0x7e, 0x73,
0x9f, 0x9c, 0xe7, 0xff, 0xf9, 0xff, 0xfe, 0x7e,
0x73, 0x9f, 0x9c, 0xe7, 0xe7, 0x39, 0xff, 0xff,
0xf7, 0xff, 0xf8,

/* U+F1FC "" */
0x0, 0x0, 0xf0, 0x0, 0x1f, 0x0, 0x3, 0xf0,
0x0, 0x7e, 0x0, 0xf, 0xe0, 0x3, 0xfc, 0x0,
Expand Down Expand Up @@ -1235,27 +1243,28 @@ static const lv_font_fmt_txt_glyph_dsc_t glyph_dsc[] = {
{.bitmap_index = 3262, .adv_w = 120, .box_w = 8, .box_h = 19, .ofs_x = 0, .ofs_y = -2},
{.bitmap_index = 3281, .adv_w = 320, .box_w = 20, .box_h = 20, .ofs_x = 0, .ofs_y = -3},
{.bitmap_index = 3331, .adv_w = 240, .box_w = 15, .box_h = 19, .ofs_x = 0, .ofs_y = -2},
{.bitmap_index = 3367, .adv_w = 320, .box_w = 20, .box_h = 19, .ofs_x = 0, .ofs_y = -2},
{.bitmap_index = 3415, .adv_w = 320, .box_w = 21, .box_h = 15, .ofs_x = 0, .ofs_y = 0},
{.bitmap_index = 3455, .adv_w = 320, .box_w = 20, .box_h = 17, .ofs_x = 0, .ofs_y = -1},
{.bitmap_index = 3498, .adv_w = 400, .box_w = 25, .box_h = 12, .ofs_x = 0, .ofs_y = 1},
{.bitmap_index = 3536, .adv_w = 400, .box_w = 25, .box_h = 12, .ofs_x = 0, .ofs_y = 1},
{.bitmap_index = 3574, .adv_w = 400, .box_w = 25, .box_h = 12, .ofs_x = 0, .ofs_y = 1},
{.bitmap_index = 3612, .adv_w = 400, .box_w = 25, .box_h = 12, .ofs_x = 0, .ofs_y = 1},
{.bitmap_index = 3650, .adv_w = 400, .box_w = 25, .box_h = 12, .ofs_x = 0, .ofs_y = 1},
{.bitmap_index = 3688, .adv_w = 240, .box_w = 15, .box_h = 19, .ofs_x = 0, .ofs_y = -2},
{.bitmap_index = 3724, .adv_w = 280, .box_w = 15, .box_h = 20, .ofs_x = 1, .ofs_y = -3},
{.bitmap_index = 3762, .adv_w = 200, .box_w = 11, .box_h = 21, .ofs_x = 0, .ofs_y = -3},
{.bitmap_index = 3791, .adv_w = 280, .box_w = 16, .box_h = 19, .ofs_x = 1, .ofs_y = -2},
{.bitmap_index = 3829, .adv_w = 400, .box_w = 25, .box_h = 21, .ofs_x = 0, .ofs_y = -3},
{.bitmap_index = 3895, .adv_w = 360, .box_w = 23, .box_h = 17, .ofs_x = 0, .ofs_y = -1},
{.bitmap_index = 3944, .adv_w = 320, .box_w = 20, .box_h = 20, .ofs_x = 0, .ofs_y = -2},
{.bitmap_index = 3994, .adv_w = 400, .box_w = 25, .box_h = 19, .ofs_x = 0, .ofs_y = -2},
{.bitmap_index = 4054, .adv_w = 320, .box_w = 20, .box_h = 21, .ofs_x = 0, .ofs_y = -3},
{.bitmap_index = 4107, .adv_w = 360, .box_w = 23, .box_h = 21, .ofs_x = 0, .ofs_y = -3},
{.bitmap_index = 4168, .adv_w = 360, .box_w = 22, .box_h = 20, .ofs_x = 0, .ofs_y = -2},
{.bitmap_index = 4223, .adv_w = 360, .box_w = 22, .box_h = 19, .ofs_x = 0, .ofs_y = -2},
{.bitmap_index = 4276, .adv_w = 320, .box_w = 20, .box_h = 15, .ofs_x = 0, .ofs_y = 0}
{.bitmap_index = 3367, .adv_w = 280, .box_w = 18, .box_h = 19, .ofs_x = 0, .ofs_y = -2},
{.bitmap_index = 3410, .adv_w = 320, .box_w = 20, .box_h = 19, .ofs_x = 0, .ofs_y = -2},
{.bitmap_index = 3458, .adv_w = 320, .box_w = 21, .box_h = 15, .ofs_x = 0, .ofs_y = 0},
{.bitmap_index = 3498, .adv_w = 320, .box_w = 20, .box_h = 17, .ofs_x = 0, .ofs_y = -1},
{.bitmap_index = 3541, .adv_w = 400, .box_w = 25, .box_h = 12, .ofs_x = 0, .ofs_y = 1},
{.bitmap_index = 3579, .adv_w = 400, .box_w = 25, .box_h = 12, .ofs_x = 0, .ofs_y = 1},
{.bitmap_index = 3617, .adv_w = 400, .box_w = 25, .box_h = 12, .ofs_x = 0, .ofs_y = 1},
{.bitmap_index = 3655, .adv_w = 400, .box_w = 25, .box_h = 12, .ofs_x = 0, .ofs_y = 1},
{.bitmap_index = 3693, .adv_w = 400, .box_w = 25, .box_h = 12, .ofs_x = 0, .ofs_y = 1},
{.bitmap_index = 3731, .adv_w = 240, .box_w = 15, .box_h = 19, .ofs_x = 0, .ofs_y = -2},
{.bitmap_index = 3767, .adv_w = 280, .box_w = 15, .box_h = 20, .ofs_x = 1, .ofs_y = -3},
{.bitmap_index = 3805, .adv_w = 200, .box_w = 11, .box_h = 21, .ofs_x = 0, .ofs_y = -3},
{.bitmap_index = 3834, .adv_w = 280, .box_w = 16, .box_h = 19, .ofs_x = 1, .ofs_y = -2},
{.bitmap_index = 3872, .adv_w = 400, .box_w = 25, .box_h = 21, .ofs_x = 0, .ofs_y = -3},
{.bitmap_index = 3938, .adv_w = 360, .box_w = 23, .box_h = 17, .ofs_x = 0, .ofs_y = -1},
{.bitmap_index = 3987, .adv_w = 320, .box_w = 20, .box_h = 20, .ofs_x = 0, .ofs_y = -2},
{.bitmap_index = 4037, .adv_w = 400, .box_w = 25, .box_h = 19, .ofs_x = 0, .ofs_y = -2},
{.bitmap_index = 4097, .adv_w = 320, .box_w = 20, .box_h = 21, .ofs_x = 0, .ofs_y = -3},
{.bitmap_index = 4150, .adv_w = 360, .box_w = 23, .box_h = 21, .ofs_x = 0, .ofs_y = -3},
{.bitmap_index = 4211, .adv_w = 360, .box_w = 22, .box_h = 20, .ofs_x = 0, .ofs_y = -2},
{.bitmap_index = 4266, .adv_w = 360, .box_w = 22, .box_h = 19, .ofs_x = 0, .ofs_y = -2},
{.bitmap_index = 4319, .adv_w = 320, .box_w = 20, .box_h = 15, .ofs_x = 0, .ofs_y = 0}
};

/*---------------------
Expand All @@ -1265,10 +1274,10 @@ static const lv_font_fmt_txt_glyph_dsc_t glyph_dsc[] = {
static const uint16_t unicode_list_2[] = {
0x0, 0x14, 0x16, 0x23, 0x26, 0x27, 0x28, 0x39,
0x47, 0x4a, 0x4b, 0x4c, 0x50, 0x68, 0x6d, 0x71,
0x94, 0x128, 0x184, 0x1e5, 0x1fb, 0x200, 0x21d, 0x23f,
0x240, 0x241, 0x242, 0x243, 0x251, 0x292, 0x293, 0x2f1,
0x3dc, 0x3fc, 0x45c, 0x54a, 0x55f, 0x568, 0x59e, 0x59f,
0x6a8
0x94, 0x128, 0x184, 0x1e5, 0x1eb, 0x1fb, 0x200, 0x21d,
0x23f, 0x240, 0x241, 0x242, 0x243, 0x251, 0x292, 0x293,
0x2f1, 0x3dc, 0x3fc, 0x45c, 0x54a, 0x55f, 0x568, 0x59e,
0x59f, 0x6a8
};

/*Collect the unicode lists and glyph_id offsets*/
Expand All @@ -1284,7 +1293,7 @@ static const lv_font_fmt_txt_cmap_t cmaps[] =
},
{
.range_start = 61441, .range_length = 1705, .glyph_id_start = 160,
.unicode_list = unicode_list_2, .glyph_id_ofs_list = NULL, .list_length = 41, .type = LV_FONT_FMT_TXT_CMAP_SPARSE_TINY
.unicode_list = unicode_list_2, .glyph_id_ofs_list = NULL, .list_length = 42, .type = LV_FONT_FMT_TXT_CMAP_SPARSE_TINY
}
};

Expand Down
2 changes: 1 addition & 1 deletion src/displayapp/screens/ApplicationList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ std::unique_ptr<Screen> ApplicationList::CreateScreen2() {
{Symbols::paintbrush, Apps::Paint},
{Symbols::paddle, Apps::Paddle},
{"2", Apps::Twos},
{Symbols::chartLine, Apps::Motion},
{Symbols::calculator, Apps::Calculator},
{Symbols::drum, Apps::Metronome},
{Symbols::clock, Apps::Alarm},
}};
Expand Down
Loading