Skip to content

Commit

Permalink
comments update
Browse files Browse the repository at this point in the history
  • Loading branch information
inesmaria08 committed Oct 15, 2024
1 parent 1f37cbb commit 9a9fce7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
24 changes: 15 additions & 9 deletions apis/interface/servo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,34 +15,40 @@ impl<S: Syscalls> Servo<S> {
}
}
/// Returns the number of the servomotors available.
pub fn servo_count() -> Result<u32, ErrorCode> {
pub fn count() -> Result<u32, ErrorCode> {
S::command(DRIVER_NUM, SERVO_COUNT, 0, 0).to_result()
}

/// Changes the angle of the servo.
/// Return values:
///
/// # Arguments
/// - `angle` - the variable that receives the angle
/// (in degrees from 0 to 180) from the servo driver.
/// - `index` - the variable that receives the index of the servomotor.
///
/// # Return values:
/// - `Ok(())`: The attempt at changing the angle was successful.
///
/// # Errors:
/// - `FAIL`: Cannot change the angle.
/// - `INVAL`: The value exceeds u16, indicating it's incorrect
/// since servomotors can only have a maximum of 360 degrees.
/// - `NODEVICE`: The index exceeds the number of servomotors provided.
/// # Arguments
/// - `angle` - the variable that receives the angle
/// (in degrees from 0 to 180) from the servo driver.
/// - `index` - the variable that receives the index of the servomotor.
pub fn set_angle(index: u32, angle: u32) -> Result<(), ErrorCode> {
S::command(DRIVER_NUM, SET_ANGLE, index, angle).to_result()
}

/// Returns the angle of the servo.
/// Return values:
///
/// # Arguments
/// - `index` - the variable that receives the index of the servomotor.
///
/// # Return values:
/// - `angle`: The value, in angles from 0 to 360, of the servo.
///
/// # Errors:
/// - `NOSUPPORT`: The servo cannot return its angle.
/// - `NODEVICE`: The index exceeds the number of servomotors provided.
/// # Arguments
/// - `index` - the variable that receives the index of the servomotor.
pub fn get_angle(index: u32) -> Result<u32, ErrorCode> {
S::command(DRIVER_NUM, GET_ANGLE, index, 0).to_result()
}
Expand Down
4 changes: 2 additions & 2 deletions apis/interface/servo/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ fn exists() {
assert_eq!(Servo::exists(), Ok(()));
}
#[test]
fn servo_count() {
fn count() {
let kernel = fake::Kernel::new();
let driver = fake::Servo::<2>::new();
kernel.add_driver(&driver);
assert_eq!(Servo::servo_count(), Ok(2));
assert_eq!(Servo::count(), Ok(2));
}
#[test]
fn set_angle() {
Expand Down

0 comments on commit 9a9fce7

Please sign in to comment.