Skip to content

Commit

Permalink
Initial Commit of Octowatch2
Browse files Browse the repository at this point in the history
  • Loading branch information
schlotzz committed Nov 24, 2016
1 parent d0d7e05 commit 1f23f1b
Show file tree
Hide file tree
Showing 28 changed files with 1,503 additions and 0 deletions.
94 changes: 94 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
{
"author": "[email protected]",
"dependencies": {
"pebble-clay": "^1.0.4"
},
"keywords": [],
"name": "octowatch2",
"pebble": {
"capabilities": [
"configurable"
],
"displayName": "OctoWatch2",
"enableMultiJS": true,
"messageKeys": [
"ready",
"filename",
"remaining_time",
"state",
"progress",
"temp0",
"temp1",
"tempbed"
],
"projectType": "native",
"resources": {
"media": [
{
"file": "images/icon_connect.png",
"name": "CONNECT_ICON",
"targetPlatforms": null,
"type": "bitmap"
},
{
"file": "images/icon_cancel.png",
"name": "CANCEL_ICON",
"targetPlatforms": null,
"type": "bitmap"
},
{
"file": "images/icon_nozzle.png",
"name": "NOZZLE_ICON",
"targetPlatforms": null,
"type": "bitmap"
},
{
"file": "images/icon_bed.png",
"name": "BED_ICON",
"targetPlatforms": null,
"type": "bitmap"
},
{
"file": "images/icon_play.png",
"name": "PLAY_ICON",
"targetPlatforms": null,
"type": "bitmap"
},
{
"file": "images/icon_pause.png",
"name": "PAUSE_ICON",
"targetPlatforms": null,
"type": "bitmap"
},
{
"file": "images/icon_menu.png",
"menuIcon": true,
"name": "MENU_ICON",
"targetPlatforms": null,
"type": "bitmap"
},
{
"file": "images/icon_ellipsis.png",
"name": "ELLIPSIS_ICON",
"targetPlatforms": null,
"type": "bitmap"
},
{
"file": "images/icon_dismiss.png",
"name": "DISMISS_ICON",
"targetPlatforms": null,
"type": "bitmap"
}
]
},
"sdkVersion": "3",
"targetPlatforms": [
"basalt"
],
"uuid": "605e1126-d933-433e-8334-e519995a1ac0",
"watchapp": {
"watchface": false
}
},
"version": "2.0.0"
}
Binary file added resources/images/icon_bed.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/images/icon_cancel.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/images/icon_connect.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/images/icon_dismiss.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/images/icon_ellipsis.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/images/icon_menu.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/images/icon_nozzle.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/images/icon_pause.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/images/icon_play.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
92 changes: 92 additions & 0 deletions src/c/app_glance.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
// OctoWatch2
// A Pebble watch app for monitoring and basic controlling of 3D printers via Octoprint
//
// Licence: CC BY-SA 3.0, http://creativecommons.org/licenses/by-sa/3.0/
// Author: Dominik Scholz <[email protected]>, go4u.de Webdesign <[email protected]>

#include <pebble.h>
#include "app_glance.h"
#include "printer.h"

#define APP_GLANCE_DEFAULT_TIMEOUT 30*60 // 30 minutes after last update


static int s_app_glance_timeout = APP_GLANCE_SLICE_NO_EXPIRATION;


// add the app glance
static void app_glance_update(AppGlanceReloadSession *session, size_t limit, void *context) {
// return, if no app glances allowed
if (limit < 1) return;

// cast the context object to a string
const char *message = (char *)context;

// create the slice
const AppGlanceSlice slice = (AppGlanceSlice) {
.layout = {
//.icon = APP_GLANCE_SLICE_DEFAULT_ICON,
.subtitle_template_string = message
},
.expiration_time = s_app_glance_timeout
};

APP_LOG(APP_LOG_LEVEL_DEBUG, "app_glance_update time is: %u", s_app_glance_timeout);

// Add the slice, and check the result
const AppGlanceResult result = app_glance_add_slice(session, slice);
if (result != APP_GLANCE_RESULT_SUCCESS) {
APP_LOG(APP_LOG_LEVEL_ERROR, "app_glance_update Error: %d", result);
}
}


// do the app glance
void app_glance_destroy(void) {
static char s_message[128] = "Unknown printer state";
s_app_glance_timeout = time(0) + APP_GLANCE_DEFAULT_TIMEOUT;

// choose proper message
switch (printer_get_state()) {

// clear app glance if still loading
case LOADING:
app_glance_reload(NULL, NULL);
return;

// printer is offline
case OFFLINE:
snprintf(s_message, sizeof(s_message), "Printer offline");
break;

// connecting to printer
case CONNECTING:
snprintf(s_message, sizeof(s_message), "Connecting");
break;

// printer finished or is ready/online
case OPERATIONAL:
if (printer_get_progress() == 100) snprintf(s_message, sizeof(s_message), "Finished %s", printer_get_filename());
else if (printer_get_finish_timestamp() > 0) snprintf(s_message, sizeof(s_message), "Ready for %s", printer_get_filename());
else snprintf(s_message, sizeof(s_message), "Printer online");
break;

// job is being printed / has been completed
case PRINTING:
snprintf(s_message, sizeof(s_message), "{time_until(%u)|format(>0S:'Printing, %%aT left','Print completed')}", (uint)printer_get_finish_timestamp());
s_app_glance_timeout = printer_get_finish_timestamp() + APP_GLANCE_DEFAULT_TIMEOUT;
break;

// printer has been paused
case PAUSED:
snprintf(s_message, sizeof(s_message), "Print paused");
break;

// an error occured
case ERROR:
snprintf(s_message, sizeof(s_message), "Print error occured");
break;
}

app_glance_reload(app_glance_update, s_message);
}
4 changes: 4 additions & 0 deletions src/c/app_glance.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#pragma once

