labjack: use symbolic gain values
This reads better in the config file.
This commit is contained in:
parent
0e88022a8d
commit
7105775426
@ -48,8 +48,8 @@ labjack: LabjackConfig = .{
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
controller: ControllerConfig = .{
|
controller: ControllerConfig = .{
|
||||||
.azimuth_input = .{ .channel = .diff_01, .gain_index = 2 },
|
.azimuth_input = .{ .channel = .diff_01, .range = .@"5 V" },
|
||||||
.elevation_input = .{ .channel = .diff_23, .gain_index = 2 },
|
.elevation_input = .{ .channel = .diff_23, .range = .@"5 V" },
|
||||||
.azimuth_outputs = .{ .increase = .{ .io = 0 }, .decrease = .{ .io = 1 } },
|
.azimuth_outputs = .{ .increase = .{ .io = 0 }, .decrease = .{ .io = 1 } },
|
||||||
.elevation_outputs = .{ .increase = .{ .io = 2 }, .decrease = .{ .io = 3 } },
|
.elevation_outputs = .{ .increase = .{ .io = 2 }, .decrease = .{ .io = 3 } },
|
||||||
.loop_interval_ns = 50_000_000,
|
.loop_interval_ns = 50_000_000,
|
||||||
|
@ -50,7 +50,7 @@ pub const Labjack = struct {
|
|||||||
&id,
|
&id,
|
||||||
@intFromBool(self.demo),
|
@intFromBool(self.demo),
|
||||||
input.channelNumber(),
|
input.channelNumber(),
|
||||||
input.gain_index,
|
input.gainIndex(),
|
||||||
&over_v,
|
&over_v,
|
||||||
&res.voltage,
|
&res.voltage,
|
||||||
);
|
);
|
||||||
@ -93,7 +93,7 @@ pub const Labjack = struct {
|
|||||||
var gains: [incount]c_long = undefined;
|
var gains: [incount]c_long = undefined;
|
||||||
for (inputs, &in_channels, &gains) |from, *inc, *gain| {
|
for (inputs, &in_channels, &gains) |from, *inc, *gain| {
|
||||||
inc.* = from.channelNumber();
|
inc.* = from.channelNumber();
|
||||||
gain.* = from.gain_index;
|
gain.* = from.gainIndex();
|
||||||
}
|
}
|
||||||
var v_out: [4]f32 = .{0} ** 4;
|
var v_out: [4]f32 = .{0} ** 4;
|
||||||
var over_v: c_long = 0;
|
var over_v: c_long = 0;
|
||||||
@ -133,11 +133,15 @@ pub const Labjack = struct {
|
|||||||
|
|
||||||
pub const AnalogInput = struct {
|
pub const AnalogInput = struct {
|
||||||
channel: AnalogInputChannel,
|
channel: AnalogInputChannel,
|
||||||
gain_index: GainIndex = 0,
|
range: InputRange = .@"20 V",
|
||||||
|
|
||||||
pub fn channelNumber(self: AnalogInput) u4 {
|
pub fn channelNumber(self: AnalogInput) u4 {
|
||||||
return @intFromEnum(self.channel);
|
return @intFromEnum(self.channel);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn gainIndex(self: AnalogInput) GainIndex {
|
||||||
|
return @intFromEnum(self.range);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const AnalogReadResult = struct {
|
pub const AnalogReadResult = struct {
|
||||||
@ -207,6 +211,17 @@ pub const DigitalOutputChannel = union(enum) {
|
|||||||
// 7 => G=20 ±1 volt
|
// 7 => G=20 ±1 volt
|
||||||
pub const GainIndex = u3;
|
pub const GainIndex = u3;
|
||||||
|
|
||||||
|
pub const InputRange = enum(GainIndex) {
|
||||||
|
@"20 V" = 0,
|
||||||
|
@"10 V" = 1,
|
||||||
|
@"5 V" = 2,
|
||||||
|
@"4 V" = 3,
|
||||||
|
@"2.5 V" = 4,
|
||||||
|
@"2 V" = 5,
|
||||||
|
@"1.25 V" = 6,
|
||||||
|
@"1 V" = 7,
|
||||||
|
};
|
||||||
|
|
||||||
pub const PackedOutput = packed struct(u4) {
|
pub const PackedOutput = packed struct(u4) {
|
||||||
io0: bool,
|
io0: bool,
|
||||||
io1: bool,
|
io1: bool,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user