Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@
"dur_max",
"shock_dur",
"shock_str",
"js_ready"
"js_ready",
"ID",
"mode"
]
}
}
61 changes: 56 additions & 5 deletions src/c/windows/control_window.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Copy link
Copy Markdown
Owner

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

static int mode;
extern bool js_ready;
static GFont poppins20;
typedef struct ClaySettings
{

int maxStrength;
int maxDuration;
bool configured;
Expand Down Expand Up @@ -62,6 +65,7 @@ void update_state(screenState new_state)
{
case MAIN:
state = new_state;
ID = 2;
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The 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);
Expand All @@ -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);
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The 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));
Expand All @@ -97,6 +103,7 @@ static void up_click_handler()
switch (state)
{
case MAIN:
ID = 1;
update_state(STRENGTH);
break;
case STRENGTH:
Expand All @@ -120,8 +127,7 @@ static void up_click_handler()

static void select_click_handler()
{
if (state == MAIN)
{
mode = 2;
if (!js_ready)
{
return;
Expand All @@ -132,25 +138,67 @@ static void select_click_handler()
{
dict_write_int(out_iter, MESSAGE_KEY_shock_str, &current_strength, sizeof(int), true);
dict_write_int(out_iter, MESSAGE_KEY_shock_dur, &current_duration, sizeof(int), true);
dict_write_int(out_iter, MESSAGE_KEY_ID, &ID, sizeof(int), true);
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The 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()
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

abstract, don't copy paste

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The 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, &current_strength, sizeof(int), true);
dict_write_int(out_iter, MESSAGE_KEY_shock_dur, &current_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:
Expand Down Expand Up @@ -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;
Expand All @@ -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);

Expand Down
12 changes: 11 additions & 1 deletion src/pkjs/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@
"type": "input",
"messageKey": "shocker_id",
"label": "OpenShock Shocker ID"
},
{
"type": "input",
"messageKey": "shocker_id2",
"label": "OpenShock Shocker ID 2"
},
{
"type": "input",
"messageKey": "shocker_id3",
"label": "OpenShock Shocker ID 3"
},
{
"type": "slider",
Expand Down Expand Up @@ -46,4 +56,4 @@
"type": "submit",
"defaultValue": "Save"
}
]
]
53 changes: 40 additions & 13 deletions src/pkjs/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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) {
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The 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"])
Expand Down