void app_glance_destroy(void);
//static void app_glance_update(AppGlanceReloadSession *, size_t, void *);
33 changes: 33 additions & 0 deletions src/c/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// OctoWatch2
// A Pebble watch app for monitoring and basic controlling of 3D printers via Octoprint
//
// Licence: CC BY-SA 3.0, http://creativecommons.org/licenses/by-sa/3.0/
// Author: Dominik Scholz <[email protected]>, go4u.de Webdesign <[email protected]>

#include <pebble.h>
#include "window_main.h"
#include "messaging.h"
#include "app_glance.h"


// do init
static void init(void) {
window_main_init();
messaging_init();
}


// do deinit
static void deinit(void) {
messaging_destroy();
window_main_destroy();
app_glance_destroy();
}


// main
int main(void) {
init();
app_event_loop();
deinit();
}
118 changes: 118 additions & 0 deletions src/c/messaging.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
// OctoWatch2
// A Pebble watch app for monitoring and basic controlling of 3D printers via Octoprint
//
// Licence: CC BY-SA 3.0, http://creativecommons.org/licenses/by-sa/3.0/
// Author: Dominik Scholz <[email protected]>, go4u.de Webdesign <[email protected]>

#include <pebble.h>
#include "messaging.h"
#include "window_main.h"
#include "printer.h"


// inbox success handler
static void messaging_inbox_received(DictionaryIterator *iter, void *context) {
// read tuples
Tuple *tuple_filename = dict_find(iter, 1);
Tuple *tuple_remain = dict_find(iter, 2);
Tuple *tuple_state = dict_find(iter, 3);
Tuple *tuple_progress = dict_find(iter, 4);
Tuple *tuple_secs = dict_find(iter, 5);
Tuple *tuple_temp0 = dict_find(iter, 6);
Tuple *tuple_temp1 = dict_find(iter, 7);
Tuple *tuple_tempbed = dict_find(iter, 8);

// received filename
if (tuple_filename) {
APP_LOG(APP_LOG_LEVEL_DEBUG, "setting filename to: %s", tuple_filename->value->cstring);
printer_set_filename(tuple_filename->value->cstring);
window_main_set_filename(printer_get_filename());
}

// received remaining time, human readable
if (tuple_remain) {
APP_LOG(APP_LOG_LEVEL_DEBUG, "setting time remaining to: %s", tuple_remain->value->cstring);
printer_set_remaining(tuple_remain->value->cstring);
window_main_set_time_remaing_counter(printer_get_remaining());
}

// received state
if (tuple_state) {
APP_LOG(APP_LOG_LEVEL_DEBUG, "setting state to: %s", tuple_state->value->cstring);
printer_set_state_by_char(tuple_state->value->cstring);
window_main_set_state(printer_get_state_text());
}

// received progress
if (tuple_progress) {
APP_LOG(APP_LOG_LEVEL_DEBUG, "setting progress to: %u", (uint)tuple_progress->value->uint8);
printer_set_progress(tuple_progress->value->uint8);
window_main_set_progress(printer_get_progress());
}

// received remaining time, seconds
if (tuple_secs) {
APP_LOG(APP_LOG_LEVEL_DEBUG, "setting secs to: %u", (uint)tuple_secs->value->uint32);
printer_set_finish_timestamp(tuple_secs->value->uint32);
}

// received nozzle0 temp
if (tuple_temp0) {
APP_LOG(APP_LOG_LEVEL_DEBUG, "setting nozzle0 temp to: %u", (uint)tuple_temp0->value->uint16);
printer_set_temp0(tuple_temp0->value->uint16);
window_main_set_nozzle(printer_get_temp0(), printer_get_temp1());
}

// received nozzle1 temp
if (tuple_temp1) {
APP_LOG(APP_LOG_LEVEL_DEBUG, "setting nozzle1 temp to: %u", (uint)tuple_temp1->value->uint16);
printer_set_temp1(tuple_temp1->value->uint16);
window_main_set_nozzle(printer_get_temp0(), printer_get_temp1());
}

// received bed temp
if (tuple_tempbed) {
APP_LOG(APP_LOG_LEVEL_DEBUG, "setting bed temp to: %u", tuple_tempbed->value->uint16);
printer_set_tempbed(tuple_tempbed->value->uint16);
window_main_set_bed(printer_get_tempbed());
}
}


// inbox failure handler
static void messaging_inbox_dropped(AppMessageResult reason, void *context) {
APP_LOG(APP_LOG_LEVEL_DEBUG, "App Message Dropped %d", (int)reason);
vibes_double_pulse();
}


// send an outgoing message
void messaging_outbox_send(const char *value) {
DictionaryIterator *iter;
app_message_outbox_begin(&iter);

if (!iter) {
// Error creating outbound message
APP_LOG(APP_LOG_LEVEL_ERROR, "messaging_outbox_send: cannot send app message");
return;
}

dict_write_cstring(iter, 0, value);
dict_write_end(iter);

app_message_outbox_send();
}


// setup app message inbox
void messaging_init(void) {
app_message_register_inbox_received(messaging_inbox_received);
app_message_register_inbox_dropped(messaging_inbox_dropped);
app_message_open(256, 64);
}


// destroy message handlers
void messaging_destroy(void) {
app_message_deregister_callbacks();
}
7 changes: 7 additions & 0 deletions src/c/messaging.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#pragma once

//static void messaging_inbox_received(DictionaryIterator *, void *);
//static void messaging_inbox_dropped(AppMessageResult, void *);
void messaging_outbox_send(const char *);
void messaging_init(void);
void messaging_destroy(void);
Loading

0 comments on commit 1f23f1b

Please sign in to comment.