Skip to content

Commit

Permalink
small changes
Browse files Browse the repository at this point in the history
  • Loading branch information
inesmaria08 committed Nov 20, 2024
1 parent b60f9d2 commit f79bf0a
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 13 deletions.
7 changes: 2 additions & 5 deletions examples/servo/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ int main(void) {
returncode_t result = RETURNCODE_EOFF;
uint16_t servo_count = 0;
libtock_servo_count(&servo_count);
printf("The number of available servomotors is: %d", servo_count);
printf("The number of available servomotors is: %d\n", servo_count);
uint16_t angle = 0;
uint16_t index = 0; // the first index available.

Expand All @@ -30,11 +30,8 @@ int main(void) {
libtocksync_alarm_delay_ms(100);
// Verifies if the function successfully returned the current angle.
if (libtock_servo_read_angle(index, &angle) == RETURNCODE_SUCCESS) {
printf("\nThe current angle is: %d", angle);
printf("Requested angle %d. Actual current angle is: %d\n", i, angle);
}
} else if (result == RETURNCODE_EINVAL) {
printf("\nThe angle you provided exceeds 360 degrees\n");
return -1;
} else if (result == RETURNCODE_FAIL) {
printf("\nAngle %d exceeds the servo's limit angle.\n", i);
}
Expand Down
10 changes: 3 additions & 7 deletions libtock/interface/syscalls/servo_syscalls.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@ bool libtock_servo_exists(void) {
return driver_exists(DRIVER_NUM_SERVO);
}

returncode_t libtock_servo_count(uint16_t* servo_count) {
returncode_t libtock_servo_count(uint32_t* servo_count) {
uint32_t value = 0;
syscall_return_t r = command(DRIVER_NUM_SERVO, 1, 0, 0);
// Converts the returned value stored in `r`
// and assigns it to `ret`.
returncode_t ret = tock_command_return_u32_to_returncode(r, &value);
returncode_t ret = tock_command_return_u32_to_returncode(r, &value);
*servo_count = (uint16_t)value;
return ret;

Expand All @@ -24,9 +22,7 @@ returncode_t libtock_servo_set_angle(uint16_t index, uint16_t angle) {
returncode_t libtock_servo_read_angle(uint16_t index, uint16_t* angle) {
uint32_t value = 0;
syscall_return_t r = command(DRIVER_NUM_SERVO, 3, index, 0);
// Converts the value returned by the servo, stored in `r`
// and assigns it to `ret`.
returncode_t ret = tock_command_return_u32_to_returncode(r, &value);
returncode_t ret = tock_command_return_u32_to_returncode(r, &value);
*angle = (uint16_t)value;
return ret;
}
2 changes: 1 addition & 1 deletion libtock/interface/syscalls/servo_syscalls.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ extern "C" {
// Check if the servo system call driver is available on this board.
bool libtock_servo_exists(void);
// Returns the number of available servomotors.
returncode_t libtock_servo_count(uint16_t* servo_count);
returncode_t libtock_servo_count(uint32_t* servo_count);
// Change the angle.
returncode_t libtock_servo_set_angle(uint16_t index, uint16_t angle);
// Requests the current angle from the servo.
Expand Down

0 comments on commit f79bf0a

Please sign in to comment.