diff --git a/main.lua b/main.lua index 8a063d4..a658695 100644 --- a/main.lua +++ b/main.lua @@ -1,8 +1,13 @@ -- main.lua - Entry point for ACTelemetry CSP Lua app -- CSP calls script.update(dt) every frame; we delegate to the telemetry module. +-- CSP calls script.windowMain(dt) to draw the app window. local telemetry = require("src.telemetry") function script.update(dt) telemetry.update(dt) end + +function script.windowMain(dt) + ui.text("AC Telemetry ●") +end diff --git a/manifest.ini b/manifest.ini index bfbc31f..679f955 100644 --- a/manifest.ini +++ b/manifest.ini @@ -6,6 +6,18 @@ Name = ACTelemetry Author = jan Version = 1.0.0 Description = Sends car telemetry data as JSON over UDP for external dashboards and analysis tools. +REQUIRED_VERSION = 0 -[SCRIPT] -Script = main.lua +[CORE] +LAZY = NONE + +[WINDOW_...] +ID = main +NAME = AC Telemetry +ICON = icon.png +FUNCTION_MAIN = windowMain +FLAGS = NO_SCROLLBAR,NO_SCROLL_WITH_MOUSE,NO_BACKGROUND,NO_TITLE_BAR,FADING,FLOATING_TITLE_BAR +SIZE = 160, 30 +MIN_SIZE = 160, 30 +PADDING = 0 +VISIBLE = 1 diff --git a/src/telemetry.lua b/src/telemetry.lua index 2056e74..ff986dd 100644 --- a/src/telemetry.lua +++ b/src/telemetry.lua @@ -6,13 +6,32 @@ local json = require("src.json") local telemetry = {} -local socket = require("socket.udp") -local udp = socket() +local ac_available = type(ac) == "table" and type(ac.getCarState) == "function" + +if ac_available then + ac.log("[ACTelemetry] Before require('socket')") +else + print("[ACTelemetry] Before require('socket')") +end + +local socket = require("socket") + +if ac_available then + ac.log("[ACTelemetry] require('socket') succeeded, type = " .. type(socket)) +else + print("[ACTelemetry] require('socket') succeeded, type = " .. type(socket)) +end + +local udp = socket.udp() + +if ac_available then + ac.log("[ACTelemetry] socket.udp() succeeded, type = " .. type(udp)) +else + print("[ACTelemetry] socket.udp() succeeded, type = " .. type(udp)) +end local last_send_time = 0 -local ac_available = type(ac) == "table" and type(ac.getCarState) == "function" - local buf_g_forces = { x = 0, y = 0, z = 0 } local buf_wheel_slip = { 0, 0, 0, 0 } local buf_suspension_travel = { 0, 0, 0, 0 }