| 278 | } |
| 279 | |
| 280 | int GoPiGo3::get_motor_status(uint8_t port, uint8_t &state, int8_t &power, int32_t &position, int16_t &dps){ |
| 281 | uint8_t msg_type; |
| 282 | switch(port){ |
| 283 | case MOTOR_LEFT: |
| 284 | msg_type = GPGSPI_MESSAGE_GET_MOTOR_STATUS_LEFT; |
| 285 | break; |
| 286 | case MOTOR_RIGHT: |
| 287 | msg_type = GPGSPI_MESSAGE_GET_MOTOR_STATUS_RIGHT; |
| 288 | break; |
| 289 | default: |
| 290 | fatal_error("get_motor_status error. Must be one motor at a time. MOTOR_LEFT or MOTOR_RIGHT."); |
| 291 | } |
| 292 | spi_array_out[0] = Address; |
| 293 | spi_array_out[1] = msg_type; |
| 294 | // assign error to the value returned by spi_transfer_array, and if not 0: |
| 295 | if(int error = spi_transfer_array(12, spi_array_out, spi_array_in)){ |
| 296 | return error; |
| 297 | } |
| 298 | |
| 299 | if(spi_array_in[3] != 0xA5){ |
| 300 | return ERROR_SPI_RESPONSE; |
| 301 | } |
| 302 | |
| 303 | state = spi_array_in[4]; |
| 304 | power = spi_array_in[5]; |
| 305 | position = ((spi_array_in[6] << 24) | (spi_array_in[7] << 16) | (spi_array_in[8] << 8) | spi_array_in[9]); |
| 306 | dps = ((spi_array_in[10] << 8) | spi_array_in[11]); |
| 307 | |
| 308 | return ERROR_NONE; |
| 309 | } |
| 310 | |
| 311 | int GoPiGo3::offset_motor_encoder(uint8_t port, int32_t position){ |
| 312 | spi_array_out[0] = Address; |
no test coverage detected