Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 83 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ tiny4linux_assets = { git = "https://github.com/OpenFoxes/Tiny4Linux-Icons", rev
iced = { version = "0.13.0", features = ["image", "tokio"], optional = true }
iced_font_awesome = { version = "0.3.0", optional = true }
nix = { version = "0.30.0", features = ["ioctl"] }
bon = "3.8.1"
errno = "0.3.14"
hex = "0.4.3"
glob = "0.3.3"
Expand Down
90 changes: 25 additions & 65 deletions src/libs/camera/command02.rs
Original file line number Diff line number Diff line change
@@ -1,68 +1,28 @@
// SPDX-License-Identifier: EUPL-1.2

pub struct Command02 {
pub function_group: Option<[u8; 6]>,
pub sequence_nr: Option<[u8; 2]>,
pub checksum: Option<[u8; 2]>,
pub command: Option<[u8; 6]>,
pub appendix: Option<[u8; 16]>,
}

impl Command02 {
pub fn new() -> Self {
Self {
function_group: None,
sequence_nr: None,
checksum: None,
command: None,
appendix: None,
}
}

pub fn function_group(mut self, function_group: [u8; 6]) -> Self {
self.function_group = Some(function_group);
self
}

pub fn sequence_nr(mut self, sequence_number: [u8; 2]) -> Self {
self.sequence_nr = Some(sequence_number);
self
}

pub fn checksum(mut self, checksum: [u8; 2]) -> Self {
self.checksum = Some(checksum);
self
}

pub fn command(mut self, cmd: [u8; 6]) -> Self {
self.command = Some(cmd);
self
}

pub fn appendix(mut self, app: [u8; 16]) -> Self {
self.appendix = Some(app);
self
}

pub fn build(self) -> [u8; 36] {
const FRAME_ID: [u8; 2] = [0xaa, 0x25];
const SEGMENT_SIZE: [u8; 2] = [0x0c, 0x00];

[
FRAME_ID.as_slice(),
self.sequence_nr
.expect("sequence_nr is required")
.as_slice(),
SEGMENT_SIZE.as_slice(),
self.checksum.expect("checksum is required").as_slice(),
self.function_group
.expect("function_group is required")
.as_slice(),
self.command.expect("command is required").as_slice(),
self.appendix.unwrap_or([0x00; 16]).as_slice(),
]
.concat()
.try_into()
.unwrap()
}
use bon::builder;

#[builder(finish_fn = build)]
pub fn command02(
function_group: [u8; 6],
sequence_nr: [u8; 2],
checksum: [u8; 2],
command: [u8; 6],
appendix: Option<[u8; 16]>,
) -> [u8; 36] {
const FRAME_ID: [u8; 2] = [0xaa, 0x25];
const SEGMENT_SIZE: [u8; 2] = [0x0c, 0x00];

[
FRAME_ID.as_slice(),
sequence_nr.as_slice(),
SEGMENT_SIZE.as_slice(),
checksum.as_slice(),
function_group.as_slice(),
command.as_slice(),
appendix.unwrap_or([0x00; 16]).as_slice(),
]
.concat()
.try_into()
.unwrap()
}
5 changes: 2 additions & 3 deletions src/libs/camera/commands/exposure_mode_type.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: EUPL-1.2

use crate::Command02;
use crate::ExposureMode;
use crate::{ExposureMode, command02};

pub struct ExposureModeTypeCommand;

Expand All @@ -23,7 +22,7 @@ impl ExposureModeTypeCommand {
)
};

Command02::new()
command02()
.function_group(FUNCTION_GROUP_EXPOSURE_MODE_TYPE)
.sequence_nr(sequence_nr)
.checksum(checksum)
Expand Down
4 changes: 2 additions & 2 deletions src/libs/camera/commands/goto_preset_position.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: EUPL-1.2

use crate::Command02;
use crate::command02;
use crate::libs::errors::T4lError;

pub struct GotoPresetPositionCommand;
Expand Down Expand Up @@ -35,7 +35,7 @@ impl GotoPresetPositionCommand {
}
};

Ok(Command02::new()
Ok(command02()
.function_group(FUNCTION_GROUP_PRESETS)
.sequence_nr(sequence_nr)
.checksum(checksum)
Expand Down
5 changes: 2 additions & 3 deletions src/libs/camera/commands/sleep.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
// SPDX-License-Identifier: EUPL-1.2

use crate::Command02;
use crate::SleepMode;
use crate::libs::errors::T4lError;
use crate::{SleepMode, command02};

pub struct SleepCommand;

Expand All @@ -28,7 +27,7 @@ impl SleepCommand {
SleepMode::Unknown => panic!(),
};

Ok(Command02::new()
Ok(command02()
.function_group(FUNCTION_GROUP_SLEEP)
.sequence_nr(sequence_nr)
.checksum(checksum)
Expand Down
5 changes: 2 additions & 3 deletions src/libs/camera/commands/tracking_speed.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
// SPDX-License-Identifier: EUPL-1.2

use crate::Command02;
use crate::TrackingSpeed;
use crate::libs::errors::T4lError;
use crate::{TrackingSpeed, command02};

pub struct TrackingSpeedCommand;

Expand All @@ -29,7 +28,7 @@ impl TrackingSpeedCommand {
),
};

Ok(Command02::new()
Ok(command02()
.function_group(FUNCTION_GROUP_TRACKING_SPEED)
.sequence_nr(sequence_nr)
.checksum(checksum)
Expand Down
2 changes: 1 addition & 1 deletion src/libs/camera/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ mod transport;

pub use camera::Camera;
pub use camera::Tiny2Camera;
pub use command02::Command02;
pub use command02::command02;
pub use commands::*;
pub use enums::*;
pub use status::CameraStatus;