Skip to content

Commit

Permalink
Implement configuration for showing date
Browse files Browse the repository at this point in the history
  • Loading branch information
amoshydra committed Jul 8, 2017
1 parent 457e120 commit 5df6fb7
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 12 deletions.
15 changes: 11 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
{
"author": "CodeHydra",
"dependencies": {},
"dependencies": {
"pebble-clay": "^1.0.4"
},
"keywords": [],
"name": "robot-toy",
"pebble": {
"capabilities": [
"configurable"
],
"displayName": "Robot Toy",
"enableMultiJS": false,
"messageKeys": [],
"enableMultiJS": true,
"messageKeys": [
"ShowDate"
],
"projectType": "native",
"resources": {
"media": [
Expand All @@ -30,5 +37,5 @@
"watchface": true
}
},
"version": "1.3.0"
"version": "1.4.0"
}
70 changes: 62 additions & 8 deletions src/c/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,32 @@ static TextLayer *s_time_minute_layer;
static TextLayer *s_date_layer;
static Layer *s_canvas_layer;


static void canvas_update_proc(Layer *this_layer, GContext *ctx);
static void initialise_color_template();




// Persistent storage key
#define SETTINGS_KEY 1

// Define our settings struct
typedef struct ClaySettings {
bool ShowDates;
} ClaySettings;

// An instance of the struct
static ClaySettings settings;










#ifdef PBL_COLOR
static void get_random_color(GColor *colorPrimary, GColor *colorSecondary, GColor *colorBackground) {
srand(time(NULL));
Expand Down Expand Up @@ -146,6 +167,8 @@ static void initialise_color_template() {

// Time updater
static void update_time() {
APP_LOG(APP_LOG_LEVEL_INFO, "Updating time");

// Get a tm structure
time_t temp = time(NULL);
struct tm *tick_time = localtime(&temp);
Expand All @@ -159,13 +182,14 @@ static void update_time() {
if(clock_is_24h_style()) strftime(buffer_time_hour, sizeof(buffer_time_hour), "%H", tick_time);
else strftime(buffer_time_hour, sizeof(buffer_time_hour), "%I", tick_time);
strftime(buffer_time_minute, sizeof(buffer_time_minute), "%M", tick_time);
strftime(buffer_date, sizeof(buffer_date), "%A", tick_time);

if (settings.ShowDates) strftime(buffer_date, sizeof(buffer_date), "%a %d", tick_time);
else strftime(buffer_date, sizeof(buffer_date), "%A", tick_time);

// Capitalize all alphabeth
for (unsigned int i = 1; i < sizeof(buffer_date); i++) {
if (buffer_date[i] > 0) {
if (buffer_date[i] > 96 && buffer_date[i] < 123) {
buffer_date[i] -= 32;
} else {
break;
}
}

Expand Down Expand Up @@ -320,10 +344,34 @@ static void bluetooth_handler(bool connected) {
update_bluetooth_status();
}

// Initialize the default settings
static void prv_default_settings() {
settings.ShowDates = false;
}

// Read settings from persistent storage
static void prv_load_settings() {
// Load the default settings
prv_default_settings();
// Read settings from persistent storage, if they exist
persist_read_data(SETTINGS_KEY, &settings, sizeof(settings));
}

// Save the settings to persistent storage
static void prv_save_settings() {
persist_write_data(SETTINGS_KEY, &settings, sizeof(settings));
}

static void inbox_received_callback(DictionaryIterator *iterator, void *context) {
Tuple *show_date_t = dict_find(iterator, MESSAGE_KEY_ShowDate);
if(show_date_t) {
settings.ShowDates = show_date_t->value->int32 == 1;
}
prv_save_settings();
update_time();
}


static void inbox_dropped_callback(AppMessageResult reason, void *context) {
APP_LOG(APP_LOG_LEVEL_ERROR, "Message dropped!");
}
Expand All @@ -336,8 +384,14 @@ static void outbox_sent_callback(DictionaryIterator *iterator, void *context) {
APP_LOG(APP_LOG_LEVEL_INFO, "Outbox send success!");
}






// Initialise Pebble App
static void init() {
prv_load_settings();

// Color assignment
initialise_color_template();
Expand All @@ -361,16 +415,16 @@ static void init() {
.load = main_window_load,
.unload = main_window_unload
});

// Register callbacks
app_message_register_inbox_received(inbox_received_callback);
app_message_register_inbox_dropped(inbox_dropped_callback);
app_message_register_outbox_failed(outbox_failed_callback);
app_message_register_outbox_sent(outbox_sent_callback);

// Open AppMessage
app_message_open(app_message_inbox_size_maximum(), app_message_outbox_size_maximum());

window_set_background_color(s_main_window, COLOR_TEMPLATE[COLOR_BACKGROUND]);
// Show the Window on the watch, with animated=true
window_stack_push(s_main_window, true);
Expand Down
6 changes: 6 additions & 0 deletions src/pkjs/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// Import the Clay package
var Clay = require('pebble-clay');
// Load our Clay configuration file
var clayConfig = require('./config');
// Initialize Clay
var clay = new Clay(clayConfig);
29 changes: 29 additions & 0 deletions src/pkjs/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
module.exports = [
{
"type": "heading",
"defaultValue": "App Configuration"
},
{
"type": "text",
"defaultValue": "Blah blah blah"
},
{
"type": "section",
"items": [
{
"type": "heading",
"defaultValue": "Settings"
},
{
"type": "toggle",
"messageKey": "ShowDate",
"label": "Show date",
"defaultValue": true
}
]
},
{
"type": "submit",
"defaultValue": "Save Settings"
}
];

0 comments on commit 5df6fb7

Please sign in to comment.