From 7d54e9e6f91b874fce364d7e36283a26fd91c0b8 Mon Sep 17 00:00:00 2001 From: Your Name Date: Sun, 23 Aug 2026 11:43:31 +0300 Subject: [PATCH] Second --- README.md | 4 +- TODO.md | 6 + package.json | 41 +----- screenshots/pic2.png | Bin 0 -> 6814 bytes src/c/items.c | 290 ++++++++----------------------------------- src/pkjs/config.js | 274 ++-------------------------------------- 6 files changed, 74 insertions(+), 541 deletions(-) create mode 100644 TODO.md create mode 100644 screenshots/pic2.png diff --git a/README.md b/README.md index a078e9f..5a188e7 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,7 @@ This is source code for "Percentage" pebble app. It tracks success/fail rates of 9 items. It was designed in cloudpebble. + ## Features @@ -20,5 +21,4 @@ This is source code for "Percentage" pebble app. It tracks success/fail rates of ## Resources * Pixelorama project files (Blue/Red/Green) -* C code -* Silkscreen font \ No newline at end of file +* C code \ No newline at end of file diff --git a/TODO.md b/TODO.md new file mode 100644 index 0000000..b27af45 --- /dev/null +++ b/TODO.md @@ -0,0 +1,6 @@ +# TODO + +* Configurable ORANGE/RED limits +* RED & GREEN theme +* Automatic smaller font to allow more characters? +* add "fail/success" display system (red/green) \ No newline at end of file diff --git a/package.json b/package.json index 235f581..b5e8063 100644 --- a/package.json +++ b/package.json @@ -12,42 +12,11 @@ "displayName": "Percentage", "enableMultiJS": true, "messageKeys": [ - "ITEM_1", - "ITEM_2", - "ITEM_3", - "ITEM_4", - "ITEM_5", - "ITEM_6", - "ITEM_7", - "ITEM_8", - "ITEM_9", - "ITEM_1_SUCCESS", - "ITEM_1_FAIL", - "ITEM_1_PERCENTAGE", - "ITEM_2_SUCCESS", - "ITEM_2_FAIL", - "ITEM_2_PERCENTAGE", - "ITEM_3_SUCCESS", - "ITEM_3_FAIL", - "ITEM_3_PERCENTAGE", - "ITEM_4_SUCCESS", - "ITEM_4_FAIL", - "ITEM_4_PERCENTAGE", - "ITEM_5_SUCCESS", - "ITEM_5_FAIL", - "ITEM_5_PERCENTAGE", - "ITEM_6_SUCCESS", - "ITEM_6_FAIL", - "ITEM_6_PERCENTAGE", - "ITEM_7_SUCCESS", - "ITEM_7_FAIL", - "ITEM_7_PERCENTAGE", - "ITEM_8_SUCCESS", - "ITEM_8_FAIL", - "ITEM_8_PERCENTAGE", - "ITEM_9_SUCCESS", - "ITEM_9_FAIL", - "ITEM_9_PERCENTAGE" + "ITEM_NAME", + "ITEM_SUCCESS", + "ITEM_FAIL", + "ITEM_PERCENTAGE", + "ITEM_REMOVE" ], "projectType": "native", "resources": { diff --git a/screenshots/pic2.png b/screenshots/pic2.png new file mode 100644 index 0000000000000000000000000000000000000000..7a3e38a4337c560a86ac9e14c275bcb665be3137 GIT binary patch literal 6814 zcmXw;2UHWm+J+OO2_+#xP&xzzQBXj7Cj!ztC@Mt|6r@Y9A#{)`NbewB14wT{6r^{N z4oWff9(v%9_x|^sZD)7B-I<*;^L+0+5jtARFbYNr0000}RZ-LSbZr#jI z<7T~7N9%AtWf|yt>0q-ZSi%NIa z%mc}CBf__7>99D9znYGNz89m<{Y~c$_7#0;CV*sy;f`g?)j|TXG;Sb-Je)c%q@$zc zt?y>1lB$c79>{;%RVD|ki!b*12B2PI!k}`Dg>o3gyD?-4BvcAK)l=lgFFQ_Ha%%|; zUdHNP?dmbZhjoBj`s?$HuJogV7%G15y=k21_$EW|P8(CP=+i3Jd4#UxT##v;Z!%q_ zwO$u*TF;Rn?}_kQc%;z2&Mc19KwQg0!nPt?{wK2X-HNTW!y$PD`Fd$S=MFtE`|tuh?d!1)#x!KC$=z;Ntw!TzEb8L+N9z9sq((U3jx$hB1ZOE zC)S`#|9XNyj;6_d>8W3qd=w}KJr^qNYCNGCePo-6)&7gGJ0<-Hh8!XDXHS5H2EIIaJUl&a7-xd`%?;{m<7!26!2fxu6oXCc{wG zsE0@(P`;cDF-!`@fixe%rJCDMq`73e8gP!&uVT?sm#NzV{p-4)uamYAtvmFj(Bcb4 z!66n&bZjk6>b^502TH4Q-d)&3PFPK7psj^4L#JO7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$q2*7B1a<$H;W699xt}U^Jkhoo zV_3@N{Hw#v=@;Icx-c61IqlUo;_VCL{g@MRe7t$$w4@yFAO;m2M^^j_NVL75FwTKUtEVCW(^~dG07xJ&Loi zi6N}~Dtg>$=(2U#5$c!-?@$v)$wNw&Tes|OXN2;z9+z^(GhF$Y^wXC4zNOhIpu|}n zD_DGUt;REI6rz&oVelCIxcT@wz0)b+jrk4XAH#ybC3{H|vmwP!DQ1uG!f8xed~fHX zo_PI=iItZC>SKTbmf=n|aQq^h^}QHsXOm7&&UXY+aNaLb(_$wKk#OEIZ1YlNIg{`F zZ>?Rx#z%nEFny0{2JvXeNO6+PR6K5HMn}?Z2DM&tD_Cx!tzWAjDW#mzTWEPkmxM;F zh>b;fX3~JeF_bb7YsI37_hv ziBpBPKV?7#lccqiq1xAGUEiw?H{Jn&d0)w2sjVNq6NYc%fo?E9;Nz>|mO0M-Uo!-E pAf&~m%S*l{auDeP{4b>h0XDv~83uTG$dc{=R3B+6V&%;O{|{dABtZZG literal 0 HcmV?d00001 diff --git a/src/c/items.c b/src/c/items.c index 3b530e8..981a5c3 100644 --- a/src/c/items.c +++ b/src/c/items.c @@ -1,4 +1,6 @@ #include +#include + #include "items.h" #include "src/c/scrolllayer.h" @@ -41,281 +43,95 @@ item_list_t *items_get() { return &s_items; } +// ------------ HELPERS ------------ +static int str_case_cmp(const char *a, const char *b, size_t n) { + for (size_t i = 0; i < n; i++) { + unsigned char ca = (unsigned char)a[i]; + unsigned char cb = (unsigned char)b[i]; + + int lca = tolower(ca); + int lcb = tolower(cb); + + if (lca != lcb) { + return lca - lcb; + } + if (ca == '\0') { + return 0; + } + } + return 0; +} + // ------------ PHONE ------------ -static void update_items(item_list_t *items, const item_list_t *buffer) { - if (!items || !buffer) { +static void update_items(item_list_t *items, const item_t *item, bool remove) { + if (!items || !item || item->name[0] == '\0') { return; } - // Check existing items + // Find existing item for (int i = 0; i < MAX_ITEMS; i++) { - if (items->items[i].name[0] == '\0') { - continue; - } - - bool found = false; - for (int j = 0; j < MAX_ITEMS; j++) { - if (buffer->items[j].name[0] != '\0' && strcmp(items->items[i].name, buffer->items[j].name) == 0) { - - // Item still exists - items->items[i].show_percentage = buffer->items[j].show_percentage; - found = true; - break; + if (items->items[i].name[0] != '\0' && str_case_cmp(items->items[i].name, item->name, MAX_CHARACTERS) == 0) { + if (remove) { + memset(&items->items[i], 0, sizeof(items->items[i])); + } + else { + items->items[i].show_percentage = item->show_percentage; } - } - - // Item no longer exists - if (!found) { - memset(&items->items[i], 0, sizeof(items->items[i])); + return; } } - // Add items - for (int i = 0; i < MAX_ITEMS; i++) { - if (buffer->items[i].name[0] == '\0') { - continue; - } - - bool found = false; - for (int j = 0; j < MAX_ITEMS; j++) { - if (items->items[j].name[0] != '\0' && strcmp(items->items[j].name, buffer->items[i].name) == 0) { - found = true; + // Not found + if (!remove) { + for (int i = 0; i < MAX_ITEMS; i++) { + if (items->items[i].name[0] == '\0') { + items->items[i] = *item; break; } } - - if (!found) { - for (int j = 0; j < MAX_ITEMS; j++) { - if (items->items[j].name[0] == '\0') { - memcpy(&items->items[j], &buffer->items[i], sizeof(items->items[j])); - break; - } - } - } } - - items_organize(items); } static void inbox_received_handler(DictionaryIterator *iter, void *context) { // Remove scroll layer items scroll_layer_remove_items(); - Tuple *tuple; - item_list_t item_buffer; + Tuple *tuple;; + item_t item; + memset(&item, 0, sizeof(item)); + bool remove = false; // Get the item 1 - tuple = dict_find(iter, MESSAGE_KEY_ITEM_1); + tuple = dict_find(iter, MESSAGE_KEY_ITEM_NAME); if (tuple) { - strncpy(item_buffer.items[0].name, tuple->value->cstring, MAX_CHARACTERS); + strncpy(item.name, tuple->value->cstring, MAX_CHARACTERS); + item.name[MAX_CHARACTERS - 1] = '\0'; } - tuple = dict_find(iter, MESSAGE_KEY_ITEM_1_SUCCESS); + tuple = dict_find(iter, MESSAGE_KEY_ITEM_SUCCESS); if (tuple) { int success = atoi(tuple->value->cstring); if (success < 0) { success = 0; } - item_buffer.items[0].successes = success; + item.successes = success; } - tuple = dict_find(iter, MESSAGE_KEY_ITEM_1_FAIL); + tuple = dict_find(iter, MESSAGE_KEY_ITEM_FAIL); if (tuple) { int fail = atoi(tuple->value->cstring); if (fail < 0) { fail = 0; } - item_buffer.items[0].fails = fail; + item.fails = fail; } - tuple = dict_find(iter, MESSAGE_KEY_ITEM_1_PERCENTAGE); + tuple = dict_find(iter, MESSAGE_KEY_ITEM_PERCENTAGE); if (tuple) { bool show_percentage = tuple->value->int32 != 0; - item_buffer.items[0].show_percentage = show_percentage; + item.show_percentage = show_percentage; } - - // Get the item 2 - tuple = dict_find(iter, MESSAGE_KEY_ITEM_2); + // Add or remove + tuple = dict_find(iter, MESSAGE_KEY_ITEM_REMOVE); if (tuple) { - strncpy(item_buffer.items[1].name, tuple->value->cstring, MAX_CHARACTERS); + remove = tuple->value->int32 != 0; } - tuple = dict_find(iter, MESSAGE_KEY_ITEM_2_SUCCESS); - if (tuple) { - int success = atoi(tuple->value->cstring); - if (success < 0) { success = 0; } - item_buffer.items[1].successes = success; - } - tuple = dict_find(iter, MESSAGE_KEY_ITEM_2_FAIL); - if (tuple) { - int fail = atoi(tuple->value->cstring); - if (fail < 0) { fail = 0; } - item_buffer.items[1].fails = fail; - } - tuple = dict_find(iter, MESSAGE_KEY_ITEM_2_PERCENTAGE); - if (tuple) { - bool show_percentage = tuple->value->int32 != 0; - item_buffer.items[1].show_percentage = show_percentage; - } - - // Get the item 3 - tuple = dict_find(iter, MESSAGE_KEY_ITEM_3); - if (tuple) { - strncpy(item_buffer.items[2].name, tuple->value->cstring, MAX_CHARACTERS); - } - tuple = dict_find(iter, MESSAGE_KEY_ITEM_3_SUCCESS); - if (tuple) { - int success = atoi(tuple->value->cstring); - if (success < 0) { success = 0; } - item_buffer.items[2].successes = success; - } - tuple = dict_find(iter, MESSAGE_KEY_ITEM_3_FAIL); - if (tuple) { - int fail = atoi(tuple->value->cstring); - if (fail < 0) { fail = 0; } - item_buffer.items[2].fails = fail; - } - tuple = dict_find(iter, MESSAGE_KEY_ITEM_3_PERCENTAGE); - if (tuple) { - bool show_percentage = tuple->value->int32 != 0; - item_buffer.items[2].show_percentage = show_percentage; - } - - // Get the item 4 - tuple = dict_find(iter, MESSAGE_KEY_ITEM_4); - if (tuple) { - strncpy(item_buffer.items[3].name, tuple->value->cstring, MAX_CHARACTERS); - } - tuple = dict_find(iter, MESSAGE_KEY_ITEM_4_SUCCESS); - if (tuple) { - int success = atoi(tuple->value->cstring); - if (success < 0) { success = 0; } - item_buffer.items[3].successes = success; - } - tuple = dict_find(iter, MESSAGE_KEY_ITEM_4_FAIL); - if (tuple) { - int fail = atoi(tuple->value->cstring); - if (fail < 0) { fail = 0; } - item_buffer.items[3].fails = fail; - } - tuple = dict_find(iter, MESSAGE_KEY_ITEM_4_PERCENTAGE); - if (tuple) { - bool show_percentage = tuple->value->int32 != 0; - item_buffer.items[3].show_percentage = show_percentage; - } - - // Get the item 5 - tuple = dict_find(iter, MESSAGE_KEY_ITEM_5); - if (tuple) { - strncpy(item_buffer.items[4].name, tuple->value->cstring, MAX_CHARACTERS); - } - tuple = dict_find(iter, MESSAGE_KEY_ITEM_5_SUCCESS); - if (tuple) { - int success = atoi(tuple->value->cstring); - if (success < 0) { success = 0; } - item_buffer.items[4].successes = success; - } - tuple = dict_find(iter, MESSAGE_KEY_ITEM_5_FAIL); - if (tuple) { - int fail = atoi(tuple->value->cstring); - if (fail < 0) { fail = 0; } - item_buffer.items[4].fails = fail; - } - tuple = dict_find(iter, MESSAGE_KEY_ITEM_5_PERCENTAGE); - if (tuple) { - bool show_percentage = tuple->value->int32 != 0; - item_buffer.items[4].show_percentage = show_percentage; - } - - // Get the item 6 - tuple = dict_find(iter, MESSAGE_KEY_ITEM_6); - if (tuple) { - strncpy(item_buffer.items[5].name, tuple->value->cstring, MAX_CHARACTERS); - } - tuple = dict_find(iter, MESSAGE_KEY_ITEM_6_SUCCESS); - if (tuple) { - int success = atoi(tuple->value->cstring); - if (success < 0) { success = 0; } - item_buffer.items[5].successes = success; - } - tuple = dict_find(iter, MESSAGE_KEY_ITEM_6_FAIL); - if (tuple) { - int fail = atoi(tuple->value->cstring); - if (fail < 0) { fail = 0; } - item_buffer.items[5].fails = fail; - } - tuple = dict_find(iter, MESSAGE_KEY_ITEM_6_PERCENTAGE); - if (tuple) { - bool show_percentage = tuple->value->int32 != 0; - item_buffer.items[5].show_percentage = show_percentage; - } - - // Get the item 7 - tuple = dict_find(iter, MESSAGE_KEY_ITEM_7); - if (tuple) { - strncpy(item_buffer.items[6].name, tuple->value->cstring, MAX_CHARACTERS); - } - tuple = dict_find(iter, MESSAGE_KEY_ITEM_7_SUCCESS); - if (tuple) { - int success = atoi(tuple->value->cstring); - if (success < 0) { success = 0; } - item_buffer.items[6].successes = success; - } - tuple = dict_find(iter, MESSAGE_KEY_ITEM_7_FAIL); - if (tuple) { - int fail = atoi(tuple->value->cstring); - if (fail < 0) { fail = 0; } - item_buffer.items[6].fails = fail; - } - tuple = dict_find(iter, MESSAGE_KEY_ITEM_7_PERCENTAGE); - if (tuple) { - bool show_percentage = tuple->value->int32 != 0; - item_buffer.items[6].show_percentage = show_percentage; - } - - // Get the item 8 - tuple = dict_find(iter, MESSAGE_KEY_ITEM_8); - if (tuple) { - strncpy(item_buffer.items[7].name, tuple->value->cstring, MAX_CHARACTERS); - } - tuple = dict_find(iter, MESSAGE_KEY_ITEM_8_SUCCESS); - if (tuple) { - int success = atoi(tuple->value->cstring); - if (success < 0) { success = 0; } - item_buffer.items[7].successes = success; - } - tuple = dict_find(iter, MESSAGE_KEY_ITEM_8_FAIL); - if (tuple) { - int fail = atoi(tuple->value->cstring); - if (fail < 0) { fail = 0; } - item_buffer.items[7].fails = fail; - } - tuple = dict_find(iter, MESSAGE_KEY_ITEM_8_PERCENTAGE); - if (tuple) { - bool show_percentage = tuple->value->int32 != 0; - item_buffer.items[7].show_percentage = show_percentage; - } - - // Get the item 9 - tuple = dict_find(iter, MESSAGE_KEY_ITEM_9); - if (tuple) { - strncpy(item_buffer.items[8].name, tuple->value->cstring, MAX_CHARACTERS); - } - tuple = dict_find(iter, MESSAGE_KEY_ITEM_9_SUCCESS); - if (tuple) { - int success = atoi(tuple->value->cstring); - if (success < 0) { success = 0; } - item_buffer.items[8].successes = success; - } - tuple = dict_find(iter, MESSAGE_KEY_ITEM_9_FAIL); - if (tuple) { - int fail = atoi(tuple->value->cstring); - if (fail < 0) { fail = 0; } - item_buffer.items[8].fails = fail; - } - tuple = dict_find(iter, MESSAGE_KEY_ITEM_9_PERCENTAGE); - if (tuple) { - bool show_percentage = tuple->value->int32 != 0; - item_buffer.items[8].show_percentage = show_percentage; - } - - // Organize buffer - items_organize(&item_buffer); // Update list from buffer - update_items(&s_items, &item_buffer); + update_items(&s_items, &item, remove); // Save the items to NVM items_organize(&s_items); diff --git a/src/pkjs/config.js b/src/pkjs/config.js index 6be4d1a..542d3b4 100644 --- a/src/pkjs/config.js +++ b/src/pkjs/config.js @@ -5,7 +5,7 @@ module.exports = [ }, { "type": "text", - "defaultValue": "Character limit is 10. If numbers go higher than 1000, use percentage." + "defaultValue": "Add/remove up to 9 items. Character limit is 10. If numbers go higher than 1000, use percentage." }, { @@ -13,293 +13,35 @@ module.exports = [ "items": [ { "type": "heading", - "defaultValue": "Item 1" + "defaultValue": "Item" }, { "type": "input", - "messageKey": "ITEM_1", + "messageKey": "ITEM_NAME", "defaultValue": "" }, { "type": "input", - "messageKey": "ITEM_1_SUCCESS", + "messageKey": "ITEM_SUCCESS", "label": "Success", "defaultValue": "0" }, { "type": "input", - "messageKey": "ITEM_1_FAIL", + "messageKey": "ITEM_FAIL", "label": "Fail", "defaultValue": "0" }, { "type": "toggle", - "messageKey": "ITEM_1_PERCENTAGE", + "messageKey": "ITEM_PERCENTAGE", "label": "Show percentage", "defaultValue": false - } - ] - }, - - { - "type": "section", - "items": [ - { - "type": "heading", - "defaultValue": "Item 2" - }, - { - "type": "input", - "messageKey": "ITEM_2", - "defaultValue": "" - }, - { - "type": "input", - "messageKey": "ITEM_2_SUCCESS", - "label": "Success", - "defaultValue": "0" - }, - { - "type": "input", - "messageKey": "ITEM_2_FAIL", - "label": "Fail", - "defaultValue": "0" }, { "type": "toggle", - "messageKey": "ITEM_2_PERCENTAGE", - "label": "Show percentage", - "defaultValue": false - } - ] - }, - - { - "type": "section", - "items": [ - { - "type": "heading", - "defaultValue": "Item 3" - }, - { - "type": "input", - "messageKey": "ITEM_3", - "defaultValue": "" - }, - { - "type": "input", - "messageKey": "ITEM_3_SUCCESS", - "label": "Success", - "defaultValue": "0" - }, - { - "type": "input", - "messageKey": "ITEM_3_FAIL", - "label": "Fail", - "defaultValue": "0" - }, - { - "type": "toggle", - "messageKey": "ITEM_3_PERCENTAGE", - "label": "Show percentage", - "defaultValue": false - } - ] - }, - - { - "type": "section", - "items": [ - { - "type": "heading", - "defaultValue": "Item 4" - }, - { - "type": "input", - "messageKey": "ITEM_4", - "defaultValue": "" - }, - { - "type": "input", - "messageKey": "ITEM_4_SUCCESS", - "label": "Success", - "defaultValue": "0" - }, - { - "type": "input", - "messageKey": "ITEM_4_FAIL", - "label": "Fail", - "defaultValue": "0" - }, - { - "type": "toggle", - "messageKey": "ITEM_4_PERCENTAGE", - "label": "Show percentage", - "defaultValue": false - } - ] - }, - - { - "type": "section", - "items": [ - { - "type": "heading", - "defaultValue": "Item 5" - }, - { - "type": "input", - "messageKey": "ITEM_5", - "defaultValue": "" - }, - { - "type": "input", - "messageKey": "ITEM_5_SUCCESS", - "label": "Success", - "defaultValue": "0" - }, - { - "type": "input", - "messageKey": "ITEM_5_FAIL", - "label": "Fail", - "defaultValue": "0" - }, - { - "type": "toggle", - "messageKey": "ITEM_5_PERCENTAGE", - "label": "Show percentage", - "defaultValue": false - } - ] - }, - - { - "type": "section", - "items": [ - { - "type": "heading", - "defaultValue": "Item 6" - }, - { - "type": "input", - "messageKey": "ITEM_6", - "defaultValue": "" - }, - { - "type": "input", - "messageKey": "ITEM_6_SUCCESS", - "label": "Success", - "defaultValue": "0" - }, - { - "type": "input", - "messageKey": "ITEM_6_FAIL", - "label": "Fail", - "defaultValue": "0" - }, - { - "type": "toggle", - "messageKey": "ITEM_6_PERCENTAGE", - "label": "Show percentage", - "defaultValue": false - } - ] - }, - - { - "type": "section", - "items": [ - { - "type": "heading", - "defaultValue": "Item 7" - }, - { - "type": "input", - "messageKey": "ITEM_7", - "defaultValue": "" - }, - { - "type": "input", - "messageKey": "ITEM_7_SUCCESS", - "label": "Success", - "defaultValue": "0" - }, - { - "type": "input", - "messageKey": "ITEM_7_FAIL", - "label": "Fail", - "defaultValue": "0" - }, - { - "type": "toggle", - "messageKey": "ITEM_7_PERCENTAGE", - "label": "Show percentage", - "defaultValue": false - } - ] - }, - - { - "type": "section", - "items": [ - { - "type": "heading", - "defaultValue": "Item 8" - }, - { - "type": "input", - "messageKey": "ITEM_8", - "defaultValue": "" - }, - { - "type": "input", - "messageKey": "ITEM_8_SUCCESS", - "label": "Success", - "defaultValue": "0" - }, - { - "type": "input", - "messageKey": "ITEM_8_FAIL", - "label": "Fail", - "defaultValue": "0" - }, - { - "type": "toggle", - "messageKey": "ITEM_8_PERCENTAGE", - "label": "Show percentage", - "defaultValue": false - } - ] - }, - - { - "type": "section", - "items": [ - { - "type": "heading", - "defaultValue": "Item 9" - }, - { - "type": "input", - "messageKey": "ITEM_9", - "defaultValue": "" - }, - { - "type": "input", - "messageKey": "ITEM_9_SUCCESS", - "label": "Success", - "defaultValue": "0" - }, - { - "type": "input", - "messageKey": "ITEM_9_FAIL", - "label": "Fail", - "defaultValue": "0" - }, - { - "type": "toggle", - "messageKey": "ITEM_9_PERCENTAGE", - "label": "Show percentage", + "messageKey": "ITEM_REMOVE", + "label": "Remove item", "defaultValue": false } ]