Skip to content

Commit

Permalink
function name update
Browse files Browse the repository at this point in the history
  • Loading branch information
inesmaria08 committed Oct 15, 2024
1 parent 0ceefbf commit 834d6d6
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
11 changes: 6 additions & 5 deletions examples/servo/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,20 @@ int main(void) {
uint16_t angle = 0;
uint16_t index = 0; // the first index available.

if (libtock_read_servo_angle(index, &angle) == RETURNCODE_ENODEVICE) {
if (libtock_servo_read_angle(index, &angle) == RETURNCODE_ENODEVICE) {
printf("\n The index number is bigger than the available servomotors\n");
return -1;
}

// Changes the angle of the servomotor from 0 to 180 degrees (waiting 0.1 ms between every change).
for (int i = 0; i <= 180; i++) {
// `result` stores the returned code received from the driver.
result = libtock_set_servo_angle(index, i);
result = libtock_servo_set_angle(index, i);
if (result == RETURNCODE_SUCCESS) {
libtocksync_alarm_delay_ms(100);
// Verifies if the function successfully returned the current angle.
if (libtock_read_servo_angle(index, &angle) == RETURNCODE_SUCCESS) {
if (libtock_servo_read_angle(index, &angle) == RETURNCODE_SUCCESS) {
printf("\nThe current angle is: %d", angle);
} else {
printf("\n This servo cannot return its angle.\n");
}
} else if (result == RETURNCODE_EINVAL) {
printf("\nThe angle you provided exceeds 360 degrees\n");
Expand All @@ -42,4 +40,7 @@ int main(void) {
return -1;
}
}
if (libtock_servo_read_angle(index, &angle) != RETURNCODE_SUCCESS) {
printf("\n This servo cannot return its angle.\n");
}
}
4 changes: 2 additions & 2 deletions libtock/interface/syscalls/servo_syscalls.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ returncode_t libtock_servo_count(uint16_t* servo_count) {

}

returncode_t libtock_set_servo_angle(uint16_t index, uint16_t angle) {
returncode_t libtock_servo_set_angle(uint16_t index, uint16_t angle) {
syscall_return_t cval = command(DRIVER_NUM_SERVO, 2, index, angle);
return tock_command_return_novalue_to_returncode(cval);
}

returncode_t libtock_read_servo_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`
Expand Down
4 changes: 2 additions & 2 deletions libtock/interface/syscalls/servo_syscalls.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ bool libtock_servo_exists(void);
// Returns the number of available servomotors.
returncode_t libtock_servo_count(uint16_t* servo_count);
// Change the angle.
returncode_t libtock_set_servo_angle(uint16_t index, uint16_t angle);
returncode_t libtock_servo_set_angle(uint16_t index, uint16_t angle);
// Requests the current angle from the servo.
returncode_t libtock_read_servo_angle(uint16_t index, uint16_t* angle);
returncode_t libtock_servo_read_angle(uint16_t index, uint16_t* angle);

#ifdef __cplusplus
}
Expand Down

0 comments on commit 834d6d6

Please sign in to comment.