|
| 1 | +// OctoWatch2 |
| 2 | +// A Pebble watch app for monitoring and basic controlling of 3D printers via Octoprint |
| 3 | +// |
| 4 | +// Licence: CC BY-SA 3.0, http://creativecommons.org/licenses/by-sa/3.0/ |
| 5 | +// Author: Dominik Scholz <[email protected]>, go4u.de Webdesign <[email protected]> |
| 6 | + |
| 7 | +#include <pebble.h> |
| 8 | +#include "window_menu.h" |
| 9 | +#include "window_confirm.h" |
| 10 | +#include "messaging.h" |
| 11 | + |
| 12 | +#define MENU_SECTIONS 3 |
| 13 | +#define MENU_FIRST_ITEMS 1 |
| 14 | +#define MENU_SECOND_ITEMS 4 |
| 15 | +#define MENU_THIRD_ITEMS 2 |
| 16 | + |
| 17 | +static Window *s_window_main; |
| 18 | + |
| 19 | +static SimpleMenuLayer *s_layer_simplemenu; |
| 20 | +static SimpleMenuSection s_menu_sections[MENU_SECTIONS]; |
| 21 | +static SimpleMenuItem s_menu_items_first[MENU_FIRST_ITEMS]; |
| 22 | +static SimpleMenuItem s_menu_items_second[MENU_SECOND_ITEMS]; |
| 23 | +static SimpleMenuItem s_menu_items_third[MENU_THIRD_ITEMS]; |
| 24 | + |
| 25 | + |
| 26 | +// user canceled printjob |
| 27 | +static void window_menu_cancel_printjob(void) { |
| 28 | + messaging_outbox_send("cancel", ""); |
| 29 | +} |
| 30 | + |
| 31 | + |
| 32 | +// confirm cancel printjob |
| 33 | +static void window_menu_confirm_cancel_printjob(int s, void *ctx) { |
| 34 | + window_confirm_init_custom("Abort printjob?", PBL_IF_COLOR_ELSE(GColorRed, GColorWhite), window_menu_cancel_printjob); |
| 35 | +} |
| 36 | + |
| 37 | + |
| 38 | +// preheat bed and nozzle |
| 39 | +static void window_menu_preheat(int s, void *ctx) { |
| 40 | + messaging_outbox_send("preheat", ""); |
| 41 | +} |
| 42 | + |
| 43 | + |
| 44 | +// cooldown bed and nozzle |
| 45 | +static void window_menu_cooldown(int s, void *ctx) { |
| 46 | + messaging_outbox_send("gcode", "M117 Cooldown...\nM140 S0\nM104 S0"); |
| 47 | +} |
| 48 | + |
| 49 | + |
| 50 | +// turn fans on |
| 51 | +static void window_menu_fans_on(int s, void *ctx) { |
| 52 | + messaging_outbox_send("gcode", "M117 Fans on...\nM106 S255"); |
| 53 | +} |
| 54 | + |
| 55 | + |
| 56 | +// turn fans off |
| 57 | +static void window_menu_fans_off(int s, void *ctx) { |
| 58 | + messaging_outbox_send("gcode", "M117 Fans off...\nM106 S0"); |
| 59 | +} |
| 60 | + |
| 61 | + |
| 62 | +// home all axes |
| 63 | +static void window_menu_home_axes(int s, void *ctx) { |
| 64 | + messaging_outbox_send("gcode", "M117 Homing...\nG28"); |
| 65 | +} |
| 66 | + |
| 67 | + |
| 68 | +// turn all motors off |
| 69 | +static void window_menu_motors_off(int s, void *ctx) { |
| 70 | + messaging_outbox_send("gcode", "M117 Motors off...\nM18"); |
| 71 | +} |
| 72 | + |
| 73 | + |
| 74 | +// load window handler |
| 75 | +static void window_menu_load_handler(Window *window) { |
| 76 | + // create window layer |
| 77 | + Layer *window_layer = window_get_root_layer(window); |
| 78 | + GRect bounds = layer_get_bounds(window_layer); |
| 79 | + |
| 80 | + // create first menu section |
| 81 | + s_menu_items_first[0] = (SimpleMenuItem) { |
| 82 | + .title = "Abort printjob", |
| 83 | + .subtitle = "Stop running printjob", |
| 84 | + .callback = window_menu_confirm_cancel_printjob |
| 85 | + }; |
| 86 | + s_menu_sections[0] = (SimpleMenuSection) { |
| 87 | + .title = "Printjob", |
| 88 | + .num_items = MENU_FIRST_ITEMS, |
| 89 | + .items = s_menu_items_first |
| 90 | + }; |
| 91 | + |
| 92 | + // create second menu section |
| 93 | + s_menu_items_second[0] = (SimpleMenuItem) { |
| 94 | + .title = "Preheat", |
| 95 | + .subtitle = "Preheat nozzle and bed", |
| 96 | + .callback = window_menu_preheat |
| 97 | + }; |
| 98 | + s_menu_items_second[1] = (SimpleMenuItem) { |
| 99 | + .title = "Cooldown", |
| 100 | + .subtitle = "Cooldown nozzle and bed", |
| 101 | + .callback = window_menu_cooldown |
| 102 | + }; |
| 103 | + s_menu_items_second[2] = (SimpleMenuItem) { |
| 104 | + .title = "Fans on", |
| 105 | + .subtitle = "Turn the fans on", |
| 106 | + .callback = window_menu_fans_on |
| 107 | + }; |
| 108 | + s_menu_items_second[3] = (SimpleMenuItem) { |
| 109 | + .title = "Fans off", |
| 110 | + .subtitle = "Turn the fans off", |
| 111 | + .callback = window_menu_fans_off |
| 112 | + }; |
| 113 | + s_menu_sections[1] = (SimpleMenuSection) { |
| 114 | + .title = "Temperature", |
| 115 | + .num_items = MENU_SECOND_ITEMS, |
| 116 | + .items = s_menu_items_second |
| 117 | + }; |
| 118 | + |
| 119 | + // create third menu section |
| 120 | + s_menu_items_third[0] = (SimpleMenuItem) { |
| 121 | + .title = "Home all", |
| 122 | + .subtitle = "Home all axes (XYZ)", |
| 123 | + .callback = window_menu_home_axes |
| 124 | + }; |
| 125 | + s_menu_items_third[1] = (SimpleMenuItem) { |
| 126 | + .title = "Motors off", |
| 127 | + .subtitle = "Turn the motors off", |
| 128 | + .callback = window_menu_motors_off |
| 129 | + }; |
| 130 | + s_menu_sections[2] = (SimpleMenuSection) { |
| 131 | + .title = "Motion", |
| 132 | + .num_items = MENU_THIRD_ITEMS, |
| 133 | + .items = s_menu_items_third |
| 134 | + }; |
| 135 | + |
| 136 | + // create simplemenulayer |
| 137 | + s_layer_simplemenu = simple_menu_layer_create(bounds, window, s_menu_sections, MENU_SECTIONS, NULL); |
| 138 | + menu_layer_set_highlight_colors(simple_menu_layer_get_menu_layer(s_layer_simplemenu), PBL_IF_COLOR_ELSE(GColorVividCerulean, GColorBlack), PBL_IF_COLOR_ELSE(GColorBlack, GColorWhite)); |
| 139 | + layer_add_child(window_layer, simple_menu_layer_get_layer(s_layer_simplemenu)); |
| 140 | +} |
| 141 | + |
| 142 | + |
| 143 | +// unload window handler |
| 144 | +static void window_menu_unload_handler(Window *window) { |
| 145 | + // destroy simple menu layer |
| 146 | + simple_menu_layer_destroy(s_layer_simplemenu); |
| 147 | + |
| 148 | + // destroy window |
| 149 | + window_destroy(s_window_main); |
| 150 | +} |
| 151 | + |
| 152 | + |
| 153 | +// create new window |
| 154 | +void window_menu_init(void) { |
| 155 | + s_window_main = window_create(); |
| 156 | + window_set_background_color(s_window_main, PBL_IF_COLOR_ELSE(GColorWhite, GColorWhite)); |
| 157 | + window_set_window_handlers(s_window_main, (WindowHandlers) { |
| 158 | + .load = window_menu_load_handler, |
| 159 | + .unload = window_menu_unload_handler |
| 160 | + }); |
| 161 | + window_stack_push(s_window_main, true); |
| 162 | +} |
| 163 | + |
| 164 | + |
| 165 | +// destroy window |
| 166 | +void window_menu_destroy(void) { |
| 167 | + window_stack_pop(true); |
| 168 | +} |
0 commit comments