diff --git a/src/Log.zig b/src/Log.zig index 1e7b678..76a4f25 100644 --- a/src/Log.zig +++ b/src/Log.zig @@ -12,10 +12,16 @@ duration: f32, /// Items to be logged on every selected axis. config: Config, /// Axes to be logged. -axes: [3]bool, +axes: Axes, /// Command run by the driver while logging. command: Command, +pub const Axes = struct { + axis1: bool, + axis2: bool, + axis3: bool, +}; + pub const Command = union(Kind) { // TODO: Support the remaining commands SHDrv provide: // - Offline commands with applied voltage (V) and applied angle (turn): diff --git a/src/Message.zig b/src/Message.zig index 36e5fa2..1812f69 100644 --- a/src/Message.zig +++ b/src/Message.zig @@ -443,8 +443,8 @@ pub const Request = union(Kind) { // f32 samples, then ETX and BCC. The sample count is truncated // like SHDrv's `(int)(m_Sec * 15000)`. const config_count = @popCount(@as(u32, @bitCast(log.config))); - const axis_count: u32 = - @intCast(std.mem.countScalar(bool, &log.axes, true)); + const axis_names = @typeInfo(Log.Axes).@"struct".field_names; + const axis_count: u32 = axis_names.len; const sample_count: u32 = @trunc(@as(f32, @floatFromInt(Log.FREQUENCY)) * log.duration); const response_size: u32 = @sizeOf(Header) + @@ -468,7 +468,8 @@ pub const Request = union(Kind) { result.profile_acceleration = profile.acceleration; }, } - for (&result.config, log.axes) |*axis_config, is_logged| { + inline for (&result.config, axis_names) |*axis_config, axis_name| { + const is_logged = @field(log.axes, axis_name); const names = @typeInfo(Log.Config).@"struct".field_names; inline for (names) |name| { @field(axis_config.*, name) = AxisConfig.fromBool(