From 9b21a971fef408445530c11e7f7a808334c1103d Mon Sep 17 00:00:00 2001 From: Mikayla Fischler Date: Wed, 20 Jul 2022 13:28:58 -0400 Subject: [PATCH] #74 close supervisor connection on exit, start of touch event handling --- coordinator/coordinator.lua | 12 +++++++++++- coordinator/renderer.lua | 17 ++++++++++++++++- coordinator/startup.lua | 13 ++++++++++--- 3 files changed, 37 insertions(+), 5 deletions(-) diff --git a/coordinator/coordinator.lua b/coordinator/coordinator.lua index 9a72cdb..5972bfc 100644 --- a/coordinator/coordinator.lua +++ b/coordinator/coordinator.lua @@ -44,7 +44,9 @@ function coordinator.configure_monitors(num_units) ---@class monitors_struct local monitors = { primary = nil, - unit_displays = {} + primary_name = "", + unit_displays = {}, + unit_name_map = {} } local monitors_avail = ppm.get_monitor_list() @@ -89,6 +91,7 @@ function coordinator.configure_monitors(num_units) util.filter_table(names, function (x) return x ~= iface_primary_display end) monitors.primary = ppm.get_periph(iface_primary_display) + monitors.primary_name = iface_primary_display ------------------- -- UNIT DISPLAYS -- @@ -139,6 +142,7 @@ function coordinator.configure_monitors(num_units) for i = 1, #unit_displays do monitors.unit_displays[i] = ppm.get_periph(unit_displays[i]) + monitors.unit_name_map[i] = unit_displays[i] end return true, monitors @@ -251,6 +255,12 @@ function coordinator.comms(version, modem, sv_port, sv_listen, api_listen, sv_wa _open_channels() end + -- close the connection to the server + function public.close() + sv_watchdog.cancel() + _send_sv(PROTOCOLS.SCADA_MGMT, SCADA_MGMT_TYPES.CLOSE, {}) + end + -- attempt to connect to the subervisor ---@param timeout_s number timeout in seconds ---@param tick_dmesg_waiting function callback to tick dmesg waiting diff --git a/coordinator/renderer.lua b/coordinator/renderer.lua index 59fafcf..2e49026 100644 --- a/coordinator/renderer.lua +++ b/coordinator/renderer.lua @@ -1,4 +1,4 @@ -local log = require("scada-common.log") +local log = require("scada-common.log") local main_view = require("coordinator.ui.layout.main_view") local unit_view = require("coordinator.ui.layout.unit_view") @@ -99,4 +99,19 @@ function renderer.close_ui(recolor) engine.dmesg_window.redraw() end +-- handle a touch event +---@param event monitor_touch +function renderer.handle_touch(event) + if event.monitor == engine.monitors.primary_name then + ui.main_layout.handle_touch(event) + else + for id, monitor in pairs(engine.monitors.unit_name_map) do + if event.monitor == monitor then + local layout = ui.unit_layouts[id] ---@type graphics_element + layout.handle_touch(event) + end + end + end +end + return renderer diff --git a/coordinator/startup.lua b/coordinator/startup.lua index d0320c7..b6728f7 100644 --- a/coordinator/startup.lua +++ b/coordinator/startup.lua @@ -8,12 +8,14 @@ local log = require("scada-common.log") local ppm = require("scada-common.ppm") local util = require("scada-common.util") +local core = require("graphics.core") + local apisessions = require("coordinator.apisessions") local config = require("coordinator.config") local coordinator = require("coordinator.coordinator") local renderer = require("coordinator.renderer") -local COORDINATOR_VERSION = "alpha-v0.3.5" +local COORDINATOR_VERSION = "alpha-v0.3.6" local print = util.print local println = util.println @@ -211,12 +213,17 @@ while ui_ok do -- got a packet local packet = coord_comms.parse_packet(param1, param2, param3, param4, param5) coord_comms.handle_packet(packet) + elseif event == "monitor_touch" then + -- handle a monitor touch event + renderer.handle_touch(core.events.touch(param1, param2, param3)) end -- check for termination request if event == "terminate" or ppm.should_terminate() then - log_comms("terminate requested, closing sessions...") - println_ts("closing sessions...") + log_comms("terminate requested, closing supervisor connection") + coord_comms.close() + log_comms("closing api sessions...") + println_ts("closing api sessions...") apisessions.close_all() log_comms("api sessions closed") break