From b6957c15c8ada68936faef6a77604ffe95a79920 Mon Sep 17 00:00:00 2001 From: Roger Braunstein Date: Thu, 7 Nov 2013 19:41:19 -0800 Subject: [PATCH] (somewhat painfully) upgrading to SDK 2.0 --- appinfo.json | 24 ++ build/pbl_pom.pbw | Bin 13166 -> 12118 bytes resources/{src => }/images/menu_icon.png | Bin resources/src/resource_map.json | 11 - src/debugging.h | 2 +- src/http.c | 490 ----------------------- src/http.h | 109 ----- src/pom.c | 169 ++++---- src/pom.h | 15 +- src/pom_cookies.c | 104 ++--- src/pom_cookies.h | 8 +- src/pom_menu.c | 60 +-- src/pom_menu.h | 2 +- src/pom_text.c | 4 +- src/pom_vibes.h | 2 +- 15 files changed, 197 insertions(+), 803 deletions(-) create mode 100644 appinfo.json rename resources/{src => }/images/menu_icon.png (100%) delete mode 100644 resources/src/resource_map.json delete mode 100644 src/http.c delete mode 100644 src/http.h diff --git a/appinfo.json b/appinfo.json new file mode 100644 index 0000000..3f6432c --- /dev/null +++ b/appinfo.json @@ -0,0 +1,24 @@ +{ + "uuid": "42b276d7-8f6f-449b-8903-d156c0d1e9bd", + "shortName": "PblPom", + "longName": "PblPom", + "companyName": "Partlyhuman", + "versionCode": 2.0, + "versionLabel": "2.0", + "watchapp": { + "watchface": false + }, + "appKeys": { + }, + "resources": { + "media": [ + { + "name": "IMAGE_MENU_ICON", + "type": "png", + "file": "images/menu_icon.png", + "menuIcon": true + } + ] + }, + "capabilities": [] +} diff --git a/build/pbl_pom.pbw b/build/pbl_pom.pbw index 2e3f72f9fd913c5f5c13056e4073cac9df6f9c90..043f99f70b9fc2573f61b1fc40f7f333f324431b 100644 GIT binary patch delta 4373 zcmZ`-4Rll09ltM0zY8t2VyLyeCV&yzlBOTD*n`DBGuqce1&+p}Xp%N1sr@2t8MJ9r zJj%)$b3gz)1!c%Mo(X3Kse<%bI6CJz-8od9!ww`9Hj6NQ1-B$kAp6~y@Wh=h?JxIt z|M&lK@Bel#XSZd8JDb*L`*5?-$*Xir?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vmj_dZFjV`v!)<8dHIy`Uq95uy+e-}oF}Kl{ryC|F_>x1434*CmfvSD%D#cq z;zanSr=LEHUk%=4O$zFlr;m111!=c4(Qf}esJDJ$e@7zSCVr(f1E=6=4eMo`w{z@X9n9hOg5dl4mF;d?0QP88y%6c{X;wseW!qA#Oqyl}Algzw}%sUAzV z{fJi^98>x$d%0H?j7R-1UWO%N9!4m{2xrd}2I}!pJd2D-#}Mgx6uoCGEP1Xy4!03{ z+O$iQ(V3l-;*QFu_6+7*3XlRCxVRSL)A^{z!MEde=N(xF-5<3+&posH>Wgrc`kB{mfgYSRE&45aI`p>`x?0TfA?^^`{Hriun^V3 zxc){42G!aNh1k$eiTPfhsGf%%|!S-0iJ;J%vZAf0e1X1 zh{vmF`!U+8(3WzFK^9MbzZkn01jE7`3Lg;K6)p(DJsRRn@CN8zW0B89&#*cJYU(4z2H zh0hg!SV+e!e$3_}Aw%IULYBgx7R(Cw>=8JnvO_3Sc&*@4c#W`0;hO}v!Z!%p6z&je z75=brP~oeEHia)2PAS|XbW`q$`ew0kUJ(=tL50r~H1K(BHD*Dl@LVBD;Zp^@!lwx7 z3eONS6rLtzDLhHoq;Rd^p^p{)t;a`?)xc}Oqrf&`5AZC&0cF4@;4nbHo}2=X0pI^! zf*bIp;#D1QStzdqw}AjE9{_&fU4X_$8W8n=9tidKLZA#-13WW|Lnw~|jTq=4@I3ed zV9zMFp=<)y0Y3#U02hHd&@BS!#4P}wJZ@gm1=>+Q3OIoEQ#^#YKXYeLu`jo#79=2Y z5>&p=W~^Q@Z{F // RELEASE is set by the build system (waf configure --debug). // On debug builds, it simply omits this define. diff --git a/src/http.c b/src/http.c deleted file mode 100644 index 608923f..0000000 --- a/src/http.c +++ /dev/null @@ -1,490 +0,0 @@ -/* - * httpebble stuff - * Copyright (C) 2013 Katharine Berry - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in - * the Software without restriction, including without limitation the rights to - * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of - * the Software, and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS - * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR - * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER - * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - -#include "pebble_os.h" -#include "http.h" - -#define HTTP_URL_KEY 0xFFFF -#define HTTP_STATUS_KEY 0xFFFE -#define HTTP_COOKIE_KEY 0xFFFC -#define HTTP_CONNECT_KEY 0xFFFB -#define HTTP_USE_GET_KEY 0xFFFA - -#define HTTP_APP_ID_KEY 0xFFF2 -#define HTTP_COOKIE_STORE_KEY 0xFFF0 -#define HTTP_COOKIE_LOAD_KEY 0xFFF1 -#define HTTP_COOKIE_FSYNC_KEY 0xFFF3 -#define HTTP_COOKIE_DELETE_KEY 0xFFF4 - -#define HTTP_TIME_KEY 0xFFF5 -#define HTTP_UTC_OFFSET_KEY 0xFFF6 -#define HTTP_IS_DST_KEY 0xFFF7 -#define HTTP_TZ_NAME_KEY 0xFFF8 - -#define HTTP_LOCATION_KEY 0xFFE0 -#define HTTP_LATITUDE_KEY 0xFFE1 -#define HTTP_LONGITUDE_KEY 0xFFE2 -#define HTTP_ALTITUDE_KEY 0xFFE3 - -static bool callbacks_registered; -static AppMessageCallbacksNode app_callbacks; -static HTTPCallbacks http_callbacks; -static int32_t our_app_id; - -static void app_send_failed(DictionaryIterator* failed, AppMessageResult reason, void* context); -static void app_received(DictionaryIterator* received, void* context); -static void app_dropped(void* context, AppMessageResult reason); - -HTTPResult http_out_get(const char* url, int32_t cookie, DictionaryIterator **iter_out) { - AppMessageResult app_result = app_message_out_get(iter_out); - if(app_result != APP_MSG_OK) { - return app_result; - } - DictionaryResult dict_result = dict_write_cstring(*iter_out, HTTP_URL_KEY, url); - if(dict_result != DICT_OK) { - return dict_result << 12; - } - dict_result = dict_write_int32(*iter_out, HTTP_COOKIE_KEY, cookie); - if(dict_result != DICT_OK) { - return dict_result << 12; - } - dict_result = dict_write_int32(*iter_out, HTTP_APP_ID_KEY, our_app_id); - if(dict_result != DICT_OK) { - return dict_result << 12; - } - return HTTP_OK; -} - - -HTTPResult http_out_send() { - AppMessageResult result = app_message_out_send(); - app_message_out_release(); // We don't care if it's already released. - return result; -} - -bool http_register_callbacks(HTTPCallbacks callbacks, void* context) { - http_callbacks = callbacks; - if(callbacks_registered) { - if(app_message_deregister_callbacks(&app_callbacks) == APP_MSG_OK) - callbacks_registered = false; - } - if(!callbacks_registered) { - app_callbacks = (AppMessageCallbacksNode){ - .callbacks = { - .out_failed = app_send_failed, - .in_received = app_received, - .in_dropped = app_dropped, - }, - .context = context - }; - if(app_message_register_callbacks(&app_callbacks) == APP_MSG_OK) - callbacks_registered = true; - } - return callbacks_registered; -} - -static void app_send_failed(DictionaryIterator* failed, AppMessageResult reason, void* context) { - if(!http_callbacks.failure) return; - http_callbacks.failure(0, 1000 + reason, context); -} - -static void app_received_http_response(DictionaryIterator* received, bool success, void* context) { - Tuple* status_tuple = dict_find(received, HTTP_STATUS_KEY); - Tuple* cookie_tuple = dict_find(received, HTTP_COOKIE_KEY); - if(status_tuple == NULL || cookie_tuple == NULL) { - if(http_callbacks.failure) { - http_callbacks.failure(0, 1000 + HTTP_INVALID_BRIDGE_RESPONSE, context); - } - return; - } - uint16_t status = status_tuple->value->int16; - int32_t cookie = cookie_tuple->value->int32; - if(!success) { - if(http_callbacks.failure) { - http_callbacks.failure(cookie, status, context); - } - return; - } - if(http_callbacks.success) { - http_callbacks.success(cookie, status, received, context); - } -} - -static void app_received_cookie_set_response(int32_t request_id, void* context) { - if(http_callbacks.cookie_set) { - http_callbacks.cookie_set(request_id, true, context); - } -} - -static void app_received_cookie_get_response(int32_t request_id, DictionaryIterator* iter, void* context) { - if(http_callbacks.cookie_batch_get) { - http_callbacks.cookie_batch_get(request_id, iter, context); - } - if(http_callbacks.cookie_get) { - Tuple* tuple = dict_read_first(iter); - if(!tuple) return; - do { - // Don't pass along reserved values. - if(tuple->key >= 0xF000 && tuple->key <= 0xFFFF) continue; - http_callbacks.cookie_get(request_id, tuple, context); - } while((tuple = dict_read_next(iter))); - } -} - -static void app_received_cookie_fsync_response(bool successful, void* context) { - if(http_callbacks.cookie_fsync) { - http_callbacks.cookie_fsync(successful, context); - } -} -static void app_received_cookie_delete_response(int32_t request_id, void* context) { - if(http_callbacks.cookie_delete) { - http_callbacks.cookie_delete(request_id, true, context); - } -} - -static void app_received_time(uint32_t unixtime, DictionaryIterator *iter, void* context) { - if(!http_callbacks.time) return; - int32_t utc_offset; - bool is_dst; - const char* tz_name; - Tuple* tuple = dict_find(iter, HTTP_UTC_OFFSET_KEY); - if(!tuple) return; - utc_offset = tuple->value->int32; - tuple = dict_find(iter, HTTP_IS_DST_KEY); - if(!tuple) return; - is_dst = tuple->value->uint8; - tuple = dict_find(iter, HTTP_TZ_NAME_KEY); - if(!tuple) return; - tz_name = tuple->value->cstring; - http_callbacks.time(utc_offset, is_dst, unixtime, tz_name, context); -} - -// Handy helper for getting floats out of ints. -struct alias_float { - float f; -} __attribute__((__may_alias__)); - -float floatFromUint32(uint32_t value) { - return ((struct alias_float*)&value)->f; -} - -static void app_received_location(uint32_t accuracy_int, DictionaryIterator *iter, void* context) { - if(!http_callbacks.location) return; - float accuracy = floatFromUint32(accuracy_int); - float latitude = 0.f; - float longitude = 0.f; - float altitude = 0.f; - - Tuple* tuple = dict_read_first(iter); - if(!tuple) return; - do { - switch(tuple->key) { - case HTTP_LATITUDE_KEY: - latitude = floatFromUint32(tuple->value->uint32); - break; - case HTTP_LONGITUDE_KEY: - longitude = floatFromUint32(tuple->value->uint32); - break; - case HTTP_ALTITUDE_KEY: - altitude = floatFromUint32(tuple->value->uint32); - break; - default: - break; - } - } while((tuple = dict_read_next(iter))); - http_callbacks.location(latitude, longitude, altitude, accuracy, context); -} - -static void app_received(DictionaryIterator* received, void* context) { - // Reconnect message (special: no app id) - Tuple* tuple = dict_find(received, HTTP_CONNECT_KEY); - if(tuple && tuple->value->uint8) { - if(http_callbacks.reconnect) { - http_callbacks.reconnect(context); - } - return; - } - // Time response (special: no app id) - tuple = dict_find(received, HTTP_TIME_KEY); - if(tuple) { - app_received_time(tuple->value->uint32, received, context); - return; - } - // Location response (special: no app id) - tuple = dict_find(received, HTTP_LOCATION_KEY); - if(tuple) { - app_received_location(tuple->value->uint32, received, context); - return; - } - // Check for the app id - tuple = dict_find(received, HTTP_APP_ID_KEY); - if(!tuple) { - return; - } - // Ignore it if it isn't ours. - if(tuple->value->int32 != our_app_id) return; - - // HTTP responses - tuple = dict_find(received, HTTP_URL_KEY); - if(tuple) { - app_received_http_response(received, tuple->value->uint8, context); - return; - } - - // Cookie set confirmation - tuple = dict_find(received, HTTP_COOKIE_STORE_KEY); - if(tuple) { - app_received_cookie_set_response(tuple->value->int32, context); - return; - } - - // Cookie get response - tuple = dict_find(received, HTTP_COOKIE_LOAD_KEY); - if(tuple) { - app_received_cookie_get_response(tuple->value->int32, received, context); - return; - } - - // Save response - tuple = dict_find(received, HTTP_COOKIE_FSYNC_KEY); - if(tuple) { - app_received_cookie_fsync_response(tuple->value->uint8, context); - return; - } - - // Delete response - tuple = dict_find(received, HTTP_COOKIE_DELETE_KEY); - if(tuple) { - app_received_cookie_delete_response(tuple->value->int32, context); - return; - } -} - -static void app_dropped(void* context, AppMessageResult reason) { - if(!http_callbacks.failure) return; - http_callbacks.failure(0, 1000 + reason, context); -} - -// Time stuff -HTTPResult http_time_request() { - DictionaryIterator *iter; - AppMessageResult app_result = app_message_out_get(&iter); - if(app_result != APP_MSG_OK) { - return app_result; - } - DictionaryResult dict_result = dict_write_uint8(iter, HTTP_TIME_KEY, 1); - if(dict_result != DICT_OK) { - return dict_result << 12; - } - app_result = app_message_out_send(); - app_message_out_release(); - return app_result; -} - -// Location stuff -HTTPResult http_location_request() { - DictionaryIterator *iter; - AppMessageResult app_result = app_message_out_get(&iter); - if(app_result != APP_MSG_OK) { - return app_result; - } - DictionaryResult dict_result = dict_write_uint8(iter, HTTP_LOCATION_KEY, 1); - if(dict_result != DICT_OK) { - return dict_result << 12; - } - app_result = app_message_out_send(); - app_message_out_release(); - return app_result; -} - -// Cookie stuff -void http_set_app_id(int32_t new_app_id) { - our_app_id = new_app_id; -} - -HTTPResult http_cookie_set_start(int32_t request_id, DictionaryIterator **iter_out) { - AppMessageResult app_result = app_message_out_get(iter_out); - if(app_result != APP_MSG_OK) { - return app_result; - } - DictionaryResult dict_result = dict_write_int32(*iter_out, HTTP_COOKIE_STORE_KEY, request_id); - if(dict_result != DICT_OK) { - return dict_result << 12; - } - dict_result = dict_write_int32(*iter_out, HTTP_APP_ID_KEY, our_app_id); - if(dict_result != DICT_OK) { - return dict_result << 12; - } - return HTTP_OK; -} - -HTTPResult http_cookie_set_end() { - AppMessageResult result = app_message_out_send(); - app_message_out_release(); // We don't care if it's already released. - return result; -} - -HTTPResult http_cookie_get_multiple(int32_t request_id, uint32_t* keys, int32_t length) { - // Basic setup - DictionaryIterator *iter; - AppMessageResult app_result = app_message_out_get(&iter); - if(app_result != APP_MSG_OK) { - return app_result; - } - DictionaryResult dict_result = dict_write_int32(iter, HTTP_COOKIE_LOAD_KEY, request_id); - if(dict_result != DICT_OK) { - app_message_out_release(); - return dict_result << 12; - } - dict_result = dict_write_int32(iter, HTTP_APP_ID_KEY, our_app_id); - if(dict_result != DICT_OK) { - app_message_out_release(); - return dict_result << 12; - } - // Add the keys - for(int i = 0; i < length; ++i) { - dict_result = dict_write_uint8(iter, keys[i], 1); - if(dict_result != DICT_OK) { - app_message_out_release(); - return dict_result << 12; - } - } - // Send it. - app_result = app_message_out_send(); - app_message_out_release(); - return app_result; -} - -HTTPResult http_cookie_delete_multiple(int32_t request_id, uint32_t* keys, int32_t length) { - // Basic setup - DictionaryIterator *iter; - AppMessageResult app_result = app_message_out_get(&iter); - if(app_result != APP_MSG_OK) { - return app_result; - } - DictionaryResult dict_result = dict_write_int32(iter, HTTP_COOKIE_DELETE_KEY, request_id); - if(dict_result != DICT_OK) { - app_message_out_release(); - return dict_result << 12; - } - dict_result = dict_write_int32(iter, HTTP_APP_ID_KEY, our_app_id); - if(dict_result != DICT_OK) { - app_message_out_release(); - return dict_result << 12; - } - // Add the keys - for(int i = 0; i < length; ++i) { - dict_result = dict_write_uint8(iter, keys[i], 1); - if(dict_result != DICT_OK) { - app_message_out_release(); - return dict_result << 12; - } - } - // Send it. - app_result = app_message_out_send(); - app_message_out_release(); - return app_result; -} - -HTTPResult http_cookie_fsync() { - DictionaryIterator *iter; - AppMessageResult app_result = app_message_out_get(&iter); - if(app_result != APP_MSG_OK) { - return app_result; - } - DictionaryResult dict_result = dict_write_int32(iter, HTTP_APP_ID_KEY, our_app_id); - if(dict_result != DICT_OK) { - return dict_result << 12; - } - app_result = app_message_out_send(); - app_message_out_release(); - return app_result; -} - -HTTPResult http_cookie_set_int(uint32_t request_id, uint32_t key, const void* integer, uint8_t width_bytes, bool is_signed) { - DictionaryIterator *iter; - HTTPResult http_result = http_cookie_set_start(request_id, &iter); - if(http_result != HTTP_OK) { - return http_result; - } - DictionaryResult dict_result = dict_write_int(iter, key, integer, width_bytes, is_signed); - if(dict_result != DICT_OK) { - app_message_out_release(); - return dict_result << 12; - } - return http_cookie_set_end(); -} - -HTTPResult http_cookie_set_cstring(uint32_t request_id, uint32_t key, const char* value) { - DictionaryIterator *iter; - HTTPResult http_result = http_cookie_set_start(request_id, &iter); - if(http_result != HTTP_OK) { - return http_result; - } - DictionaryResult dict_result = dict_write_cstring(iter, key, value); - if(dict_result != DICT_OK) { - app_message_out_release(); - return dict_result << 12; - } - return http_cookie_set_end(); -} - -HTTPResult http_cookie_set_data(uint32_t request_id, uint32_t key, const uint8_t* const value, int length) { - DictionaryIterator *iter; - HTTPResult http_result = http_cookie_set_start(request_id, &iter); - if(http_result != HTTP_OK) { - return http_result; - } - DictionaryResult dict_result = dict_write_data(iter, key, value, length); - if(dict_result != DICT_OK) { - app_message_out_release(); - return dict_result << 12; - } - return http_cookie_set_end(); -} - -HTTPResult http_cookie_get(uint32_t request_id, uint32_t key) { - return http_cookie_get_multiple(request_id, &key, 1); -} - -HTTPResult http_cookie_delete(uint32_t request_id, uint32_t key) { - return http_cookie_delete_multiple(request_id, &key, 1); -} - -HTTPResult http_cookie_set_int32(uint32_t request_id, uint32_t key, int32_t value) { - return http_cookie_set_int(request_id, key, &value, 4, true); -} -HTTPResult http_cookie_set_uint32(uint32_t request_id, uint32_t key, uint32_t value) { - return http_cookie_set_int(request_id, key, &value, 4, false); -} -HTTPResult http_cookie_set_int16(uint32_t request_id, uint32_t key, int16_t value) { - return http_cookie_set_int(request_id, key, &value, 2, true); -} -HTTPResult http_cookie_set_uint16(uint32_t request_id, uint32_t key, uint16_t value) { - return http_cookie_set_int(request_id, key, &value, 2, false); -} -HTTPResult http_cookie_set_int8(uint32_t request_id, uint32_t key, int8_t value) { - return http_cookie_set_int(request_id, key, &value, 1, true); -} -HTTPResult http_cookie_set_uint8(uint32_t request_id, uint32_t key, uint8_t value) { - return http_cookie_set_int(request_id, key, &value, 1, false); -} diff --git a/src/http.h b/src/http.h deleted file mode 100644 index 34617a0..0000000 --- a/src/http.h +++ /dev/null @@ -1,109 +0,0 @@ -/* - * httpebble header - * Copyright (C) 2013 Katharine Berry - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in - * the Software without restriction, including without limitation the rights to - * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of - * the Software, and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS - * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR - * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER - * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - -#ifndef HTTP_H -#define HTTP_H - -#define HTTP_UUID { 0x91, 0x41, 0xB6, 0x28, 0xBC, 0x89, 0x49, 0x8E, 0xB1, 0x47, 0x04, 0x9F, 0x49, 0xC0, 0x99, 0xAD } - -// Shared values. -typedef enum { - HTTP_OK = 0, - HTTP_SEND_TIMEOUT = APP_MSG_SEND_TIMEOUT, - HTTP_SEND_REJECTED = APP_MSG_SEND_REJECTED, - HTTP_NOT_CONNECTED = APP_MSG_NOT_CONNECTED, - HTTP_BRIDGE_NOT_RUNNING = APP_MSG_APP_NOT_RUNNING, - HTTP_INVALID_ARGS = APP_MSG_INVALID_ARGS, - HTTP_BUSY = APP_MSG_BUSY, - HTTP_BUFFER_OVERFLOW = APP_MSG_BUFFER_OVERFLOW, - HTTP_ALREADY_RELEASED = APP_MSG_ALREADY_RELEASED, - HTTP_CALLBACK_ALREADY_REGISTERED = APP_MSG_CALLBACK_ALREADY_REGISTERED, - HTTP_CALLBACK_NOT_REGISTERED = APP_MSG_CALLBACK_NOT_REGISTERED, - HTTP_NOT_ENOUGH_STORAGE = DICT_NOT_ENOUGH_STORAGE << 12, - HTTP_INVALID_DICT_ARGS = DICT_INVALID_ARGS << 12, - HTTP_INTERNAL_INCONSISTENCY = DICT_INTERNAL_INCONSISTENCY << 12, - HTTP_INVALID_BRIDGE_RESPONSE = 1 << 17 -} HTTPResult; - -// HTTP Request callbacks -typedef void(*HTTPRequestFailedHandler)(int32_t request_id, int http_status, void* context); -typedef void(*HTTPRequestSucceededHandler)(int32_t request_id, int http_status, DictionaryIterator* sent, void* context); -typedef void(*HTTPReconnectedHandler)(void* context); -// Local cookie callbacks -typedef void(*HTTPPhoneCookieBatchGetHandler)(int32_t request_id, DictionaryIterator* result, void* context); -typedef void(*HTTPPhoneCookieGetHandler)(int32_t request_id, Tuple* result, void* context); -typedef void(*HTTPPhoneCookieSetHandler)(int32_t request_id, bool successful, void* context); -typedef void(*HTTPPhoneCookieFsyncHandler)(bool successful, void* context); -typedef void(*HTTPPhoneCookieDeleteHandler)(int32_t request_id, bool success, void* context); -// Time callback -typedef void(*HTTPTimeHandler)(int32_t utc_offset_seconds, bool is_dst, uint32_t unixtime, const char* tz_name, void* context); -// Location callback -typedef void(*HTTPLocationHandler)(float latitude, float longitude, float altitude, float accuracy, void* context); - -// HTTP stuff -typedef struct { - HTTPRequestFailedHandler failure; - HTTPRequestSucceededHandler success; - HTTPReconnectedHandler reconnect; - HTTPPhoneCookieGetHandler cookie_get; - HTTPPhoneCookieBatchGetHandler cookie_batch_get; - HTTPPhoneCookieSetHandler cookie_set; - HTTPPhoneCookieFsyncHandler cookie_fsync; - HTTPPhoneCookieDeleteHandler cookie_delete; - HTTPTimeHandler time; - HTTPLocationHandler location; -} HTTPCallbacks; - -// HTTP requests -HTTPResult http_out_get(const char* url, int32_t request_id, DictionaryIterator **iter_out); -HTTPResult http_out_send(); -bool http_register_callbacks(HTTPCallbacks callbacks, void* context); - -// Time information -HTTPResult http_time_request(); - -// Location information -HTTPResult http_location_request(); - -// Local cookies -// Basic API -void http_set_app_id(int32_t id); -HTTPResult http_cookie_set_start(int32_t request_id, DictionaryIterator **iter_out); -HTTPResult http_cookie_set_end(); -HTTPResult http_cookie_get_multiple(int32_t request_id, uint32_t* keys, int32_t length); -HTTPResult http_cookie_delete_multiple(int32_t request_id, uint32_t* keys, int32_t length); -HTTPResult http_cookie_fsync(); -// Convenience methods -HTTPResult http_cookie_set_int(uint32_t request_id, uint32_t key, const void* integer, uint8_t width_bytes, bool is_signed); -HTTPResult http_cookie_set_cstring(uint32_t request_id, uint32_t key, const char* value); -HTTPResult http_cookie_set_data(uint32_t request_id, uint32_t key, const uint8_t* const value, int length); -HTTPResult http_cookie_get(uint32_t request_id, uint32_t key); -HTTPResult http_cookie_delete(uint32_t request_id, uint32_t key); -// Convenience convenience methods -HTTPResult http_cookie_set_int32(uint32_t request_id, uint32_t key, int32_t value); -HTTPResult http_cookie_set_uint32(uint32_t request_id, uint32_t key, uint32_t value); -HTTPResult http_cookie_set_int16(uint32_t request_id, uint32_t key, int16_t value); -HTTPResult http_cookie_set_uint16(uint32_t request_id, uint32_t key, uint16_t value); -HTTPResult http_cookie_set_int8(uint32_t request_id, uint32_t key, int8_t value); -HTTPResult http_cookie_set_uint8(uint32_t request_id, uint32_t key, uint8_t value); - -#endif diff --git a/src/pom.c b/src/pom.c index a900c9f..9c25517 100644 --- a/src/pom.c +++ b/src/pom.c @@ -1,9 +1,7 @@ -#include "pebble_os.h" -#include "pebble_app.h" -#include "pebble_fonts.h" +#include +#include #include "debugging.h" #include "pom.h" -#include "http.h" #include "pom_vibes.h" #include "pom_text.h" #include "pom_menu.h" @@ -33,27 +31,27 @@ void pomMoveTextLayers() { switch (app.state) { case PomStateWorking: case PomStateReady: - frame = app.workingTextLayer.layer.frame; + frame = layer_get_frame(text_layer_get_layer(app.workingTextLayer)); frame.origin.y = 2; - layer_set_frame(&app.workingTextLayer.layer, frame); - frame = app.timeTextLayer.layer.frame; + layer_set_frame(text_layer_get_layer(app.workingTextLayer), frame); + frame = layer_get_frame(text_layer_get_layer(app.timeTextLayer)); frame.origin.y = 45; - layer_set_frame(&app.timeTextLayer.layer, frame); + layer_set_frame(text_layer_get_layer(app.timeTextLayer), frame); break; case PomStateResting: - frame = app.workingTextLayer.layer.frame; + frame = layer_get_frame(text_layer_get_layer(app.workingTextLayer)); frame.origin.y = FULL_SIZE.h - 65 - 2; - layer_set_frame(&app.workingTextLayer.layer, frame); - frame = app.timeTextLayer.layer.frame; + layer_set_frame(text_layer_get_layer(app.workingTextLayer), frame); + frame = layer_get_frame(text_layer_get_layer(app.timeTextLayer)); frame.origin.y = FULL_SIZE.h - 20 - 2; - layer_set_frame(&app.timeTextLayer.layer, frame); + layer_set_frame(text_layer_get_layer(app.timeTextLayer), frame); break; default: break; } - frame = app.timeTextLayer.layer.frame; + frame = layer_get_frame(text_layer_get_layer(app.timeTextLayer)); frame.size.w = (app.state == PomStateReady)? 80 : 30; - layer_set_frame(&app.timeTextLayer.layer, frame); + layer_set_frame(text_layer_get_layer(app.timeTextLayer), frame); } /** Change the state between ready, working, and resting. */ @@ -64,9 +62,9 @@ void pomSetState(PomState newState) { case PomStateWorking: app.totalTicks = app.ticksRemaining = app.settings.workTicks; - text_layer_set_text(&app.workingTextLayer, POM_TEXT_WORK[app.settings.language]); + text_layer_set_text(app.workingTextLayer, POM_TEXT_WORK[app.settings.language]); formatTime(gTimeString, app.settings.workTicks); - text_layer_set_text(&app.timeTextLayer, gTimeString); + text_layer_set_text(app.timeTextLayer, gTimeString); break; case PomStateResting: @@ -75,17 +73,17 @@ void pomSetState(PomState newState) { app.ticksRemaining = app.settings.longRestTicks; } - text_layer_set_text(&app.workingTextLayer, POM_TEXT_REST[app.settings.language]); + text_layer_set_text(app.workingTextLayer, POM_TEXT_REST[app.settings.language]); formatTime(gTimeString, app.settings.restTicks); - text_layer_set_text(&app.timeTextLayer, gTimeString); + text_layer_set_text(app.timeTextLayer, gTimeString); break; case PomStateReady: - layer_set_bounds(&app.inverterLayer.layer, GRectZero); - text_layer_set_text(&app.workingTextLayer, POM_TEXT_READY[app.settings.language]); + layer_set_bounds(inverter_layer_get_layer(app.inverterLayer), GRectZero); + text_layer_set_text(app.workingTextLayer, POM_TEXT_READY[app.settings.language]); static char pomCounterString[64]; snprintf(pomCounterString, ARRAY_LENGTH(pomCounterString), POM_TEXT_POM_COUNTER[app.settings.language], app.completedPoms); - text_layer_set_text(&app.timeTextLayer, pomCounterString); + text_layer_set_text(app.timeTextLayer, pomCounterString); break; default: @@ -94,12 +92,11 @@ void pomSetState(PomState newState) { } pomMoveTextLayers(); - layer_mark_dirty(&app.mainWindow.layer); -// layer_set_frame(&app.inverterLayer.layer, GRectZero); + layer_mark_dirty(window_get_root_layer(app.mainWindow)); } /** Tick handler. Called every second. Also called on the minute for "heartbeat" working reminders. */ -void pomOnTick(AppContextRef ctx, PebbleTickEvent *event) { +void pomOnTick(struct tm *tick_time, TimeUnits units_changed) { if (app.state == PomStateReady) return; app.ticksRemaining--; @@ -127,7 +124,7 @@ void pomOnTick(AppContextRef ctx, PebbleTickEvent *event) { bool isResting = (app.state == PomStateResting); // heartbeat - if (isWorking && app.settings.vibrateWhileWorking && (event->units_changed & MINUTE_UNIT) > 0) { + if (isWorking && app.settings.vibrateWhileWorking && (units_changed & MINUTE_UNIT) > 0) { vibes_enqueue_custom_pattern(VIBRATE_MINIMAL); } @@ -140,14 +137,14 @@ void pomOnTick(AppContextRef ctx, PebbleTickEvent *event) { else if (isResting) { inverterFrame.size.h = pctRemaining * FULL_SIZE.h; } - layer_set_frame(&app.inverterLayer.layer, inverterFrame); + layer_set_frame(inverter_layer_get_layer(app.inverterLayer), inverterFrame); // set timer text formatTime(gTimeString, app.ticksRemaining); - text_layer_set_text(&app.timeTextLayer, gTimeString); + text_layer_set_text(app.timeTextLayer, gTimeString); // redraw! - layer_mark_dirty(&app.mainWindow.layer); + layer_mark_dirty(window_get_root_layer(app.mainWindow)); } /** Handles up or down button click while in main window. Use this click to start or restart a cycle. */ @@ -161,63 +158,24 @@ void pomOnMainWindowUpOrDownClick(ClickRecognizerRef recognizer, void *context) /** Select (middle button) click handler. Launches into settings menu. */ void pomOnMainWindowSelectClick(ClickRecognizerRef recognizer, void *context) { - if (window_stack_contains_window(&app.menuWindow)) { + if (window_stack_contains_window(app.menuWindow)) { WARN("Window already in window stack"); return; } - window_stack_push(&app.menuWindow, true); + window_stack_push(app.menuWindow, true); } /** Set up click handlers on the main window. */ -void pomMainWindowClickProvider(ClickConfig **buttonConfigs, void *context) { - buttonConfigs[BUTTON_ID_UP]->click.handler = - buttonConfigs[BUTTON_ID_DOWN]->click.handler = - pomOnMainWindowUpOrDownClick; - buttonConfigs[BUTTON_ID_SELECT]->click.handler = pomOnMainWindowSelectClick; -} - -void pomOnDeinit(AppContextRef ctx) { +void pomMainWindowClickProvider(void *context) { + window_single_click_subscribe(BUTTON_ID_UP, pomOnMainWindowUpOrDownClick); + window_single_click_subscribe(BUTTON_ID_DOWN, pomOnMainWindowUpOrDownClick); + window_single_click_subscribe(BUTTON_ID_SELECT, pomOnMainWindowSelectClick); } /** App initialization. */ -void pomOnInit(AppContextRef ctx) { - window_init(&app.mainWindow, "Pom"); - window_set_fullscreen(&app.mainWindow, true); - window_set_background_color(&app.mainWindow, GColorWhite); - window_set_click_config_provider(&app.mainWindow, pomMainWindowClickProvider); - - text_layer_init(&app.workingTextLayer, GRect(2, 2, FULL_SIZE.w, 50)); - text_layer_set_font(&app.workingTextLayer, fonts_get_system_font(FONT_KEY_BITHAM_42_BOLD)); - - text_layer_init(&app.timeTextLayer, GRect(4, 45, 80, 30)); - text_layer_set_font(&app.timeTextLayer, fonts_get_system_font(FONT_KEY_FONT_FALLBACK)); - - inverter_layer_init(&app.inverterLayer, GRectZero); - - layer_add_child(&app.mainWindow.layer, &app.workingTextLayer.layer); - layer_add_child(&app.mainWindow.layer, &app.timeTextLayer.layer); - layer_add_child(&app.mainWindow.layer, &app.inverterLayer.layer); - window_stack_push(&app.mainWindow, true); - -#if USE_CONSOLE - text_layer_init(&__console_layer, GRect(0, 28, 144, 140)); - text_layer_set_overflow_mode(&__console_layer, GTextOverflowModeWordWrap); - text_layer_set_font(&__console_layer, fonts_get_system_font(FONT_KEY_FONT_FALLBACK)); - layer_add_child(&app.mainWindow.layer, &__console_layer.layer); -#endif - - pomInitMenuModule(ctx); - pomInitCookiesModule(ctx); - pomSetState(PomStateReady); - - pomLoadCookies(); -} - -// Pebble Core ------------------------------------------------------------ - -void pbl_main(void *params) { +void pomStartup() { // setup default settings - // TODO load settings from persistent storage + // after, load settings from persistent storage app.settings = (PomSettings){ .language = PomEnglish, .workTicks = 60 * 25, @@ -229,24 +187,49 @@ void pbl_main(void *params) { }; app.completedPoms = 0; + + app.mainWindow = window_create(); + window_set_fullscreen(app.mainWindow, true); + window_set_background_color(app.mainWindow, GColorWhite); + window_set_click_config_provider(app.mainWindow, pomMainWindowClickProvider); - PebbleAppHandlers handlers = { - .init_handler = &pomOnInit, - .deinit_handler = &pomOnDeinit, - .tick_info = { - .tick_handler = &pomOnTick, - .tick_units = SECOND_UNIT|MINUTE_UNIT, - }, - .messaging_info = { - .buffer_sizes = { - .inbound = 124, - .outbound = 256, - } - }, - }; - app_event_loop(params, &handlers); -} + app.workingTextLayer = text_layer_create(GRect(2, 2, FULL_SIZE.w, 50)); + text_layer_set_font(app.workingTextLayer, fonts_get_system_font(FONT_KEY_BITHAM_42_BOLD)); + + app.timeTextLayer = text_layer_create(GRect(4, 45, 80, 30)); + text_layer_set_font(app.timeTextLayer, fonts_get_system_font(FONT_KEY_FONT_FALLBACK)); + + app.inverterLayer = inverter_layer_create(GRectZero); + + layer_add_child(window_get_root_layer(app.mainWindow), text_layer_get_layer(app.workingTextLayer)); + layer_add_child(window_get_root_layer(app.mainWindow), text_layer_get_layer(app.timeTextLayer)); + layer_add_child(window_get_root_layer(app.mainWindow), inverter_layer_get_layer(app.inverterLayer)); + window_stack_push(app.mainWindow, true); -#ifndef XCODE -PBL_APP_INFO(HTTP_UUID, POM_NAME, "Partlyhuman", 1, 0, RESOURCE_ID_IMAGE_MENU_ICON, APP_INFO_STANDARD_APP); +#if USE_CONSOLE + __console_layer = text_layer_create(GRect(0, 28, 144, 140)); + text_layer_set_overflow_mode(__console_layer, GTextOverflowModeWordWrap); + text_layer_set_font(__console_layer, fonts_get_system_font(FONT_KEY_FONT_FALLBACK)); + layer_add_child(window_get_root_layer(app.mainWindow), text_layer_get_layer(__console_layer.layer)); #endif + + pomInitMenuModule(); + // pomInitCookiesModule(); + pomSetState(PomStateReady); + + tick_timer_service_subscribe(SECOND_UNIT|MINUTE_UNIT, pomOnTick); + // pomLoadCookies(); +} + +void pomShutdown() { + window_destroy(app.mainWindow); + window_destroy(app.menuWindow); +} + +// Pebble Core ------------------------------------------------------------ + +int main() { + pomStartup(); + app_event_loop(); + pomShutdown(); +} diff --git a/src/pom.h b/src/pom.h index e509dfb..d715781 100644 --- a/src/pom.h +++ b/src/pom.h @@ -1,8 +1,5 @@ #pragma once -#include "pebble_os.h" - -#define POM_UUID { 0x42, 0xB2, 0x76, 0xD7, 0x8F, 0x6F, 0x44, 0x9B, 0x89, 0x03, 0xD1, 0x56, 0xC0, 0xD1, 0xE9, 0xBD } -#define POM_NAME "PblPom" +#include typedef enum { PomStateReady, @@ -30,11 +27,11 @@ typedef struct { int totalTicks; PomState state; - Window mainWindow; - Window menuWindow; - TextLayer workingTextLayer; - TextLayer timeTextLayer; - InverterLayer inverterLayer; + Window *mainWindow; + Window *menuWindow; + TextLayer *workingTextLayer; + TextLayer *timeTextLayer; + InverterLayer *inverterLayer; } PomApplication; diff --git a/src/pom_cookies.c b/src/pom_cookies.c index 4e79570..ed54299 100644 --- a/src/pom_cookies.c +++ b/src/pom_cookies.c @@ -1,52 +1,52 @@ -#include "pom_cookies.h" -#include "pom.h" -#include "http.h" -#include "debugging.h" - -#define COOKIE_KEY_BYTEARRAY 293 - -static int32_t requestId; - -void traceHttpResult(HTTPResult result) { - if (result != HTTP_OK) { - CONSOLE("Error %d", result); - } -} - -void pomOnCookieSet(int32_t request_id, bool successful, void* context) { - CONSOLE("Cookie set %s", (successful)? "OK" : "FAIL"); -} - -void pomSaveCookies() { - CONSOLE("Saving settings struct: %d bytes", sizeof(PomSettings)); - void *data = &(app.settings); - traceHttpResult(http_cookie_set_data(++requestId, COOKIE_KEY_BYTEARRAY, data, sizeof(PomSettings))); -} - -void pomOnCookieGet(int32_t request_id, Tuple* t, void* context) { - CONSOLE("Cookie received"); - if (t->key == COOKIE_KEY_BYTEARRAY) { - CONSOLE("It's our settings, yay"); - memcpy(&app.settings, t->value->data, sizeof(PomSettings)); - pomSetState(app.state); - } -} - -void pomLoadCookies() { - CONSOLE("Loading cookies..."); - traceHttpResult(http_cookie_get(++requestId, COOKIE_KEY_BYTEARRAY)); -} - -void pomOnCookieReconnect(void* context) { - CONSOLE("Reconnected to phone"); - pomSaveCookies(); -} - -void pomInitCookiesModule(void *ctx) { - http_set_app_id(0x1b2b3b4b); - http_register_callbacks((HTTPCallbacks){ - .cookie_get = pomOnCookieGet, - .cookie_set = pomOnCookieSet, - .reconnect = pomOnCookieReconnect, - }, ctx); -} +// #include "pom_cookies.h" +// #include "pom.h" +// #include "http.h" +// #include "debugging.h" + +// #define COOKIE_KEY_BYTEARRAY 293 + +// static int32_t requestId; + +// void traceHttpResult(HTTPResult result) { +// if (result != HTTP_OK) { +// CONSOLE("Error %d", result); +// } +// } + +// void pomOnCookieSet(int32_t request_id, bool successful, void* context) { +// CONSOLE("Cookie set %s", (successful)? "OK" : "FAIL"); +// } + +// void pomSaveCookies() { +// CONSOLE("Saving settings struct: %d bytes", sizeof(PomSettings)); +// void *data = &(app.settings); +// traceHttpResult(http_cookie_set_data(++requestId, COOKIE_KEY_BYTEARRAY, data, sizeof(PomSettings))); +// } + +// void pomOnCookieGet(int32_t request_id, Tuple* t, void* context) { +// CONSOLE("Cookie received"); +// if (t->key == COOKIE_KEY_BYTEARRAY) { +// CONSOLE("It's our settings, yay"); +// memcpy(&app.settings, t->value->data, sizeof(PomSettings)); +// pomSetState(app.state); +// } +// } + +// void pomLoadCookies() { +// CONSOLE("Loading cookies..."); +// traceHttpResult(http_cookie_get(++requestId, COOKIE_KEY_BYTEARRAY)); +// } + +// void pomOnCookieReconnect(void* context) { +// CONSOLE("Reconnected to phone"); +// pomSaveCookies(); +// } + +// void pomInitCookiesModule(void *ctx) { +// http_set_app_id(0x1b2b3b4b); +// http_register_callbacks((HTTPCallbacks){ +// .cookie_get = pomOnCookieGet, +// .cookie_set = pomOnCookieSet, +// .reconnect = pomOnCookieReconnect, +// }, ctx); +// } diff --git a/src/pom_cookies.h b/src/pom_cookies.h index 1e10fc8..f6f20da 100644 --- a/src/pom_cookies.h +++ b/src/pom_cookies.h @@ -1,5 +1,5 @@ -#pragma once +// #pragma once -void pomLoadCookies(); -void pomSaveCookies(); -void pomInitCookiesModule(void *); +// void pomLoadCookies(); +// void pomSaveCookies(); +// void pomInitCookiesModule(void *); diff --git a/src/pom_menu.c b/src/pom_menu.c index fe814ec..98aa950 100644 --- a/src/pom_menu.c +++ b/src/pom_menu.c @@ -14,12 +14,12 @@ typedef enum { PomMenuItemCount } PomMenuId; // Aliases for each menu item by index -static SimpleMenuLayer menuLayer; +static SimpleMenuLayer *menuLayer; static SimpleMenuItem menuItems[PomMenuItemCount]; static SimpleMenuSection menuSectionRoot; static SimpleMenuSection menuSectionsAll[1]; -static NumberWindow durationChooserWindow; +static NumberWindow *durationChooserWindow; /** Handler for number window, when you select a value. @@ -28,7 +28,7 @@ static NumberWindow durationChooserWindow; void pomOnNumberSelect(struct NumberWindow *window, void *context) { int value = number_window_get_value(window); int ticks = value * 60; - PomMenuId id = simple_menu_layer_get_selected_index(&menuLayer); + PomMenuId id = simple_menu_layer_get_selected_index(menuLayer); switch (id) { case PomMenuRestDuration: app.settings.restTicks = ticks; @@ -69,21 +69,21 @@ void pomOnMenuSelect(int index, void *context) { break; case PomMenuRestDuration: - number_window_set_value(&durationChooserWindow, s->restTicks/60); - number_window_set_label(&durationChooserWindow, POM_TEXT_SETTINGS_REST_DURATION[s->language]); - window_stack_push((Window*)&durationChooserWindow, true); + number_window_set_value(durationChooserWindow, s->restTicks/60); + number_window_set_label(durationChooserWindow, POM_TEXT_SETTINGS_REST_DURATION[s->language]); + window_stack_push((Window *)durationChooserWindow, true); break; case PomMenuLongRestDuration: - number_window_set_value(&durationChooserWindow, s->longRestTicks/60); - number_window_set_label(&durationChooserWindow, POM_TEXT_SETTINGS_LONG_REST_DURATION[s->language]); - window_stack_push((Window*)&durationChooserWindow, true); + number_window_set_value(durationChooserWindow, s->longRestTicks/60); + number_window_set_label(durationChooserWindow, POM_TEXT_SETTINGS_LONG_REST_DURATION[s->language]); + window_stack_push((Window *)durationChooserWindow, true); break; case PomMenuWorkDuration: - number_window_set_value(&durationChooserWindow, s->workTicks/60); - number_window_set_label(&durationChooserWindow, POM_TEXT_SETTINGS_WORK_DURATION[s->language]); - window_stack_push((Window*)&durationChooserWindow, true); + number_window_set_value(durationChooserWindow, s->workTicks/60); + number_window_set_label(durationChooserWindow, POM_TEXT_SETTINGS_WORK_DURATION[s->language]); + window_stack_push((Window *)durationChooserWindow, true); break; @@ -141,7 +141,7 @@ void pomUpdateMenus() { break; } } - menu_layer_reload_data((MenuLayer*)&menuLayer); + menu_layer_reload_data((MenuLayer *)menuLayer); } /** Window load handler for settings window. Called before opening the window. */ @@ -151,17 +151,17 @@ void pomOnMenuWindowLoad(struct Window *menuWindowRef) { /** Window unload handler for settings window. */ void pomOnMenuWindowUnload(struct Window *menuWindowRef) { - pomSaveCookies(); + // pomSaveCookies(); pomSetState(app.state); //redraw in case language changed } /** Initialize everything needed for settings menus. Called by pomOnInit(). */ -void pomInitMenuModule(void *ctx) { +void pomInitMenuModule() { // setup window with all the settings in it - window_init(&app.menuWindow, "MENU"); - window_set_fullscreen(&app.menuWindow, true); - window_set_background_color(&app.menuWindow, GColorWhite); - window_set_window_handlers(&app.menuWindow, (WindowHandlers){ + app.menuWindow = window_create(); + window_set_fullscreen(app.menuWindow, true); + window_set_background_color(app.menuWindow, GColorWhite); + window_set_window_handlers(app.menuWindow, (WindowHandlers){ .load = pomOnMenuWindowLoad, .unload = pomOnMenuWindowUnload, }); @@ -177,17 +177,17 @@ void pomInitMenuModule(void *ctx) { menuSectionsAll[0] = menuSectionRoot; // setup menu layer - simple_menu_layer_init(&menuLayer, - app.menuWindow.layer.frame, - &app.menuWindow, - menuSectionsAll, - 1, - NULL); - layer_add_child(&app.menuWindow.layer, simple_menu_layer_get_layer(&menuLayer)); + menuLayer = simple_menu_layer_create( + layer_get_frame(window_get_root_layer(app.menuWindow)), + app.menuWindow, + menuSectionsAll, + 1, + NULL); + layer_add_child(window_get_root_layer(app.menuWindow), simple_menu_layer_get_layer(menuLayer)); // setup number picker window, used when you edit a duration value - number_window_init(&durationChooserWindow, "Duration", (NumberWindowCallbacks){.selected = pomOnNumberSelect}, NULL); - number_window_set_min(&durationChooserWindow, 1); - number_window_set_max(&durationChooserWindow, 60); - number_window_set_step_size(&durationChooserWindow, 1); + durationChooserWindow = number_window_create("Duration", (NumberWindowCallbacks){.selected = pomOnNumberSelect}, NULL); + number_window_set_min(durationChooserWindow, 1); + number_window_set_max(durationChooserWindow, 60); + number_window_set_step_size(durationChooserWindow, 1); } diff --git a/src/pom_menu.h b/src/pom_menu.h index 7c52907..a0f7f85 100644 --- a/src/pom_menu.h +++ b/src/pom_menu.h @@ -1,4 +1,4 @@ #pragma once void pomUpdateMenus(); -void pomInitMenuModule(void *); +void pomInitMenuModule(); diff --git a/src/pom_text.c b/src/pom_text.c index c969d5a..39db904 100644 --- a/src/pom_text.c +++ b/src/pom_text.c @@ -50,11 +50,11 @@ const char* POM_TEXT_SETTINGS_LANGUAGES[] = { }; const char* POM_TEXT_SETTINGS_WORK_DURATION[] = { [PomEnglish] = "Work for", - [PomSpanish] = "Trabajar para", + [PomSpanish] = "Trabajar por", }; const char* POM_TEXT_SETTINGS_REST_DURATION[] = { [PomEnglish] = "Rest for", - [PomSpanish] = "Descansar para", + [PomSpanish] = "Descansar por", }; const char* POM_TEXT_SETTINGS_VIBRATE_WHILE_WORKING[] = { [PomEnglish] = "Work ticking", diff --git a/src/pom_vibes.h b/src/pom_vibes.h index b4e58c3..5a501da 100644 --- a/src/pom_vibes.h +++ b/src/pom_vibes.h @@ -1,5 +1,5 @@ #pragma once -#include "pebble_os.h" +#include static const uint32_t VIBRATE_PAT_MINIMAL[] = {30,}; static const VibePattern VIBRATE_MINIMAL = {