start writing control and config functionality

In theory, this will poll the feedback lines, but in practice, it
probably crashes or catches on fire or something.
This commit is contained in:
2024-07-01 23:55:56 -07:00
parent be819363b9
commit c8bec6a7c5
5 changed files with 669 additions and 24 deletions

View File

@@ -1,25 +1,38 @@
const std = @import("std");
const ljack = @import("./ljacklm.zig");
const Config = @import("./Config.zig");
const lj = @import("./labjack.zig");
const RotCtl = @import("./RotCtl.zig");
pub fn main() !void {
const ver = ljack.getDriverVersion();
const log = std.log.scoped(.main);
pub fn main() !u8 {
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
defer _ = gpa.deinit();
const allocator = gpa.allocator();
blk: {
const conf_file = std.fs.cwd().openFile("yaes.json", .{}) catch {
log.warn("Could not load config file yaes.json. Using default config.", .{});
Config.loadDefault(allocator);
break :blk;
};
defer conf_file.close();
Config.load(allocator, conf_file.reader()) catch {
log.err("Could not parse config file yaes.json. Good luck figuring out why.", .{});
return 1;
};
}
defer Config.destroy(allocator);
const ver = lj.getDriverVersion();
std.debug.print("Driver version: {d}\n", .{ver});
const device = ljack.Labjack.autodetect();
RotCtl.run(allocator) catch |err| {
log.err("rotator controller ceased unexpectedly! {s}", .{@errorName(err)});
return 1;
};
const in = try device.analogReadOne(.{ .channel = .diff_01, .gain = 2 });
std.debug.print("Read voltage: {d}. Overvolt: {}\n", .{ in.voltage, in.over_voltage });
try device.digitalWriteOne(.{ .channel = .{ .io = 0 }, .level = true });
const sample = try device.readAnalogWriteDigital(
2,
.{ .{ .channel = .diff_01, .gain = 2 }, .{ .channel = .diff_23, .gain = 2 } },
.{false} ** 4,
true,
);
for (sample, 0..) |input, idx| {
std.debug.print(" channel {d}: {d} V\n", .{ idx, input.voltage });
}
return 0;
}