Compare commits

...

4 Commits

Author SHA1 Message Date
tofasthacker
f025bef793 fixed calculator comments
(cherry picked from commit 8a40eaa9c5)
2024-05-08 17:21:58 -04:00
tofasthacker
1114911926 moved backspace and changed around the math for exponent
(cherry picked from commit c87a297a2f)
2024-05-08 17:21:48 -04:00
a73933f5fa Added enviroment_setup.md
(cherry picked from commit 65976a2b23)
2024-05-08 17:21:24 -04:00
tofasthacker
039c337ea1 working exponent math
(cherry picked from commit 86695db883)
2024-05-08 17:21:00 -04:00
3 changed files with 183 additions and 41 deletions

94
enviroment_setup.md Executable file
View File

@ -0,0 +1,94 @@
## Clone repositories
1. Clone InfiniTime:
```bash
git clone https://github.com/InfiniTimeOrg/InfiniTime.git
cd InfiniTime
git submodule update --init
```
2. Clone InfiniSim:
```bash
cd .. #Ignore this line if you already cd'd into the diretory you want it cloned into
git clone --recursive https://github.com/InfiniTimeOrg/InfiniSim.git
```
## Install dependencies
### For building InfiniTime
1. Install Docker
2. Pull docker container (optional, container will be pulled when running the docker container if not pulled now).
```bash
sudo docker pull infinitime/infinitime-build
```
### For building InfiniSim
This was the most difficult part for me to get right since the steps on the github page are not entirely complete for my setup. If you encounter errors while building, it's probably because one of the dependencies are missing or have the wrong version installed. If you do have an error while building, check out the issues on github and see if you can find some help there: https://github.com/InfiniTimeOrg/InfiniSim/issues
1. The apt install part. This is almost exactly the same as what is on the github page except for npm. When I added npm in to here, I got an older version that didn't work. We'll install the correct version in step 2.
```bash
sudo apt install -y cmake libsdl2-dev g++ libpng-dev
```
2. Install the correct node version. (At least v14.0.0 is required). Commands from https://github.com/nodesource/distributions First, choose the node version by running one of these lines:
```bash
NODE_MAJOR=16
NODE_MAJOR=18
NODE_MAJOR=20
```
I'm not sure which is the best to use, I went with 16 since that is the closest to the version required by InfiniSim, but I doubt it makes much of a difference. Once you've done that, then install it with these commands:
```bash
sudo apt-get update
sudo apt-get install -y ca-certificates curl gnupg
sudo mkdir -p /etc/apt/keyrings
curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | sudo gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg
NODE_MAJOR=20
echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_$NODE_MAJOR.x nodistro main" | sudo tee /etc/apt/sources.list.d/nodesource.list
sudo apt-get update
sudo apt-get install nodejs -y
```
3. Install npm packages
```bash
npm install lv_font_conv@1.5.2 -g
npm install ts-node@10.9.1 @swc/core@1.3.82 lv_img_conv@0.3.0 -g
```
## Build InfiniSim
### Building with stock InfiniTime
Now to see if we did everything the way our computer wants it. First cd into the directory where InfinSim was cloned (`cd InfiniSim` if you are still in the directory you started in). Now you should be able to build InfiniSim with the InfiniTime version that was included with InfiniSim:
```bash
cmake -S . -B build
cmake --build build -j4
```
If that didn't produce any error, now run it!
```bash
./build/infinisim
```
### Building with your own version of InfiniTime
To test your own modifications of InfiniTime:
```bash
cmake -S . -B build -DInfiniTime_DIR=../InfiniTime
cmake --build build -j4
```
Assuming that the git clone command was run in the same directory for both InfiniSim and InfiniTime. If not, replace `../InfiniTime` with the path to the directory where InfiniTime was cloned to.
And now run it if there were no errors!
```bash
./build/infinisim
```
## Build InfiniTime
Now is the fun part, building your own version of InfiniTime and flashing it to your watch!
First, cd into the directory into which InfiniTime cloned (`cd ~/InfiniTime` if you cloned from your home directory). Now run the docker container (for more info on this command, see https://github.com/InfiniTimeOrg/InfiniTime/blob/main/doc/buildWithDocker.md):
```bash
docker run --rm -it -v ${PWD}:/sources --user $(id -u):$(id -g) infinitime/infinitime-build
```
If that doesn't have any errors, it will save the files to build/output/. The file you will want to flash to your watch is `pinetime-mcuboot-app-dfu-x.x.x.zip`. I found a pretty nice program called WatchMate that you can use to flash it from linux, but I think you can also use Gadgetbridge to flash the file. In WatchMate, just scroll down to the "Firmware Version" dropdown and click on "Upload from file" >
"Firmware" and select the zip file mentioned above. Once that's done, you may also want to send it the `infinitime-resources-x.x.x.zip` if some features are greyed out on the watch (for me it was a couple watch faces and the navigation app that were greyed out). In WatchMate, you'll want to use the "Resources" option instead of the "Firmware" option to upload this file.
## Celebrate
There you go, you've just flashed your own custom os to your watch! If you got all this far without running into any error, you have something to celebrate about as it took me a couple of days to get to this point. If you did have some errors and figured them out, then great, you've got it all figured out now!
One final thing, I would recommend making use of git commits and branches so that you can revert if you totally mess something up and don't have to clone the entire repository and dependencies again like I had to do several times before I decided to start doing that.

View File

@ -17,7 +17,7 @@ Calculator::~Calculator() {
}
static const char* buttonMap[] = {
"7", "8", "9", Symbols::backspace, "\n", "4", "5", "6", "+ -", "\n", "1", "2", "3", "* /", "\n", "0", ".", "(-)", "=", ""};
"7", "8", "9", "^", "\n", "4", "5", "6", "+ -", "\n", "1", "2", "3", "* /", "\n", "0", ".", "(-)", "=", ""};
Calculator::Calculator() {
resultLabel = lv_label_create(lv_scr_act(), nullptr);
@ -25,14 +25,14 @@ Calculator::Calculator() {
lv_label_set_align(resultLabel, LV_LABEL_ALIGN_RIGHT);
lv_label_set_text_fmt(resultLabel, "%" PRId64, result);
lv_obj_set_size(resultLabel, 200, 20);
lv_obj_set_pos(resultLabel, 10, 5);
lv_obj_set_pos(resultLabel, -30, 5);
valueLabel = lv_label_create(lv_scr_act(), nullptr);
lv_label_set_long_mode(valueLabel, LV_LABEL_LONG_CROP);
lv_label_set_align(valueLabel, LV_LABEL_ALIGN_RIGHT);
lv_label_set_text_fmt(valueLabel, "%" PRId64, value);
lv_obj_set_size(valueLabel, 200, 20);
lv_obj_set_pos(valueLabel, 10, 35);
lv_obj_set_pos(valueLabel, -30, 35);
buttonMatrix = lv_btnmatrix_create(lv_scr_act(), nullptr);
buttonMatrix->user_data = this;
@ -51,17 +51,66 @@ Calculator::Calculator() {
lv_obj_set_style_local_bg_opa(buttonMatrix, LV_BTNMATRIX_PART_BTN, LV_STATE_CHECKED, LV_OPA_COVER);
lv_obj_set_style_local_bg_grad_stop(buttonMatrix, LV_BTNMATRIX_PART_BTN, LV_STATE_CHECKED, 128);
lv_obj_set_style_local_bg_main_stop(buttonMatrix, LV_BTNMATRIX_PART_BTN, LV_STATE_CHECKED, 128);
// BackSpace Button
back = lv_btn_create(lv_scr_act(), nullptr);
back->user_data = this;
lv_obj_set_event_cb(back, eventHandler);
lv_obj_set_size(back, 59, 44);
lv_obj_align(back, lv_scr_act(), LV_ALIGN_IN_TOP_LEFT, 179, 16);
txtback = lv_label_create(back, nullptr);
lv_obj_set_style_local_bg_color(back, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, Colors::bgAlt);
lv_label_set_text_static(txtback, Symbols::backspace);
}
void Calculator::OnButtonEvent(lv_obj_t* obj, lv_event_t event) {
if ((obj == buttonMatrix) && (event == LV_EVENT_PRESSED)) {
HandleInput();
}
if (obj == back && event == LV_EVENT_PRESSED) {
if (value != 0) {
// delete one value digit
if (offset < FIXED_POINT_OFFSET) {
if (offset == 0) {
offset = 1;
} else {
offset *= 10;
}
} else {
value /= 10;
}
if (offset < FIXED_POINT_OFFSET) {
value -= value % (10 * offset);
} else {
value -= value % offset;
}
} else if (offset < FIXED_POINT_OFFSET) {
if (offset == 0) {
offset = 1;
} else {
offset *= 10;
}
} else {
// reset the result
result = 0;
}
operation = ' ';
UpdateOperation();
UpdateValueLabel();
UpdateResultLabel();
}
}
void Calculator::HandleInput() {
const char* buttonText = lv_btnmatrix_get_active_btn_text(buttonMatrix);
if (buttonText == nullptr) {
return;
}
@ -112,6 +161,7 @@ void Calculator::HandleInput() {
break;
// Decimal
case '.':
if (offset == FIXED_POINT_OFFSET) {
offset /= 10;
@ -126,6 +176,22 @@ void Calculator::HandleInput() {
// - eval the current operator if value > FIXED_POINT_OFFSET
// - then set the new operator
// - + and - as well as * and / cycle on the same button
case '^':
if (value != 0) {
Eval();
ResetInput();
}
switch (operation) {
case ' ':
operation = '^';
break;
default:
operation = ' ';
break;
}
UpdateOperation();
break;
case '+':
if (value != 0) {
Eval();
@ -166,43 +232,6 @@ void Calculator::HandleInput() {
UpdateOperation();
break;
// this is a little hacky because it matches only the first char
case Symbols::backspace[0]:
if (value != 0) {
// delete one value digit
if (offset < FIXED_POINT_OFFSET) {
if (offset == 0) {
offset = 1;
} else {
offset *= 10;
}
} else {
value /= 10;
}
if (offset < FIXED_POINT_OFFSET) {
value -= value % (10 * offset);
} else {
value -= value % offset;
}
} else if (offset < FIXED_POINT_OFFSET) {
if (offset == 0) {
offset = 1;
} else {
offset *= 10;
}
} else {
// reset the result
result = 0;
}
NRF_LOG_INFO(". offset: %" PRId64, offset);
NRF_LOG_INFO(". value: %" PRId64, value);
NRF_LOG_INFO(". result: %" PRId64, result);
operation = ' ';
UpdateOperation();
break;
case '=':
equalSignPressed = true;
Eval();
@ -219,7 +248,7 @@ void Calculator::HandleInput() {
break;
}
NRF_LOG_INFO("Operation End: %c", operation);
UpdateValueLabel();
UpdateResultLabel();
}
@ -250,6 +279,12 @@ void Calculator::UpdateOperation() const {
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);
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::deepOrange);
lv_btnmatrix_set_btn_ctrl(buttonMatrix, 3, LV_BTNMATRIX_CTRL_CHECK_STATE);
break;
default:
lv_btnmatrix_clear_btn_ctrl_all(buttonMatrix, LV_BTNMATRIX_CTRL_CHECK_STATE);
break;
@ -390,6 +425,16 @@ void Calculator::Eval() {
result *= FIXED_POINT_OFFSET;
result /= value;
break;
case '^':
// check for zero division
if (value == 0) {
error = Error::ZeroDivision;
break;
}
place_holder = result;
place_holder /= FIXED_POINT_OFFSET;
result = pow(place_holder, (value*0.0001))*10000;
break;
default:
break;

View File

@ -31,6 +31,9 @@ namespace Pinetime {
lv_obj_t* buttonMatrix {};
lv_obj_t* valueLabel {};
lv_obj_t* resultLabel {};
lv_obj_t* back;
lv_obj_t* txtback;
double place_holder;
void Eval();
void ResetInput();