diff --git a/package.json b/package.json index 3dee8fc..caec6cc 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "author": "pebble@schlotzz.com", + "author": "schlotzz / go4u.de Webdesign", "dependencies": { "pebble-clay": "^1.0.4" }, @@ -24,6 +24,12 @@ "projectType": "native", "resources": { "media": [ + { + "file": "data/pdc_notification.pdc", + "name": "NOTIFICATION_PDC", + "targetPlatforms": null, + "type": "raw" + }, { "file": "images/icon_refresh.png", "name": "REFRESH_ICON", @@ -104,5 +110,5 @@ "watchface": false } }, - "version": "1.1.0" + "version": "1.2.0" } diff --git a/resources/data/pdc_notification.pdc b/resources/data/pdc_notification.pdc new file mode 100644 index 0000000..b1d0535 Binary files /dev/null and b/resources/data/pdc_notification.pdc differ diff --git a/src/c/app_glance.c b/src/c/app_glance.c index 222d3d3..a74a2a6 100644 --- a/src/c/app_glance.c +++ b/src/c/app_glance.c @@ -10,7 +10,6 @@ #define APP_GLANCE_DEFAULT_TIMEOUT 30*60 // 30 minutes after last update - static int s_app_glance_timeout = APP_GLANCE_SLICE_NO_EXPIRATION; diff --git a/src/c/app_glance.h b/src/c/app_glance.h index 0e9ae87..7c85009 100644 --- a/src/c/app_glance.h +++ b/src/c/app_glance.h @@ -1,4 +1,10 @@ +// 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 , go4u.de Webdesign + #pragma once +#include void app_glance_destroy(void); -//static void app_glance_update(AppGlanceReloadSession *, size_t, void *); \ No newline at end of file diff --git a/src/c/main.c b/src/c/main.c index 12c08a8..cbe6061 100644 --- a/src/c/main.c +++ b/src/c/main.c @@ -9,7 +9,6 @@ #include "messaging.h" #include "app_glance.h" - // do init static void init(void) { window_main_init(); diff --git a/src/c/messaging.h b/src/c/messaging.h index f22842e..eead035 100644 --- a/src/c/messaging.h +++ b/src/c/messaging.h @@ -1,7 +1,12 @@ +// 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 , go4u.de Webdesign + #pragma once +#include -//static void messaging_inbox_received(DictionaryIterator *, void *); -//static void messaging_inbox_dropped(AppMessageResult, void *); void messaging_outbox_send(const char *, const char *); void messaging_init(void); void messaging_destroy(void); diff --git a/src/c/printer.h b/src/c/printer.h index 2dfd362..839d0fa 100644 --- a/src/c/printer.h +++ b/src/c/printer.h @@ -1,4 +1,11 @@ +// 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 , go4u.de Webdesign + #pragma once +#include enum PRINTERSTATE { LOADING, @@ -10,7 +17,6 @@ enum PRINTERSTATE { ERROR }; - enum PRINTERSTATE printer_get_state(void); void printer_set_state(enum PRINTERSTATE); void printer_set_state_by_char(const char *); diff --git a/src/c/progress_layer.c b/src/c/progress_layer.c index dccc91a..09ebbf9 100644 --- a/src/c/progress_layer.c +++ b/src/c/progress_layer.c @@ -5,7 +5,7 @@ // Author: Dominik Scholz , go4u.de Webdesign // progress_layer -// taken from https://github.com/pebble-examples/ui-patterns/ (MIT License) +// taken from https://github.com/pebble-examples/ui-patterns/ // // Licence: The MIT License (MIT) // Author: C-D-Lewis diff --git a/src/c/progress_layer.h b/src/c/progress_layer.h index 6b5d103..680fbb2 100644 --- a/src/c/progress_layer.h +++ b/src/c/progress_layer.h @@ -1,13 +1,17 @@ -#pragma once +// 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 , go4u.de Webdesign +#pragma once #include typedef Layer ProgressLayer; - ProgressLayer* progress_layer_create(GRect frame); void progress_layer_destroy(ProgressLayer* progress_layer); void progress_layer_increment_progress(ProgressLayer* progress_layer, int16_t progress); void progress_layer_set_progress(ProgressLayer* progress_layer, int16_t progress_percent); void progress_layer_set_corner_radius(ProgressLayer* progress_layer, uint16_t corner_radius); void progress_layer_set_foreground_color(ProgressLayer* progress_layer, GColor color); -void progress_layer_set_background_color(ProgressLayer* progress_layer, GColor color); \ No newline at end of file +void progress_layer_set_background_color(ProgressLayer* progress_layer, GColor color); diff --git a/src/c/window_confirm.c b/src/c/window_confirm.c index 0921796..ccbd696 100644 --- a/src/c/window_confirm.c +++ b/src/c/window_confirm.c @@ -1,3 +1,9 @@ +// 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 , go4u.de Webdesign + #include #include "window_confirm.h" @@ -37,7 +43,7 @@ static void window_main_actionbar_config(void *context) { } -// render background layer +// render icon layer static void window_main_draw_icon_layer(Layer *layer, GContext *context) { GRect bounds = layer_get_bounds(layer); const GEdgeInsets frame_insets = { diff --git a/src/c/window_confirm.h b/src/c/window_confirm.h index 9c51ead..40a20fd 100644 --- a/src/c/window_confirm.h +++ b/src/c/window_confirm.h @@ -5,6 +5,8 @@ // Author: Dominik Scholz , go4u.de Webdesign #pragma once +#include + void window_confirm_init(void); void window_confirm_init_custom(const char *, GColor, void(*)(void)); -void window_confirm_destroy(void); \ No newline at end of file +void window_confirm_destroy(void); diff --git a/src/c/window_main.h b/src/c/window_main.h index 2b836c7..3543117 100644 --- a/src/c/window_main.h +++ b/src/c/window_main.h @@ -1,11 +1,13 @@ +// 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 , go4u.de Webdesign + #pragma once +#include -//static void window_main_actionbar_up(ClickRecognizerRef, void *); -//static void window_main_actionbar_select(ClickRecognizerRef, void *); -//static void window_main_actionbar_down(ClickRecognizerRef, void *); void window_main_actionbar_config(void *); -//static void window_main_load_handler(Window *); -//static void window_main_unload_handler(Window *); void window_main_set_time_remaing_counter(const char *); void window_main_set_filename(const char *); void window_main_set_nozzle(const uint16_t, const uint16_t); diff --git a/src/c/window_menu.c b/src/c/window_menu.c index cd8ed54..09f35f5 100644 --- a/src/c/window_menu.c +++ b/src/c/window_menu.c @@ -7,11 +7,12 @@ #include #include "window_menu.h" #include "window_confirm.h" +#include "window_message.h" #include "messaging.h" #define MENU_SECTIONS 3 #define MENU_FIRST_ITEMS 1 -#define MENU_SECOND_ITEMS 4 +#define MENU_SECOND_ITEMS 6 #define MENU_THIRD_ITEMS 2 static Window *s_window_main; @@ -37,36 +38,56 @@ static void window_menu_confirm_cancel_printjob(int s, void *ctx) { // preheat bed and nozzle static void window_menu_preheat(int s, void *ctx) { + window_message_init_custom("Preheat", GColorOrange); messaging_outbox_send("preheat", ""); } +// preheat bed +static void window_menu_preheat_bed(int s, void *ctx) { + window_message_init_custom("Preheat Bed", GColorOrange); + messaging_outbox_send("preheat", "bed"); +} + + +// preheat nozzle +static void window_menu_preheat_nozzle(int s, void *ctx) { + window_message_init_custom("Preheat Nozzle", GColorOrange); + messaging_outbox_send("preheat", "nozzle"); +} + + // cooldown bed and nozzle static void window_menu_cooldown(int s, void *ctx) { + window_message_init_custom("Cooldown", GColorCyan); messaging_outbox_send("gcode", "M117 Cooldown...\nM140 S0\nM104 S0"); } // turn fans on static void window_menu_fans_on(int s, void *ctx) { + window_message_init_custom("Fans on", GColorGreen); messaging_outbox_send("gcode", "M117 Fans on...\nM106 S255"); } // turn fans off static void window_menu_fans_off(int s, void *ctx) { + window_message_init_custom("Fans off", GColorGreen); messaging_outbox_send("gcode", "M117 Fans off...\nM106 S0"); } // home all axes static void window_menu_home_axes(int s, void *ctx) { + window_message_init_custom("Homing", GColorMagenta); messaging_outbox_send("gcode", "M117 Homing...\nG28"); } // turn all motors off static void window_menu_motors_off(int s, void *ctx) { + window_message_init_custom("Motors off", GColorVividViolet); messaging_outbox_send("gcode", "M117 Motors off...\nM18"); } @@ -96,16 +117,26 @@ static void window_menu_load_handler(Window *window) { .callback = window_menu_preheat }; s_menu_items_second[1] = (SimpleMenuItem) { + .title = "Preheat bed", + .subtitle = "Preheat bed only", + .callback = window_menu_preheat_bed + }; + s_menu_items_second[2] = (SimpleMenuItem) { + .title = "Preheat nozzle", + .subtitle = "Preheat nozzle only", + .callback = window_menu_preheat_nozzle + }; + s_menu_items_second[3] = (SimpleMenuItem) { .title = "Cooldown", .subtitle = "Cooldown nozzle and bed", .callback = window_menu_cooldown }; - s_menu_items_second[2] = (SimpleMenuItem) { + s_menu_items_second[4] = (SimpleMenuItem) { .title = "Fans on", .subtitle = "Turn the fans on", .callback = window_menu_fans_on }; - s_menu_items_second[3] = (SimpleMenuItem) { + s_menu_items_second[5] = (SimpleMenuItem) { .title = "Fans off", .subtitle = "Turn the fans off", .callback = window_menu_fans_off diff --git a/src/c/window_menu.h b/src/c/window_menu.h index bb10198..7726d12 100644 --- a/src/c/window_menu.h +++ b/src/c/window_menu.h @@ -1,4 +1,11 @@ +// 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 , go4u.de Webdesign + #pragma once +#include void window_menu_init(void); -void window_menu_destroy(void); \ No newline at end of file +void window_menu_destroy(void); diff --git a/src/c/window_message.c b/src/c/window_message.c new file mode 100644 index 0000000..a387a10 --- /dev/null +++ b/src/c/window_message.c @@ -0,0 +1,176 @@ +// 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 , go4u.de Webdesign + +#include +#include "window_message.h" + +static Window *s_window_main; + +static TextLayer *s_layer_label; + +static Layer *s_layer_background; +static Layer *s_layer_icon; + +static GDrawCommandImage *s_gdraw_image; + +static Animation *s_animation_appear = NULL; + +static AppTimer *s_timer = NULL; + +static GColor s_color; + + +// render icon layer +static void window_message_draw_icon_layer(Layer *layer, GContext *context) { + GRect bounds = layer_get_bounds(layer); + const GEdgeInsets frame_insets = { + .top = ACTION_BAR_WIDTH / 2, + .left = ACTION_BAR_WIDTH / 2 + }; + + if (s_gdraw_image) + gdraw_command_image_draw(context, s_gdraw_image, grect_inset(bounds, frame_insets).origin); +} + + +// render background layer +static void window_message_draw_background_layer(Layer *layer, GContext *context) { + graphics_context_set_fill_color(context, PBL_IF_COLOR_ELSE(s_color, GColorWhite)); + graphics_fill_rect(context, layer_get_bounds(layer), 0, 0); +} + + +// window_message_hide_automatically +static void window_message_hide_automatically(void *data) { + s_timer = NULL; + window_message_destroy(); +} + +// animation stopped +static void window_message_animation_stopped(Animation *animation, bool finished, void *context) { + s_animation_appear = NULL; +} + + +// animation appear start +static void window_message_appear_handler(Window *window) { + // if timer running, cancel it + if (s_timer) + app_timer_cancel(s_timer); + + // if animation running, cancel it + if (s_animation_appear) + animation_unschedule(s_animation_appear); + + GRect bounds = layer_get_bounds(window_get_root_layer(window)); + GRect start = layer_get_frame(s_layer_background); + GRect finish = bounds; + s_animation_appear = (Animation*)property_animation_create_layer_frame(s_layer_background, &start, &finish); + + animation_set_handlers(s_animation_appear, (AnimationHandlers) { + .stopped = window_message_animation_stopped + }, NULL); + animation_set_delay(s_animation_appear, 500); + animation_schedule(s_animation_appear); + + s_timer = app_timer_register(1250, window_message_hide_automatically, NULL); +} + + +// animation disappear start +static void window_message_disappear_handler(Window *window) { + // if timer running, cancel it + if (s_timer) { + app_timer_cancel(s_timer); + s_timer = NULL; + } + + // if animation running, cancel it + if (s_animation_appear) + animation_unschedule(s_animation_appear); +} + + +// load window handler +static void window_message_load_handler(Window *window) { + // create window layer + Layer *window_layer = window_get_root_layer(window); + GRect bounds = layer_get_bounds(window_layer); + + // create background layer + const GEdgeInsets background_insets = {.top = bounds.size.h /* Start hidden */}; + s_layer_background = layer_create(grect_inset(bounds, background_insets)); + layer_set_update_proc(s_layer_background, window_message_draw_background_layer); + layer_add_child(window_layer, s_layer_background); + + // load images + s_gdraw_image = gdraw_command_image_create_with_resource(RESOURCE_ID_NOTIFICATION_PDC); + + // create icon + s_layer_icon = layer_create(bounds); + layer_set_update_proc(s_layer_icon, window_message_draw_icon_layer); + layer_add_child(s_layer_background, s_layer_icon); + + // create message + s_layer_label = text_layer_create(GRect(ACTION_BAR_WIDTH / 2, 90, bounds.size.w - ACTION_BAR_WIDTH * 2, bounds.size.h - 90)); + text_layer_set_text_color(s_layer_label, PBL_IF_COLOR_ELSE(GColorBlack, GColorBlack)); + text_layer_set_background_color(s_layer_label, GColorClear); + text_layer_set_font(s_layer_label, fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD)); + text_layer_set_text_alignment(s_layer_label, GTextAlignmentLeft); + text_layer_set_text(s_layer_label, "Got it."); + layer_add_child(s_layer_background, text_layer_get_layer(s_layer_label)); +} + + +// unload window handler +static void window_message_unload_handler(Window *window) { + // if animation running, cancel it + if (s_animation_appear) + animation_unschedule(s_animation_appear); + + // destroy icon layers + layer_destroy(s_layer_icon); + + // destroy images + gdraw_command_image_destroy(s_gdraw_image); + + // destroy text layers + text_layer_destroy(s_layer_label); + + // destroy background layer + layer_destroy(s_layer_background); + + // destroy window + window_destroy(s_window_main); +} + + +// create new window +static void window_message_init(void) { + s_window_main = window_create(); + window_set_background_color(s_window_main, GColorClear); + window_set_window_handlers(s_window_main, (WindowHandlers) { + .load = window_message_load_handler, + .unload = window_message_unload_handler, + .appear = window_message_appear_handler, + .disappear = window_message_disappear_handler + }); + window_stack_push(s_window_main, true); +} + + +// create a new window with predefined message +void window_message_init_custom(const char *message, GColor bg_color) { + s_color = bg_color; + window_message_init(); + text_layer_set_text(s_layer_label, message); +} + + +// pop window from stack +void window_message_destroy(void) { + window_stack_pop(true); +} diff --git a/src/c/window_message.h b/src/c/window_message.h new file mode 100644 index 0000000..539e642 --- /dev/null +++ b/src/c/window_message.h @@ -0,0 +1,11 @@ +// 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 , go4u.de Webdesign + +#pragma once +#include + +void window_message_init_custom(const char *, GColor); +void window_message_destroy(void); diff --git a/src/pkjs/ajax.js b/src/pkjs/ajax.js index 033996a..a791709 100644 --- a/src/pkjs/ajax.js +++ b/src/pkjs/ajax.js @@ -1,3 +1,9 @@ +// 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 , go4u.de Webdesign + var Ajax = { // send ajax call diff --git a/src/pkjs/base64.js b/src/pkjs/base64.js index 2ffe17c..03c1dad 100644 --- a/src/pkjs/base64.js +++ b/src/pkjs/base64.js @@ -1,3 +1,15 @@ +// 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 , go4u.de Webdesign + +// Base64 encode +// taken from http://www.webtoolkit.info/javascript_base64.html +// +// Licence: CC BY 2.0, http://creativecommons.org/licenses/by/2.0/ +// Author: webtoolkit.info Inc. + var Base64 = { _keyStr : "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=", encode : function (input) { diff --git a/src/pkjs/config.js b/src/pkjs/config.js index ead147e..1f1bf01 100644 --- a/src/pkjs/config.js +++ b/src/pkjs/config.js @@ -1,3 +1,9 @@ +// 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 , go4u.de Webdesign + module.exports = [ { "type": "heading", diff --git a/src/pkjs/index.js b/src/pkjs/index.js index 989f5f5..7efbd93 100644 --- a/src/pkjs/index.js +++ b/src/pkjs/index.js @@ -1,3 +1,9 @@ +// 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 , go4u.de Webdesign + var Clay = require('pebble-clay'), clayConfig = require('./config'), clay = new Clay(clayConfig, null, {autoHandleEvents: false}), diff --git a/src/pkjs/octoprint.js b/src/pkjs/octoprint.js index 1ecea23..9e552ef 100644 --- a/src/pkjs/octoprint.js +++ b/src/pkjs/octoprint.js @@ -1,3 +1,9 @@ +// 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 , go4u.de Webdesign + var Octoprint = { path: { diff --git a/src/pkjs/octowatch.js b/src/pkjs/octowatch.js index d9627d1..20fc2e0 100644 --- a/src/pkjs/octowatch.js +++ b/src/pkjs/octowatch.js @@ -1,3 +1,9 @@ +// 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 , go4u.de Webdesign + var Octowatch = { // data @@ -34,9 +40,20 @@ var Octowatch = { // preheat nozzle and bed case 'preheat': - Octoprint.sendCommand("M117 Preheating..."); // display message - Octoprint.sendCommand("M104 S" + localStorage.getItem('octoprintnozzle')); // set nozzle temp - Octoprint.sendCommand("M140 S" + localStorage.getItem('octoprintbed')); // set bed temp + switch(data[1]) { + case 'bed': + Octoprint.sendCommand("M117 Preheating Bed..."); // display message + Octoprint.sendCommand("M140 S" + localStorage.getItem('octoprintbed')); // set bed temp + break; + case 'nozzle': + Octoprint.sendCommand("M117 Preheating Nozzle..."); // display message + Octoprint.sendCommand("M104 S" + localStorage.getItem('octoprintnozzle')); // set nozzle temp + break; + default: + Octoprint.sendCommand("M117 Preheating..."); // display message + Octoprint.sendCommand("M104 S" + localStorage.getItem('octoprintnozzle')); // set nozzle temp + Octoprint.sendCommand("M140 S" + localStorage.getItem('octoprintbed')); // set bed temp + } break; // send gcode command(s)