-
Notifications
You must be signed in to change notification settings - Fork 1
Functionality updates #1
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -76,7 +76,9 @@ | |
| "dur_max", | ||
| "shock_dur", | ||
| "shock_str", | ||
| "js_ready" | ||
| "js_ready", | ||
| "ID", | ||
| "mode" | ||
| ] | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,10 +14,13 @@ static char stren_str[24]; | |
| static char dur_str[24]; | ||
| static int current_strength; | ||
| static int current_duration; | ||
| static int ID; | ||
| static int mode; | ||
| extern bool js_ready; | ||
| static GFont poppins20; | ||
| typedef struct ClaySettings | ||
| { | ||
|
|
||
| int maxStrength; | ||
| int maxDuration; | ||
| bool configured; | ||
|
|
@@ -62,6 +65,7 @@ void update_state(screenState new_state) | |
| { | ||
| case MAIN: | ||
| state = new_state; | ||
| ID = 2; | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A user cannot intuitively know that each menu does something different |
||
| action_bar_layer_set_icon(s_action_bar_layer, BUTTON_ID_UP, s_strength_bitmap); | ||
| action_bar_layer_set_icon(s_action_bar_layer, BUTTON_ID_SELECT, s_bolt_bitmap); | ||
| action_bar_layer_set_icon(s_action_bar_layer, BUTTON_ID_DOWN, s_time_bitmap); | ||
|
|
@@ -71,17 +75,19 @@ void update_state(screenState new_state) | |
|
|
||
| case STRENGTH: | ||
| state = new_state; | ||
| ID = 1; | ||
| action_bar_layer_set_icon(s_action_bar_layer, BUTTON_ID_UP, s_plus_bitmap); | ||
| action_bar_layer_clear_icon(s_action_bar_layer, BUTTON_ID_SELECT); | ||
| // action_bar_layer_clear_icon(s_action_bar_layer, BUTTON_ID_SELECT); | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't comment out code just remove it if it's not being used |
||
| action_bar_layer_set_icon(s_action_bar_layer, BUTTON_ID_DOWN, s_minus_bitmap); | ||
| text_layer_set_text_color(s_strength_label_layer, PBL_IF_COLOR_ELSE(GColorWhite, GColorBlack)); | ||
| text_layer_set_text_color(s_duration_label_layer, PBL_IF_COLOR_ELSE(GColorLightGray, GColorBlack)); | ||
| break; | ||
|
|
||
| case TIME: | ||
| state = new_state; | ||
| ID = 3; | ||
| action_bar_layer_set_icon(s_action_bar_layer, BUTTON_ID_UP, s_plus_bitmap); | ||
| action_bar_layer_clear_icon(s_action_bar_layer, BUTTON_ID_SELECT); | ||
| // action_bar_layer_clear_icon(s_action_bar_layer, BUTTON_ID_SELECT); | ||
| action_bar_layer_set_icon(s_action_bar_layer, BUTTON_ID_DOWN, s_minus_bitmap); | ||
| text_layer_set_text_color(s_strength_label_layer, PBL_IF_COLOR_ELSE(GColorLightGray, GColorBlack)); | ||
| text_layer_set_text_color(s_duration_label_layer, PBL_IF_COLOR_ELSE(GColorWhite, GColorBlack)); | ||
|
|
@@ -97,6 +103,7 @@ static void up_click_handler() | |
| switch (state) | ||
| { | ||
| case MAIN: | ||
| ID = 1; | ||
| update_state(STRENGTH); | ||
| break; | ||
| case STRENGTH: | ||
|
|
@@ -120,8 +127,7 @@ static void up_click_handler() | |
|
|
||
| static void select_click_handler() | ||
| { | ||
| if (state == MAIN) | ||
| { | ||
| mode = 2; | ||
| if (!js_ready) | ||
| { | ||
| return; | ||
|
|
@@ -132,25 +138,67 @@ static void select_click_handler() | |
| { | ||
| dict_write_int(out_iter, MESSAGE_KEY_shock_str, ¤t_strength, sizeof(int), true); | ||
| dict_write_int(out_iter, MESSAGE_KEY_shock_dur, ¤t_duration, sizeof(int), true); | ||
| dict_write_int(out_iter, MESSAGE_KEY_ID, &ID, sizeof(int), true); | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wrong indentation |
||
| dict_write_int(out_iter, MESSAGE_KEY_mode, &mode, sizeof(int), true); | ||
| result = app_message_outbox_send(); | ||
| if (result != APP_MSG_OK) | ||
| { | ||
| APP_LOG(APP_LOG_LEVEL_ERROR, "Error sending the outbox: %d", (int)result); | ||
| } | ||
| else{ | ||
| vibes_short_pulse(); | ||
| } | ||
| } | ||
| else | ||
| { | ||
| APP_LOG(APP_LOG_LEVEL_ERROR, "Error preparing the outbox: %d", (int)result); | ||
| } | ||
| } | ||
|
|
||
| } | ||
|
|
||
| static void long_up_click_handler() | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. abstract, don't copy paste
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this also disables the ability to hold to increase strength |
||
| { | ||
| mode = 1; | ||
| if (!js_ready) | ||
| { | ||
| return; | ||
| } | ||
|
|
||
| AppMessageResult result = app_message_outbox_begin(&out_iter); | ||
| if (result == APP_MSG_OK) | ||
| { | ||
| dict_write_int(out_iter, MESSAGE_KEY_shock_str, ¤t_strength, sizeof(int), true); | ||
| dict_write_int(out_iter, MESSAGE_KEY_shock_dur, ¤t_duration, sizeof(int), true); | ||
| dict_write_int(out_iter, MESSAGE_KEY_ID, &ID, sizeof(int), true); | ||
| dict_write_int(out_iter, MESSAGE_KEY_mode, &mode, sizeof(int), true); | ||
| result = app_message_outbox_send(); | ||
| if (result != APP_MSG_OK) | ||
| { | ||
| APP_LOG(APP_LOG_LEVEL_ERROR, "Error sending the outbox: %d", (int)result); | ||
| } | ||
| else | ||
| { | ||
| vibes_double_pulse(); | ||
| } | ||
| } | ||
| else | ||
| { | ||
| APP_LOG(APP_LOG_LEVEL_ERROR, "Error preparing the outbox: %d", (int)result); | ||
| } | ||
|
|
||
| } | ||
|
|
||
| static void long_down_click_handler() | ||
| { | ||
| return; | ||
| } | ||
| static void down_click_handler() | ||
| { | ||
| switch (state) | ||
| { | ||
| case MAIN: | ||
| update_state(TIME); | ||
| ID = 3; | ||
| break; | ||
|
|
||
| case STRENGTH: | ||
|
|
@@ -185,10 +233,12 @@ static void back_click_handler() | |
| case STRENGTH: | ||
| { | ||
| update_state(MAIN); | ||
| ID = 2; | ||
| } | ||
| case TIME: | ||
| { | ||
| update_state(MAIN); | ||
| ID = 2; | ||
| } | ||
| default: | ||
| break; | ||
|
|
@@ -198,6 +248,7 @@ static void back_click_handler() | |
| static void click_config_provider(void *context) | ||
| { | ||
| window_single_repeating_click_subscribe(BUTTON_ID_UP, 125, up_click_handler); | ||
| window_long_click_subscribe(BUTTON_ID_SELECT, 300, long_up_click_handler, long_down_click_handler); | ||
| window_single_click_subscribe(BUTTON_ID_SELECT, select_click_handler); | ||
| window_single_repeating_click_subscribe(BUTTON_ID_DOWN, 125, down_click_handler); | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,15 +18,25 @@ Pebble.addEventListener('appmessage', function (e) { | |
| var dict = e.payload; | ||
|
|
||
| if (dict["shock_str"] && dict["shock_dur"]) { | ||
| sendShock(dict["shock_str"], dict["shock_dur"]); | ||
| sendShock(dict["shock_str"], dict["shock_dur"], dict["ID"], dict["mode"]); | ||
| } | ||
| }); | ||
|
|
||
| function sendShock(shock_str, shock_dur) { | ||
| function sendShock(shock_str, shock_dur, ID, mode) { | ||
| var settings = JSON.parse(localStorage.getItem("clay-settings")); | ||
| if (settings && settings.api_key && settings.shocker_id) { | ||
| api_key = settings.api_key; | ||
|
|
||
| if (ID == 3){ | ||
| shocker_id = settings.shocker_id3; | ||
| } | ||
| else if (ID == 2){ | ||
| shocker_id = settings.shocker_id2; | ||
| } | ||
| else { | ||
| shocker_id = settings.shocker_id; | ||
| } | ||
|
|
||
| } | ||
| else { | ||
| console.log("VARIABLES UNSET IN CONFIG") | ||
|
|
@@ -40,18 +50,35 @@ function sendShock(shock_str, shock_dur) { | |
| xhr.setRequestHeader("OpenShockToken", api_key); | ||
| xhr.setRequestHeader("accept", "application/json"); | ||
| xhr.setRequestHeader("Content-Type", "application/json"); | ||
| xhr.send(JSON.stringify({ | ||
| shocks: [ | ||
| { | ||
| id: shocker_id, | ||
| type: "Shock", | ||
| intensity: shock_str, | ||
| duration: shock_dur, | ||
| exclusive: true | ||
| } | ||
| ], | ||
| customName: "Pebble App" | ||
| if (mode == 1) { | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Dont send 3 requests combine them |
||
| xhr.send(JSON.stringify({ | ||
| shocks: [ | ||
| { | ||
| id: shocker_id, | ||
| type: "Shock", | ||
| intensity: shock_str, | ||
| duration: shock_dur, | ||
| exclusive: true | ||
| } | ||
| ], | ||
| customName: "Pebble App" | ||
| })); | ||
| } | ||
| else | ||
| { | ||
| xhr.send(JSON.stringify({ | ||
| shocks: [ | ||
| { | ||
| id: shocker_id, | ||
| type: "Vibrate", | ||
| intensity: shock_str, | ||
| duration: shock_dur, | ||
| exclusive: true | ||
| } | ||
| ], | ||
| customName: "Pebble App" | ||
| })); | ||
| } | ||
| var response = JSON.parse(xhr.responseText); | ||
| if (response["message"] != "Successfully sent control messages") { | ||
| console.log("API Error: ", response["message"]) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not a constant don't use caps