From c0f7213110e8f7995d87bfba169090d2bc59181a Mon Sep 17 00:00:00 2001 From: = <=> Date: Sun, 2 Aug 2020 21:53:30 +0100 Subject: [PATCH] Can now receive code snippets from a phone! Font adjustment tries (cheaply) to account for newlines --- package.json | 7 +++++-- src/calc.c | 25 +++++++++++++++++++++---- src/calc.h | 3 +++ 3 files changed, 29 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index 58bc404..92a5296 100644 --- a/package.json +++ b/package.json @@ -21,7 +21,10 @@ }, "projectType": "native", "uuid": "70ec170a-8e1b-11ea-bc55-0242ac130003", - "messageKeys": {}, + "messageKeys": { + "ScriptNum": 0, + "ScriptText": 1 + }, "enableMultiJS": false, "displayName": "PebbLisp", "watchapp": { @@ -38,4 +41,4 @@ ] }, "name": "PebbLisp" -} \ No newline at end of file +} diff --git a/src/calc.c b/src/calc.c index 215ae51..e6ebe61 100644 --- a/src/calc.c +++ b/src/calc.c @@ -64,10 +64,15 @@ static const int smallestFont = 3; static void adjustFont() { int i = 0; - while(temptext[i++]) {} - int f = i < 50 ? smallestFont - 3 : - i < 100 ? smallestFont - 2 : - i < 130 ? smallestFont - 1 : + int size = 0; + while(temptext[i++]) { + if(temptext[i] == '\n') + size += 10; + size++; + } + int f = size < 50 ? smallestFont - 3 : + size < 100 ? smallestFont - 2 : + size < 130 ? smallestFont - 1 : smallestFont; text_layer_set_font(s_input_text_layer, fonts_get_system_font(fonts[f])); @@ -321,6 +326,16 @@ Object add_window(Object obj1, Object obj2, struct Environment *env) return numberObject(1); } +static void inbox_received_callback(DictionaryIterator *iter, void *context) { + Tuple *script_tuple = dict_find(iter, MESSAGE_KEY_ScriptText); + if(script_tuple) { + char *script_text = script_tuple->value->cstring; + snprintf(temptext, sizeof(temptext), "%s", script_text); + snprintf(mytext, sizeof(mytext), "%s", script_text); + updateText(); + } +} + /** General **/ static struct Environment pebbleEnv() @@ -341,6 +356,8 @@ static void init(void) .unload = menu_unload }); window_stack_push(s_menu_window, true); + app_message_open(inbox_size, outbox_size); + app_message_register_inbox_received(inbox_received_callback); } static void deinit(void) diff --git a/src/calc.h b/src/calc.h index 933125a..420f0cc 100644 --- a/src/calc.h +++ b/src/calc.h @@ -64,6 +64,9 @@ const char *func_tokens[] = { "sq ", "cube ", "exp " }; +const uint32_t inbox_size = 1024; +const uint32_t outbox_size = 64; + bool using_func_tokens = false; #endif