biscuit

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

commit 360c381b33722c4f3ac182c9bdea7f7a0887e54e
parent e5fdab48521822c7ce6424b2c4399ecb5f162a51
Author: Daniel Barlow <dan@telent.net>
Date:   Tue, 17 Jun 2025 21:39:12 +0100

move top-level forms into a main function

this is to prepare for making this a module

Diffstat:
Mpkgs/maps/main.fnl | 81+++++++++++++++++++++++++++++++++++++++----------------------------------------
1 file changed, 40 insertions(+), 41 deletions(-)

diff --git a/pkgs/maps/main.fnl b/pkgs/maps/main.fnl @@ -328,8 +328,6 @@ label.readout { (if (< (math.abs (- from to)) 3) to (+ from (* 0.3 (- to from))))) - - (fn update-app-state [new-vals] (let [old-state (merge {} app-state) old-bounds @@ -445,14 +443,6 @@ label.readout { })))) -(local socket-path (or (. arg 1) "/var/run/gnss-share.sock")) - -(local gnss-socket - (let [addr (Gio.UnixSocketAddress { - :path socket-path - })] - (: (Gio.SocketClient) :connect addr nil))) - (fn read-gnss [socket] (each [l #(socket:read "l")] ; (print "gnss" l) @@ -475,26 +465,6 @@ label.readout { ))) true) -(let [sock (gnss-socket:get_socket) - fd (sock:get_fd) - events [ GLib.IOCondition.IN GLib.IOCondition.HUP] - channel (GLib.IOChannel.unix_new fd) - handle (fdopen fd :r)] - (GLib.io_add_watch channel 0 events #(read-gnss handle))) - - -(GLib.timeout_add - GLib.PRIORITY_DEFAULT - 100 ; ms - (fn [] - ;; run cqueues scheduler - (cq:step 0) - ;; for smoother rotation when course changes, repaint more often than - ;; once per gnss message - (update-app-state {}) - true) - nil nil) - (fn collect-profile [] (GLib.timeout_add GLib.PRIORITY_DEFAULT @@ -503,16 +473,45 @@ label.readout { (print "profiling for 60 seconds") (profile.start 0)) +(fn watch-gnss-socket [socket-path] + (let [gnss-socket + (let [addr (Gio.UnixSocketAddress { + :path socket-path + })] + (: (Gio.SocketClient) :connect addr nil)) + sock (gnss-socket:get_socket) + fd (sock:get_fd) + events [ GLib.IOCondition.IN GLib.IOCondition.HUP] + channel (GLib.IOChannel.unix_new fd) + handle (fdopen fd :r)] + (GLib.io_add_watch channel 0 events #(read-gnss handle)))) + +(fn run [gnss-socket] + (watch-gnss-socket (or gnss-socket "/var/run/gnss-share.sock")) + + (GLib.timeout_add + GLib.PRIORITY_DEFAULT + 100 ; ms + (fn [] + ;; run cqueues scheduler + (cq:step 0) + ;; for smoother rotation when course changes, repaint more often than + ;; once per gnss message + (update-app-state {}) + true) + nil nil) + + (window:add + (doto (Gtk.Overlay {}) + (: :add (osm-widget)) + (: :add_overlay (readouts)) + (: :add_overlay (arrow)) + (: :add_overlay (rose)) + )) -(window:add - (doto (Gtk.Overlay {}) - (: :add (osm-widget)) - (: :add_overlay (readouts)) - (: :add_overlay (arrow)) - (: :add_overlay (rose)) - )) + (window:show_all) + (styles) + (when (os.getenv "MAP_PROFILE") (collect-profile)) + (Gtk:main)) -(window:show_all) -(styles) -(when (os.getenv "MAP_PROFILE") (collect-profile)) -(Gtk:main) +(run (table.unpack arg))