Created
August 23, 2020 15:12
-
-
Save elinux9000/ef23cc39616650503f8f0f4744e803f8 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //https://xstate.js.org/viz/?gist=https://gist.github.com/monzie9000/8006ab6c5db67c596802c73a6ab2a3a5 | |
| //https://app.lucidchart.com/documents/edit/de713c94-5b57-4100-a486-2fbdef83f28d/HWEp-vi-RSFO?beaconFlowId=DB76397B0359590F | |
| "use strict"; | |
| const debug = false; | |
| var pointer_upulse; //pointer that is used to update upulse | |
| if (visualizing()) | |
| debugLog("VIZ", debug); | |
| else | |
| debugLog("LOCAL", debug); | |
| function visualizing() | |
| { | |
| let getUrl = window.location; | |
| //console.log("URL=" + getUrl.host); | |
| if (getUrl.host.includes("xstate.js.org")) | |
| return true; | |
| return false; | |
| } | |
| function debugLog(msg, debug) | |
| { | |
| if (debug == undefined) | |
| console.log("incorrect call to debugLog " + msg); | |
| if (debug) | |
| console.log(msg); | |
| } | |
| function postDone(context, event) | |
| { | |
| let debug = false; | |
| debugLog("postDone",debug); | |
| try | |
| { | |
| context.counter++; | |
| $("#myBar").css("width", context.counter + "%"); | |
| if (context.counter < 100) | |
| { | |
| return true; | |
| } | |
| } | |
| catch (err) | |
| { | |
| } | |
| return false; | |
| }; | |
| function createCookie(name, value, days) { | |
| var expires; | |
| if (days) { | |
| var date = new Date(); | |
| date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000)); | |
| expires = "; expires=" + date.toGMTString(); | |
| } | |
| else { | |
| expires = ""; | |
| } | |
| document.cookie = name + "=" + value + expires + "; path=/"; | |
| } | |
| function getCookie(c_name) { | |
| if (document.cookie.length > 0) { | |
| var c_start = document.cookie.indexOf(c_name + "="); | |
| if (c_start != -1) { | |
| c_start = c_start + c_name.length + 1; | |
| var c_end = document.cookie.indexOf(";", c_start); | |
| if (c_end == -1) { | |
| c_end = document.cookie.length; | |
| } | |
| return unescape(document.cookie.substring(c_start, c_end)); | |
| } | |
| } | |
| return ""; | |
| } | |
| class TreatmentParms { | |
| constructor(i) | |
| { | |
| if (i==9) | |
| this.label="System"; | |
| else | |
| this.label = "Preset " + (i+1); | |
| } | |
| label = "unlabelled"; | |
| delivery_device; | |
| spot_size; | |
| power = 0; | |
| energy = 0; | |
| micro_pulse_enabled = true; | |
| micro_pulse_duty_cycle = 5; | |
| micro_pulse_duration = 0.1; | |
| micro_pulse_interval = 1.9; | |
| macro_pulse_duration = 20000; | |
| countdown_enabled = true; | |
| macro_pulse_interval = 10; | |
| macro_pulse_passes = 5; | |
| macro_pulse_actual_pass; | |
| pulses = 0; | |
| total_energy = 0; | |
| valid = false; | |
| } | |
| var preset_arr = []; | |
| var tempParm; | |
| var upulse_tempParm; | |
| var preset_index = 0; | |
| var enable_breakpoints = false; | |
| function breakpoint() | |
| { | |
| let debug = true; | |
| if (enable_breakpoints) { | |
| debugLog("breakpoint",debug); | |
| } | |
| } | |
| const guiMachine = Machine( | |
| { | |
| id: 'webGui', | |
| initial: 'start_state', | |
| context: | |
| { | |
| progressBar: 0, | |
| timeout: 0, | |
| counter: 0, | |
| previousState: 0, | |
| last: "", | |
| temp: 0, | |
| bright_value: 8, | |
| volume_value: 6, | |
| power: 0, | |
| total_energy: 0, | |
| pulses: 0, | |
| device: "",//empty when nothing connected, otherwise name of device | |
| }, | |
| on: | |
| { | |
| KEYSWITCH_OFF: "start_state.off_state", | |
| ESTOP: "start_state.off_state", | |
| ENERGY_RESET_CLICKED: | |
| { | |
| actions: "reset_energy_action", | |
| }, | |
| PULSES_RESET_CLICKED: | |
| { | |
| actions: "reset_pulses_action", | |
| }, | |
| INTERVAL_RESET_CLICKED: | |
| { | |
| actions: "reset_passes_action", | |
| }, | |
| DEVICE_CONNECT: | |
| { | |
| target: "device_state", | |
| actions: "device_connected", | |
| }, | |
| DEVICE_DISCONNECT: | |
| { | |
| target: "operation_state.standby_state", | |
| actions: "device_disconnected" | |
| }, | |
| }, | |
| states: | |
| { | |
| start_state: | |
| { | |
| initial: "off_state", | |
| states: | |
| { | |
| off_state: | |
| { | |
| on: | |
| { | |
| KEYSWITCH_ON: "post_state", | |
| } | |
| }, | |
| post_state: | |
| { | |
| invoke: | |
| { | |
| id: 'incInterval', | |
| src: (context, event) => (callback, onReceive) => | |
| { | |
| if (!visualizing()) | |
| { | |
| // This will send the event to the parent periodically | |
| const id = setInterval(() => callback('TICK'), 20); | |
| // Perform cleanup | |
| return () => clearInterval(id); | |
| } | |
| } | |
| }, | |
| entry: function(context, event) | |
| { | |
| let debug = false; | |
| try | |
| { | |
| var json_str = getCookie('preset_arr_cookie'); | |
| if (json_str) { | |
| preset_arr = JSON.parse(json_str); | |
| } | |
| else { | |
| debugLog("initialize array", debug); | |
| preset_arr = new Array(10); | |
| for (let i = 0; i < 10; i++) | |
| { | |
| preset_arr[i] = new TreatmentParms(i); | |
| debugLog("preset[" + i + "] " + preset_arr[i].label, debug); | |
| } | |
| } | |
| $("#myProgress").show(); | |
| } | |
| catch (err) | |
| { | |
| console.log(err); | |
| } | |
| }, | |
| exit: function(context, event) | |
| { | |
| try | |
| { | |
| $("#myProgress").hide(); | |
| context.counter = 0; | |
| } | |
| catch (err) | |
| { | |
| } | |
| }, | |
| on: | |
| { | |
| TICK: [ | |
| { | |
| target: "post_state", | |
| internal: true, | |
| cond: postDone, | |
| action: assign( | |
| { | |
| counter: context => context.counter + 1 | |
| }), | |
| }, | |
| { | |
| target: "#standby_id", | |
| }, ] | |
| }, | |
| }, | |
| }, | |
| }, | |
| bright_state: | |
| { | |
| id:"bright_state_uid", | |
| entry: ["show_bright_screen", "read_bright_value"], | |
| exit: ["hide_bright_screen"], | |
| on: | |
| { | |
| CANCEL: | |
| { | |
| target: '#hist_state_uid' | |
| }, | |
| OK: | |
| { | |
| target: '#hist_state_uid', | |
| actions: "write_bright_value", | |
| }, | |
| CHANGE_VAL: | |
| { | |
| target: 'bright_state', | |
| actions: "update TEMP_VAR, brightness", | |
| }, | |
| } | |
| }, | |
| volume_state: | |
| { | |
| id:"volume_state_uid", | |
| entry: ["show_volume_screen", "read_volume_value"], | |
| exit: ["hide_volume_screen"], | |
| on: | |
| { | |
| CANCEL: | |
| { | |
| target: '#hist_state_uid' | |
| }, | |
| OK: | |
| { | |
| target: '#hist_state_uid', | |
| actions: "write_volume_value", | |
| }, | |
| CHANGE_VAL: | |
| { | |
| target: 'volume_state', | |
| actions: "update TEMP_VAR, volume", | |
| }, | |
| } | |
| }, | |
| device_state: | |
| { | |
| entry: ["show_device_screen"], | |
| exit: ["hide_device_screen"], | |
| on: | |
| { | |
| EDIT_PRESET_CLICKED: | |
| { | |
| target:"operation_state.standby_state.preset_state", | |
| }, | |
| OK_CLICKED: | |
| { | |
| target:"operation_state.standby_state.main_state", | |
| actions:"load_device_defaults", | |
| }, | |
| CANCEL_CLICKED: | |
| { | |
| target:"operation_state.standby_state.main_state", | |
| }, | |
| },//on: | |
| }, | |
| micro_pulse_state: | |
| { | |
| id:"micro_pulse_state_uid", | |
| entry: ["show_micro_pulse_screen", "read_micro_pulse_value"], | |
| exit: ["hide_micro_pulse_screen"], | |
| on: | |
| { | |
| CANCEL_UPULSE: | |
| { | |
| target: '#hist_state_uid' | |
| }, | |
| DEFAULT: | |
| { | |
| actions: "micro_pulse_defaults", | |
| }, | |
| SAVE_UPULSE: | |
| { | |
| target: '#hist_state_uid', | |
| actions: "write_micro_pulse_value", | |
| }, | |
| DUTY: | |
| { | |
| actions: "update_duty_cycle", | |
| }, | |
| DURATION_CLICKED: | |
| { | |
| actions: "update_micro_duration", | |
| }, | |
| INTERVAL_CLICKED: | |
| { | |
| actions: "update_micro_interval", | |
| }, | |
| } | |
| }, | |
| operation_state: | |
| { | |
| initial:"standby_state", | |
| states: | |
| { | |
| treat_state: | |
| { | |
| entry: ["show_screen", "save_state", "update_main_screen_values","handle_leds_treat","update_working_vars_entry"], | |
| exit: ["hide_screen", "clear_main_focus","handle_leds_standby","update_working_vars_exit"], | |
| on: | |
| { | |
| TICK: | |
| { | |
| actions: ["handle_tick"], | |
| }, | |
| FOOTSWITCH: | |
| { | |
| actions: ["handle_footswitch"], | |
| }, | |
| POWER_CLICKED: | |
| { | |
| actions: ["handle_power_change"], | |
| }, | |
| INTERVAL_CLICKED: | |
| { | |
| actions: "update_macro_interval", | |
| }, | |
| DURATION_CLICKED: | |
| { | |
| actions: "update_macro_duration", | |
| }, | |
| TREAT_CLICKED: "standby_state.main_state", | |
| MICRO_PULSE_CLICKED: "#micro_pulse_state_uid", | |
| }, | |
| },//treat_state | |
| hist_state: | |
| { | |
| id: "hist_state_uid", | |
| type: 'history', | |
| history: "deep", | |
| target: 'standby_state.main_state' | |
| },//hist_state | |
| standby_state: | |
| { | |
| id: "standby_id", | |
| initial: 'main_state', | |
| on: | |
| { | |
| MAIN_CLICKED: 'standby_state.main_state', | |
| PRESET_CLICKED: 'standby_state.preset_state', | |
| SETUP_CLICKED: 'standby_state.setup_state', | |
| INFO_CLICKED: 'standby_state.info_state', | |
| BRIGHT_CLICKED: '#bright_state_uid', | |
| VOLUME_CLICKED: '#volume_state_uid', | |
| MICRO_PULSE_CLICKED: "#micro_pulse_state_uid", | |
| CW_CLICKED: | |
| { | |
| actions: ["clear_main_focus", "switch_cw_button", "update_main_screen_values"], | |
| }, | |
| BACK_CLICKED: | |
| { | |
| actions: "back", | |
| }, | |
| TREAT_CLICKED: "treat_state", | |
| }, | |
| states: | |
| { | |
| preset_editing_state: | |
| { | |
| id: "preset_editing_uid", | |
| entry: ["show_screen","update_working_vars_entry","save_state", "populate_preset_action"], | |
| exit: ["hide_screen"], | |
| on: | |
| { | |
| EDIT_LABEL: | |
| { | |
| actions: "show_keyboard_action", | |
| }, | |
| ACCEPT: | |
| { | |
| actions: "hide_keyboard_action", | |
| }, | |
| CANCEL: | |
| { | |
| actions: "hide_keyboard_action", | |
| }, | |
| OK_BUTTON: | |
| { | |
| target: "preset_state", | |
| actions: ["update_preset_action","update_working_vars_exit"], | |
| }, | |
| CANCEL_BUTTON: "preset_state", | |
| RESET_BUTTON: | |
| { | |
| actions: "reset_preset", | |
| }, | |
| CW_CLICKED: | |
| { | |
| actions: "switch_cw_button_editing", | |
| }, | |
| POWER_CLICKED: | |
| { | |
| actions: ["handle_power_change"], | |
| }, | |
| DURATION_CLICKED: | |
| { | |
| actions: "update_macro_duration", | |
| }, | |
| INTERVAL_CLICKED: | |
| { | |
| actions: "update_macro_interval", | |
| }, | |
| } | |
| }, | |
| main_state: | |
| { | |
| entry: ["show_screen", "save_state","update_working_vars_entry"], | |
| exit: ["hide_screen", "clear_main_focus","update_working_vars_exit"], | |
| on: | |
| { | |
| POWER_CLICKED: | |
| { | |
| actions: ["handle_power_change"], | |
| }, | |
| INTERVAL_CLICKED: | |
| { | |
| actions: "update_macro_interval", | |
| }, | |
| DURATION_CLICKED: | |
| { | |
| actions: "update_macro_duration", | |
| }, | |
| }, | |
| }, | |
| preset_state: | |
| { | |
| entry: ["show_screen", "save_state","populate_labels_action","show_preset_parms_action"], | |
| exit: ["hide_screen"], | |
| on: | |
| { | |
| EDIT_PRESET_CLICKED: "#preset_editing_uid", | |
| PRESET_BUTTON_CLICKED: | |
| { | |
| actions: ["show_preset_parms_action"], | |
| }, | |
| PRESET_SELECT_CLICKED: | |
| { | |
| actions: ["select_preset"], | |
| }, | |
| PRESET_RESET_CLICKED: | |
| { | |
| actions: ["reset_all_presets"], | |
| }, | |
| PRESET_CANCEL_CLICKED: | |
| { | |
| actions: "hide_preset_parms_action", | |
| }, | |
| } | |
| }, | |
| setup_state: | |
| { | |
| entry: ["show_screen", "save_state"], | |
| exit: ["hide_screen"], | |
| }, | |
| info_state: | |
| { | |
| entry: ["show_screen", "save_state"], | |
| exit: ["hide_screen"], | |
| }, | |
| hist_state_ORIG: | |
| { | |
| type: 'history', | |
| target: 'main_state' | |
| } | |
| }, | |
| },//standby_state | |
| }, | |
| }//operation_state | |
| }, | |
| }, | |
| { | |
| actions: | |
| { | |
| // action implementations | |
| load_device_defaults: function(ctx,event,actionMeta) | |
| { | |
| preset_arr[9] = new TreatmentParms(9);//need to add defaults for other devices | |
| },//load_device_defaults | |
| show_device_screen: function(ctx,event,actionMeta) | |
| { | |
| if (!visualizing()) { | |
| $("#device_screen").show(); | |
| } | |
| }, | |
| hide_device_screen: function(ctx,event,actionMeta) | |
| { | |
| if (!visualizing()) { | |
| $("#device_screen").hide(); | |
| } | |
| }, | |
| device_connected: function(ctx,event,actionMeta) | |
| { | |
| let debug = true; | |
| ctx.device = event.data; | |
| debugLog("Device connected:"+ctx.device,debug); | |
| }, | |
| device_disconnected: function(ctx,event,actionMeta) | |
| { | |
| let debug = true; | |
| ctx.device = ""; | |
| debugLog("Device disconnected",debug); | |
| }, | |
| reset_all_presets: function (ctx, event, actionMeta) | |
| { | |
| let debug = true; | |
| //Confirm selection | |
| if (confirm("Confirm resetting all presets to factory defaults")) { | |
| for (let i = 0; i < 10; i++) | |
| { | |
| preset_arr[i] = new TreatmentParms(i); | |
| } | |
| populate_labels(ctx,event,actionMeta); | |
| show_preset_parms(ctx,event,actionMeta); | |
| } | |
| }, | |
| select_preset: function (ctx, event, actionMeta) | |
| { | |
| let debug = true; | |
| if (preset_index >-1 && preset_index <9) | |
| { | |
| //Confirm selection | |
| var label = preset_arr[preset_index].label; | |
| if (confirm("Confirm loading parameters from "+label)) { | |
| preset_arr[9] = { ...preset_arr[preset_index] } | |
| } | |
| else { | |
| } | |
| } | |
| }, | |
| reset_preset: function(ctx,event,actionMeta) | |
| { | |
| tempParm = new TreatmentParms(preset_index); | |
| populate_preset_func(ctx, event, actionMeta); | |
| }, | |
| handle_leds_treat: function(ctx,event,actionMeta) | |
| { | |
| if (!visualizing()) { | |
| $("#treat_led").attr("data-state","on"); | |
| $("#standby_led").attr("data-state","off"); | |
| $("#treat_toggle_main").attr("data-state","pressed"); | |
| } | |
| }, | |
| handle_leds_standby: function(ctx,event,actionMeta) | |
| { | |
| //Don't change leds to standby if going to uPulse editing. | |
| if (actionMeta.state.value == "micro_pulse_state") | |
| return; | |
| if (!visualizing()) { | |
| $("#treat_led").attr("data-state","off"); | |
| $("#standby_led").attr("data-state","on"); | |
| $("#treat_toggle_main").attr("data-state","unpressed"); | |
| } | |
| }, | |
| populate_labels_action: function(ctx,event,actionMeta) | |
| { | |
| populate_labels(ctx,event,actionMeta); | |
| }, | |
| update_preset_action: function(ctx,event,actionMeta) | |
| { | |
| tempParm.valid = true; | |
| }, | |
| hide_preset_parms_action: function(ctx, event, actionMeta) | |
| { | |
| preset_index=-1; | |
| $("#parm_screen").hide(); | |
| for (var j=0;j<9;j++) { | |
| $("#preset_"+(j+1)).attr("data-state","unpressed"); | |
| } | |
| }, | |
| show_preset_parms_action: function(ctx, event, actionMeta) | |
| { | |
| show_preset_parms(ctx, event, actionMeta); | |
| }, | |
| hide_keyboard_action: function(ctx, event, actionMeta) | |
| { | |
| hide_keyboard_action(ctx, event, actionMeta); | |
| }, | |
| show_keyboard_action: function(ctx, event, actionMeta) | |
| { | |
| show_keyboard_action(ctx, event, actionMeta); | |
| }, | |
| populate_preset_action: function(ctx, event, actionMeta) | |
| { | |
| populate_preset_func(ctx, event, actionMeta); | |
| }, | |
| reset_passes_action: function(context, event, actionMeta) | |
| { | |
| reset_passes_func(context, event, actionMeta); | |
| }, | |
| reset_pulses_action: function(context, event, actionMeta) | |
| { | |
| reset_pulses_func(context, event, actionMeta); | |
| }, | |
| reset_energy_action: function(context, event, actionMeta) | |
| { | |
| reset_energy_func(context, event, actionMeta); | |
| }, | |
| handle_tick: function(context, event, actionMeta) | |
| { | |
| handle_tick(context, event, actionMeta); | |
| }, | |
| handle_footswitch: function(context, event, actionMeta) | |
| { | |
| handle_footswitch(context); | |
| }, | |
| update_macro_interval: function(context, event, actionMeta) | |
| { | |
| let delta = event.data; | |
| if (tempParm.countdown_enabled) | |
| { | |
| if (delta == 1) | |
| { | |
| if (tempParm.macro_pulse_passes < 10) | |
| tempParm.macro_pulse_passes += 1; | |
| } | |
| else | |
| { | |
| if (tempParm.macro_pulse_passes > 4) | |
| tempParm.macro_pulse_passes -= 1; | |
| } | |
| } | |
| else if (tempParm.macro_pulse_duration < 10000) | |
| { | |
| if (delta == 1) | |
| { | |
| if (tempParm.macro_pulse_interval < 3000) | |
| tempParm.macro_pulse_interval += 10; | |
| else | |
| tempParm.macro_pulse_interval = 3010; | |
| } | |
| else if (delta == -1) | |
| { | |
| if (tempParm.macro_pulse_interval > 0) | |
| tempParm.macro_pulse_interval -= 10; | |
| } | |
| } | |
| if (!visualizing()) | |
| { | |
| if (in_main_state(actionMeta)) { | |
| switch_main_screen_focus("#interval_setpoint"); | |
| update_main_screen_values(tempParm, event, actionMeta); | |
| } | |
| else { | |
| switch_editing_screen_focus("#interval_setpoint_editing"); | |
| update_editing_screen_values(tempParm, event, actionMeta); | |
| } | |
| } | |
| }, | |
| update_macro_duration: function(context, event, actionMeta) | |
| { | |
| debugLog("update_macro_duration triggered", debug); | |
| let delta = event.data; | |
| if (tempParm.countdown_enabled) | |
| { | |
| if (delta == 1) | |
| { | |
| if (tempParm.macro_pulse_duration < 90000) | |
| tempParm.macro_pulse_duration += 10000; | |
| } | |
| else | |
| { | |
| if (tempParm.macro_pulse_duration > 20000) | |
| tempParm.macro_pulse_duration -= 10000; | |
| else | |
| { | |
| tempParm.countdown_enabled = false; | |
| tempParm.macro_pulse_duration = 60000; | |
| } | |
| } | |
| } | |
| else | |
| { | |
| if (delta == 1) | |
| { | |
| if (tempParm.macro_pulse_duration < 3000) | |
| tempParm.macro_pulse_duration += 10; | |
| else if (tempParm.macro_pulse_duration < 9000) | |
| tempParm.macro_pulse_duration += 500; | |
| else if (tempParm.macro_pulse_duration == 9000) | |
| tempParm.macro_pulse_duration += 1000; | |
| else if (tempParm.macro_pulse_duration < 60000) | |
| tempParm.macro_pulse_duration += 10000; | |
| else | |
| { | |
| tempParm.countdown_enabled = true; | |
| tempParm.macro_pulse_duration = 20000; | |
| } | |
| } | |
| else | |
| { | |
| if (tempParm.macro_pulse_duration > 10) | |
| { | |
| if (tempParm.macro_pulse_duration <= 3000) | |
| tempParm.macro_pulse_duration -= 10; | |
| else if (tempParm.macro_pulse_duration <= 9000) | |
| tempParm.macro_pulse_duration -= 500; | |
| else if (tempParm.macro_pulse_duration == 10000) | |
| tempParm.macro_pulse_duration -= 1000; | |
| else if (tempParm.macro_pulse_duration <= 60000) | |
| tempParm.macro_pulse_duration -= 10000; | |
| } | |
| } | |
| } | |
| if (!visualizing()) | |
| { | |
| if (in_main_state(actionMeta)) { | |
| switch_main_screen_focus("#duration_setpoint"); | |
| update_main_screen_values(tempParm, event, actionMeta); | |
| } | |
| else { | |
| switch_editing_screen_focus("#duration_setpoint_editing"); | |
| update_editing_screen_values(tempParm, event, actionMeta); | |
| } | |
| } | |
| }, | |
| clear_main_focus: function(context, event, actionMeta) | |
| { | |
| switch_main_screen_focus(); | |
| preset_arr[9] = { ...tempParm }; | |
| upulse_tempParm = { ...tempParm }; | |
| }, | |
| switch_cw_button_editing: function(context, event, actionMeta) | |
| { | |
| tempParm.micro_pulse_enabled = false; | |
| if (!visualizing()) | |
| { | |
| $("#upulse_editing").attr("data-state", "unpressed"); | |
| $("#cw_editing").attr("data-state", "pressed"); | |
| $("#editing_screen_duty_cycle").hide(); | |
| } | |
| }, | |
| switch_cw_button: function(context, event, actionMeta) | |
| { | |
| context.mode = "macro"; | |
| if (!visualizing()) | |
| { | |
| $("#upulse").attr("data-state", "unpressed"); | |
| $("#cw").attr("data-state", "pressed"); | |
| $("#main_screen_duty_cycle").hide(); | |
| } | |
| }, | |
| update_working_vars_entry: function(context, event, actionMeta) | |
| { | |
| update_working_vars_entry(context, event, actionMeta); | |
| }, | |
| update_working_vars_exit: function(context, event, actionMeta) | |
| { | |
| update_working_vars_exit(context, event, actionMeta); | |
| }, | |
| update_main_screen_values: function(context, event, actionMeta) | |
| { | |
| update_main_screen_values(context, event, actionMeta); | |
| }, | |
| // Micro pulse | |
| micro_pulse_defaults: function(context, event, actionMeta) | |
| { | |
| micro_pulse_defaults(context, event, actionMeta); | |
| }, | |
| handle_power_change: function(context, event, actionMeta) | |
| { | |
| //Power is handled in 2 places, preset editing and main | |
| //If in main then change preset_arr[9], otherwise tempParm | |
| let delta = event.data; | |
| if (delta == 1) | |
| { | |
| if (tempParm.power == 0) | |
| tempParm.power = 50; | |
| else if (tempParm.power < 3000) | |
| tempParm.power += 10; | |
| } | |
| else | |
| { | |
| if (tempParm.power == 50) | |
| tempParm.power = 0; | |
| else if (tempParm.power > 0) | |
| tempParm.power -= 10; | |
| } | |
| tempParm.energy = calculateEnergy(tempParm); | |
| if (!visualizing()) | |
| { | |
| if (in_main_state(actionMeta)) { | |
| switch_main_screen_focus("#power_setpoint"); | |
| update_main_screen_values(context, event, actionMeta); | |
| } | |
| else { | |
| switch_editing_screen_focus("#power_setpoint_editing","#power_setpoint_units_editing","#energy_setpoint_editing"); | |
| update_editing_screen_values(context, event, actionMeta); | |
| } | |
| } | |
| }, | |
| update_micro_interval: function(context, event, actionMeta) | |
| { | |
| let delta = event.data; | |
| if (delta == 1) | |
| { | |
| if (upulse_tempParm.micro_pulse_interval.toFixed(2) < 10.0) | |
| { | |
| let d = parseFloat(upulse_tempParm.micro_pulse_interval) + 0.1; | |
| upulse_tempParm.micro_pulse_interval = d; | |
| } | |
| } | |
| else if (upulse_tempParm.micro_pulse_interval > 1) | |
| { | |
| let d = parseFloat(upulse_tempParm.micro_pulse_interval) - 0.1; | |
| upulse_tempParm.micro_pulse_interval = d; | |
| } | |
| calc_micro_duty_cycle(upulse_tempParm); | |
| if (!visualizing()) | |
| { | |
| $("#duty_cycle").text(upulse_tempParm.micro_pulse_duty_cycle.toFixed(1) + "%"); | |
| $("#micro_pulse_interval").text(upulse_tempParm.micro_pulse_interval.toFixed(1)); | |
| $("#micro_pulse_interval").css("background-color", "#f5f593"); | |
| $("#micro_pulse_duration").css("background-color", "white"); | |
| } | |
| debugLog("temp interval=" + upulse_tempParm.micro_pulse_interval, debug); | |
| }, | |
| update_micro_duration: function(context, event, actionMeta) | |
| { | |
| let delta = event.data; | |
| if (delta == 1) | |
| { | |
| if (upulse_tempParm.micro_pulse_duration < 1) | |
| { | |
| let d = parseFloat(upulse_tempParm.micro_pulse_duration) + 0.05; | |
| upulse_tempParm.micro_pulse_duration = d; | |
| } | |
| } | |
| else if (upulse_tempParm.micro_pulse_duration > 0.05) | |
| { | |
| let d = parseFloat(upulse_tempParm.micro_pulse_duration) - 0.05; | |
| upulse_tempParm.micro_pulse_duration = d; | |
| } | |
| calc_micro_duty_cycle(upulse_tempParm); | |
| if (!visualizing()) | |
| { | |
| $("#duty_cycle").text(upulse_tempParm.micro_pulse_duty_cycle.toFixed(1) + "%"); | |
| $("#micro_pulse_duration").text(upulse_tempParm.micro_pulse_duration.toFixed(2)); | |
| $("#micro_pulse_duration").css("background-color", "#f5f593"); | |
| $("#micro_pulse_interval").css("background-color", "white"); | |
| } | |
| debugLog("temp duration=" + upulse_tempParm.micro_pulse_duration, debug); | |
| }, | |
| update_duty_cycle: function(context, event, actionMeta) | |
| { | |
| upulse_tempParm.micro_pulse_duty_cycle = parseFloat(event.data); | |
| debugLog("temp duty=" + JSON.stringify(upulse_tempParm), debug); | |
| if (upulse_tempParm.micro_pulse_duty_cycle == 5) | |
| { | |
| upulse_tempParm.micro_pulse_duration = 0.1; | |
| upulse_tempParm.micro_pulse_interval = 1.9; | |
| } | |
| if (upulse_tempParm.micro_pulse_duty_cycle == 10) | |
| { | |
| upulse_tempParm.micro_pulse_duration = 0.2; | |
| upulse_tempParm.micro_pulse_interval = 1.8; | |
| } | |
| if (upulse_tempParm.micro_pulse_duty_cycle == 15) | |
| { | |
| upulse_tempParm.micro_pulse_duration = 0.3; | |
| upulse_tempParm.micro_pulse_interval = 1.7; | |
| } | |
| if (upulse_tempParm.micro_pulse_duty_cycle == 31.3) | |
| { | |
| upulse_tempParm.micro_pulse_duration = 0.5; | |
| upulse_tempParm.micro_pulse_interval = 1.1; | |
| } | |
| if (!visualizing()) | |
| { | |
| $("#duty_cycle").text(upulse_tempParm.micro_pulse_duty_cycle + "%"); | |
| $("#micro_pulse_duration").text(upulse_tempParm.micro_pulse_duration.toFixed(1)); | |
| $("#micro_pulse_interval").text(upulse_tempParm.micro_pulse_interval.toFixed(1)); | |
| $("#micro_pulse_interval").css("background-color", "white"); | |
| $("#micro_pulse_duration").css("background-color", "white"); | |
| } | |
| }, | |
| show_micro_pulse_screen: function(context, event, actionMeta) | |
| { | |
| if (!visualizing()) | |
| { | |
| $("#micro_pulse_screen").show(); | |
| $("#micro_pulse_interval").css("background-color", "white"); | |
| $("#micro_pulse_duration").css("background-color", "white"); | |
| $("#main_screen_duty_cycle").show(); | |
| } | |
| }, | |
| hide_micro_pulse_screen: function(context, event, actionMeta) | |
| { | |
| var debug = false; | |
| if (!visualizing()) | |
| { | |
| debugLog("Hiding micro_pulse screen", debug); | |
| $("#micro_pulse_screen").hide(); | |
| } | |
| }, | |
| read_micro_pulse_value: function(context, event, actionMeta) | |
| { | |
| upulse_tempParm = { | |
| ...tempParm | |
| }; | |
| if (!visualizing()) | |
| { | |
| $("#duty_cycle").text(upulse_tempParm.micro_pulse_duty_cycle.toFixed(1) + "%"); | |
| $("#micro_pulse_duration").text(upulse_tempParm.micro_pulse_duration.toFixed(1)); | |
| $("#micro_pulse_interval").text(upulse_tempParm.micro_pulse_interval.toFixed(1)); | |
| } | |
| }, | |
| write_micro_pulse_value: function(context, event, actionMeta) | |
| { | |
| upulse_tempParm.micro_pulse_enabled = true; | |
| upulse_tempParm.valid = true; | |
| tempParm = { | |
| ...upulse_tempParm | |
| }; | |
| //if (in_main_state(actionMeta)) { | |
| // preset_arr[9] = { ...upulse_tempParm }; | |
| //} | |
| debugLog("writing micro_pulse_value=" + JSON.stringify(upulse_tempParm), debug); | |
| if (!visualizing()) | |
| { | |
| if (in_main_state(actionMeta)) { | |
| $("#upulse").attr("data-state", "pressed"); | |
| $("#cw").attr("data-state", "unpressed"); | |
| } | |
| else { | |
| $("#upulse_editing").attr("data-state", "pressed"); | |
| $("#cw_editing").attr("data-state", "unpressed"); | |
| } | |
| } | |
| }, | |
| //Volume screen | |
| show_volume_screen: function(context, event, actionMeta) | |
| { | |
| if (!visualizing()) | |
| { | |
| $("#volume_screen").show(); | |
| debugLog("Showing volume screen", debug); | |
| } | |
| }, | |
| hide_volume_screen: function(context, event, actionMeta) | |
| { | |
| if (!visualizing()) | |
| { | |
| debugLog("Hiding volume screen", debug); | |
| $("#volume_screen").hide(); | |
| } | |
| }, | |
| read_volume_value: function(context, event, actionMeta) | |
| { | |
| debugLog("volume_value=" + context.volume_value, debug); | |
| context.volume_value = $("#volume_slider")[0].value = context.volume_value; | |
| context.temp = context.volume_value; | |
| }, | |
| write_volume_value: function(context, event, actionMeta) | |
| { | |
| context.volume_value = $("#volume_slider")[0].value; | |
| debugLog("volume_value=" + context.volume_value, debug); | |
| if (context.volume_value == 1) | |
| { | |
| $("#volume_button").css("background-image", 'url(' + getBaseUrl() + "images/web_gui/main_screen/buttons/volume_control_mute.png)"); | |
| } | |
| else | |
| { | |
| $("#volume_button").css("background-image", 'url(' + getBaseUrl() + "images/web_gui/main_screen/buttons/volume_control.png)"); | |
| } | |
| }, | |
| show_bright_screen: function(context, event, actionMeta) | |
| { | |
| if (!visualizing()) | |
| { | |
| $("#bright_screen").show(); | |
| debugLog("Showing bright screen", debug); | |
| } | |
| }, | |
| hide_bright_screen: function(context, event, actionMeta) | |
| { | |
| if (!visualizing()) | |
| { | |
| debugLog("Hiding bright screen", debug); | |
| $("#bright_screen").hide(); | |
| } | |
| }, | |
| read_bright_value: function(context, event, actionMeta) | |
| { | |
| debugLog("bright_value=" + context.bright_value, debug); | |
| context.bright_value = $("#brightness_slider")[0].value = context.bright_value; | |
| context.temp = context.bright_value; | |
| }, | |
| write_bright_value: function(context, event, actionMeta) | |
| { | |
| context.bright_value = $("#brightness_slider")[0].value; | |
| debugLog("bright_value=" + context.bright_value, debug); | |
| }, | |
| show_screen: function(context, event, actionMeta) | |
| { | |
| let state = actionMeta.state.value.operation_state.standby_state; | |
| if (state == undefined) | |
| state = actionMeta.state.value; | |
| debugLog("show_screen state=" + state, debug); | |
| const screen = getScreenFromState(state); | |
| if (!visualizing()) | |
| { | |
| $(screen).show(); | |
| } | |
| }, | |
| hide_screen: function(context, event) | |
| { | |
| let debug = false; | |
| const state = context.last; //state_history[state_history.length-1].value.standby_state; | |
| debugLog("Hiding " + state,debug); | |
| const screen = getScreenFromState(state); | |
| if (!visualizing()) | |
| { | |
| if (event.type.includes("BRIGHT_CLICKED") || event.type.includes("VOLUME_CLICKED")) | |
| { | |
| //Don't hide for dialog type widgets | |
| } | |
| else | |
| $(screen).hide(); | |
| } | |
| }, | |
| save_state: function(context, event, actionMeta) | |
| { | |
| let debug = false; | |
| try | |
| { | |
| context.last = actionMeta.state.value.operation_state.standby_state; | |
| if (context.last == undefined) | |
| context.last = actionMeta.state.value; | |
| debugLog("Saved state " + context.last, debug); | |
| } | |
| catch (err) | |
| { | |
| debugLog("Caught " + err, debug); | |
| } | |
| }, | |
| increment: (context, event) => | |
| { | |
| debugLog("incrementing " + context.progressBar++, debug); | |
| }, | |
| show: function(context, event) | |
| { | |
| debugLog("show", debug); | |
| $("#myProgress").show(); | |
| }, | |
| update_last: function(context, event) | |
| { | |
| debugLog("last=" + context.last, debug); | |
| }, | |
| back: function(context, event) | |
| { | |
| try | |
| { | |
| state_history.pop(); | |
| const t = state_history[state_history.length - 1].value.standby_state; | |
| debugLog("hist = " + JSON.stringify(t), debug); | |
| const ev = getEventFromState(t); | |
| guiService.send(ev); | |
| } | |
| catch (err) | |
| {} | |
| }, | |
| }, | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment