#74 close supervisor connection on exit, start of touch event handling

This commit is contained in:
Mikayla Fischler 2022-07-20 13:28:58 -04:00
parent 1afafba501
commit 9b21a971fe
3 changed files with 37 additions and 5 deletions

View File

@ -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

View File

@ -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

View File

@ -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