Skip to content

Commit 20f5ff4

Browse files
committed
pbdrv/ev3dev: correctly check whether a motor is able to coast
This check sometimes incorrectly passed because it defaulted to trying to coast motor0. this fixes #96
1 parent 783c5fe commit 20f5ff4

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

lib/pbio/drv/ev3dev_stretch/motor.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,14 @@ typedef struct _motor_file_t {
1818
pbio_iodev_type_id_t id;
1919
bool coasting;
2020
int dir_number;
21-
bool files_open;
2221
FILE *f_encoder_count;
2322
FILE *f_encoder_rate;
2423
FILE *f_duty;
2524
} motor_file_t;
2625

2726
motor_file_t motor_files[] = {
2827
[PORT_TO_IDX(PBDRV_CONFIG_FIRST_MOTOR_PORT) ... PORT_TO_IDX(PBDRV_CONFIG_LAST_MOTOR_PORT)]{
29-
.files_open = false
28+
.dir_number = -1
3029
}
3130
};
3231

@@ -49,11 +48,11 @@ pbio_error_t sysfs_motor_command(pbio_port_t port, const char* command) {
4948
// Close files if they are open
5049
void close_files(pbio_port_t port){
5150
int port_index = PORT_TO_IDX(port);
52-
if (motor_files[port_index].files_open) {
51+
if (motor_files[port_index].dir_number >= 0) {
5352
fclose(motor_files[port_index].f_encoder_count);
5453
fclose(motor_files[port_index].f_encoder_rate);
5554
fclose(motor_files[port_index].f_duty);
56-
motor_files[port_index].files_open = false;
55+
motor_files[port_index].dir_number = -1;
5756
}
5857
}
5958

@@ -119,8 +118,6 @@ pbio_error_t sysfs_motor_init(pbio_port_t port){
119118
motor_files[port_index].f_duty = fopen(filepath, "w");
120119
// Close tacho-motor directory when done
121120
closedir (dp);
122-
// Files are opened
123-
motor_files[port_index].files_open = true;
124121
// Return success
125122
return PBIO_SUCCESS;
126123
}

0 commit comments

Comments
 (0)