Skip to content

Commit

Permalink
Use new stream.
Browse files Browse the repository at this point in the history
  • Loading branch information
PerMalmberg committed Jul 25, 2023
1 parent caab4b8 commit d61931f
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 33 deletions.
5 changes: 3 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ PWD=$(shell pwd)
LUA_PATH := ./src/?.lua
LUA_PATH := $(LUA_PATH);$(PWD)/external/du-libs/src/?.lua
LUA_PATH := $(LUA_PATH);$(PWD)/external/du-render/src/?.lua
LUA_PATH := $(LUA_PATH);$(PWD)/external/du-render/external/du-stream/src/?.lua
LUA_PATH := $(LUA_PATH);$(PWD)/external/du-render/external/du-stream/external/du-serializer/?.lua
LUA_PATH := $(LUA_PATH);$(PWD)/external/SmartTemplateLibrary/src/?.lua

LUA_PATH_TEST := $(LUA_PATH);$(PWD)/external/du-libs/src/builtin/du_provided/?.lua
LUA_PATH_TEST := $(LUA_PATH_TEST);$(PWD)/external/du-lua-examples/api-mockup/?.lua
LUA_PATH_TEST := $(LUA_PATH_TEST);$(PWD)/external/du-libs/external/du-unit-testing/src/?.lua
LUA_PATH_TEST := $(LUA_PATH_TEST);$(PWD)/external/du-libs/external/du-unit-testing/src/mocks/?.lua
LUA_PATH_TEST := $(LUA_PATH_TEST);$(PWD)/external/du-libs/external/du-unit-testing/external/du-luac/lua/?.lua
Expand All @@ -35,7 +36,7 @@ update_version:
@./update_version_info.sh

test: clean
@LUA_PATH="$(LUA_PATH_TEST)" busted -t "flight" .
@LUA_PATH="$(LUA_PATH_TEST)" busted -t "flight" . --exclude-pattern="serializer_spec.lua" --exclude-pattern="Stream_spec.lua"
@luacov
@$(CLEAN_COV)

Expand Down
2 changes: 1 addition & 1 deletion external/du-libs
63 changes: 34 additions & 29 deletions src/controller/ScreenController.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ local commandLine = require("commandline/CommandLine").Instance()
local pub = require("util/PubSub").Instance()
local layout = require("screen/layout_out")
local Stream = require("Stream")
local ScreenDevice = require("device/ScreenDevice")
local calc = require("util/Calc")
local pagination = require("util/Pagination")
local distanceFormat = require("util/DistanceFormat")
Expand Down Expand Up @@ -55,7 +56,7 @@ function ScreenController.New(flightCore, settings)
editPointPage = 1
end)

function s.dataReceived(data)
function s.OnData(data)
-- Publish data to system
if data == nil then return end
local command = data["mouse_click"]
Expand All @@ -75,6 +76,37 @@ function ScreenController.New(flightCore, settings)
end
end

---@param isTimedOut boolean
---@param stream Stream
function s.OnTimeout(isTimedOut, stream)
if isTimedOut then
layoutSent = false
elseif not layoutSent then
stream.Write({ screen_layout = layout })

local floorRoute = settings.String("showFloor")
local floorActivated = false

if floorRoute ~= "-" then
floorActivated = s.ActivateFloorMode(floorRoute)
if not floorActivated then
log.Error("Could not activate floor mode")
end
end

if not floorActivated then
stream.Write({ activate_page = "status,routeSelection" })
end

s.sendRoutes()
layoutSent = true
end
end

function s.RegisterStream(stream)

end

---@param cmd string
function s.runRouteEditorCommand(cmd)
if cmd == "previous-route" then
Expand Down Expand Up @@ -264,33 +296,6 @@ function ScreenController.New(flightCore, settings)
return r ~= nil
end

---@param isTimedOut boolean
---@param stream Stream
local function onTimeout(isTimedOut, stream)
if isTimedOut then
layoutSent = false
elseif not layoutSent then
stream.Write({ screen_layout = layout })

local floorRoute = settings.String("showFloor")
local floorActivated = false

if floorRoute ~= "-" then
floorActivated = s.ActivateFloorMode(floorRoute)
if not floorActivated then
log.Error("Could not activate floor mode")
end
end

if not floorActivated then
stream.Write({ activate_page = "status,routeSelection" })
end

s.sendRoutes()
layoutSent = true
end
end

local function screenTask()
local screen = library.getLinkByClass("ScreenUnit")

Expand Down Expand Up @@ -351,7 +356,7 @@ function ScreenController.New(flightCore, settings)
end
end)

stream = Stream.New(screen, s.dataReceived, 1, onTimeout)
stream = Stream.New(ScreenDevice.New(screen), s, 1)

while screen do
screen.activate()
Expand Down

0 comments on commit d61931f

Please sign in to comment.