Skip to content

Commit 28ff21d

Browse files
committed
small changes
1 parent 9e188fc commit 28ff21d

File tree

3 files changed

+6
-13
lines changed

3 files changed

+6
-13
lines changed

examples/servo/main.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ int main(void) {
1313
returncode_t result = RETURNCODE_EOFF;
1414
uint16_t servo_count = 0;
1515
libtock_servo_count(&servo_count);
16-
printf("The number of available servomotors is: %d", servo_count);
16+
printf("The number of available servomotors is: %d\n", servo_count);
1717
uint16_t angle = 0;
1818
uint16_t index = 0; // the first index available.
1919

@@ -30,11 +30,8 @@ int main(void) {
3030
libtocksync_alarm_delay_ms(100);
3131
// Verifies if the function successfully returned the current angle.
3232
if (libtock_servo_read_angle(index, &angle) == RETURNCODE_SUCCESS) {
33-
printf("\nThe current angle is: %d", angle);
33+
printf("Requested angle %d. Actual current angle is: %d\n", i, angle);
3434
}
35-
} else if (result == RETURNCODE_EINVAL) {
36-
printf("\nThe angle you provided exceeds 360 degrees\n");
37-
return -1;
3835
} else if (result == RETURNCODE_FAIL) {
3936
printf("\nAngle %d exceeds the servo's limit angle.\n", i);
4037
}

libtock/interface/syscalls/servo_syscalls.c

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,10 @@ bool libtock_servo_exists(void) {
55
return driver_exists(DRIVER_NUM_SERVO);
66
}
77

8-
returncode_t libtock_servo_count(uint16_t* servo_count) {
8+
returncode_t libtock_servo_count(uint32_t* servo_count) {
99
uint32_t value = 0;
1010
syscall_return_t r = command(DRIVER_NUM_SERVO, 1, 0, 0);
11-
// Converts the returned value stored in `r`
12-
// and assigns it to `ret`.
13-
returncode_t ret = tock_command_return_u32_to_returncode(r, &value);
11+
returncode_t ret = tock_command_return_u32_to_returncode(r, &value);
1412
*servo_count = (uint16_t)value;
1513
return ret;
1614

@@ -24,9 +22,7 @@ returncode_t libtock_servo_set_angle(uint16_t index, uint16_t angle) {
2422
returncode_t libtock_servo_read_angle(uint16_t index, uint16_t* angle) {
2523
uint32_t value = 0;
2624
syscall_return_t r = command(DRIVER_NUM_SERVO, 3, index, 0);
27-
// Converts the value returned by the servo, stored in `r`
28-
// and assigns it to `ret`.
29-
returncode_t ret = tock_command_return_u32_to_returncode(r, &value);
25+
returncode_t ret = tock_command_return_u32_to_returncode(r, &value);
3026
*angle = (uint16_t)value;
3127
return ret;
3228
}

libtock/interface/syscalls/servo_syscalls.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ extern "C" {
1111
// Check if the servo system call driver is available on this board.
1212
bool libtock_servo_exists(void);
1313
// Returns the number of available servomotors.
14-
returncode_t libtock_servo_count(uint16_t* servo_count);
14+
returncode_t libtock_servo_count(uint32_t* servo_count);
1515
// Change the angle.
1616
returncode_t libtock_servo_set_angle(uint16_t index, uint16_t angle);
1717
// Requests the current angle from the servo.

0 commit comments

Comments
 (0)