From eb7ad4ef9e2692bca5efa506495a1f1081bc6a89 Mon Sep 17 00:00:00 2001 From: torque Date: Thu, 11 Jul 2024 22:01:16 -0700 Subject: [PATCH] main: hook up calibration stubs I guess I will be finishing this later. --- src/YaesuController.zig | 30 ++++++++++++++++++++++++++++++ src/main.zig | 22 +++++++++++++++++++++- 2 files changed, 51 insertions(+), 1 deletion(-) diff --git a/src/YaesuController.zig b/src/YaesuController.zig index ef471db..6a3b090 100644 --- a/src/YaesuController.zig +++ b/src/YaesuController.zig @@ -17,6 +17,24 @@ pub const AzEl = struct { elevation: f64, }; +pub const CalibrationRoutine = enum { + feedback, + orientation, +}; + +pub fn calibrate(allocator: std.mem.Allocator, routine: CalibrationRoutine) !void { + const controller = try YaesuController.init(allocator); + defer { + controller.quit(); + controller.control_thread.join(); + } + + switch (routine) { + .feedback => try controller.calibrate_feedback(), + .orientation => try controller.calibrate_orientation(), + } +} + pub fn init(allocator: std.mem.Allocator) !YaesuController { const lock = try allocator.create(std.Thread.Mutex); errdefer allocator.destroy(lock); @@ -116,6 +134,18 @@ pub fn startPark(self: YaesuController) void { self.setTarget(config.controller.parking_posture) catch unreachable; } +fn calibrate_feedback(self: YaesuController) !void { + _ = self; + log.err("this isn't implemented yet, sorry.", .{}); + return error.NotImplemented; +} + +fn calibrate_orientation(self: YaesuController) !void { + _ = self; + log.err("this isn't implemented yet, sorry.", .{}); + return error.NotImplemented; +} + fn runController(controller: *Controller) void { controller.run() catch { log.err( diff --git a/src/main.zig b/src/main.zig index 0abfca4..8ab4eda 100644 --- a/src/main.zig +++ b/src/main.zig @@ -4,6 +4,7 @@ const builtin = @import("builtin"); const Config = @import("./Config.zig"); const lj = @import("./labjack.zig"); const RotCtl = @import("./RotCtl.zig"); +const YaesuController = @import("./YaesuController.zig"); const udev = @import("udev_rules"); @@ -69,7 +70,26 @@ pub fn main() !u8 { log.err("rotator controller ceased unexpectedly! {s}", .{@errorName(err)}); return 1; }; + } else if (std.mem.eql(u8, args[1], commands.calibrate)) { + if (args.len < 3 or args.len > 4) { + printHelp(exename, .calibrate); + return 1; + } + loadConfigOrDefault(allocator, if (args.len == 4) args[3] else null) catch + return 1; + defer Config.deinit(); + + const routine = std.meta.stringToEnum(YaesuController.CalibrationRoutine, args[2]) orelse { + log.err("{s} is not a known calibration routine.", .{args[2]}); + printHelp(exename, .calibrate); + return 1; + }; + + YaesuController.calibrate(allocator, routine) catch |err| { + log.err("Calibration failed: {s}", .{@errorName(err)}); + return 1; + }; } else if (std.mem.eql(u8, args[1], commands.help)) { if (args.len != 3) { printHelp(exename, .help); @@ -271,7 +291,7 @@ const command_help = .{ \\ Perform a calibration routine and write an updated configuration with its results. \\ \\Arguments: - \\ routine Must be one of `feedback` or `orientation`. The different calibration routines have + \\ routine Must be either `feedback` or `orientation`. The different calibration routines have \\ different requirements. `orientation` calibration is a sun-pointing-based routine and \\ should be performed after `feedback` calibration is complete. \\ config_file [Optional] the path of a config file to load. This file will be updated with the