Skip to content

Commit

Permalink
Merge pull request purduesigbots#169 from TixoRebel/feature/controlle…
Browse files Browse the repository at this point in the history
…r-send-error

✨ Provide error if updates are sent too quickly to the controller or if it is not connected
  • Loading branch information
nathan-moore authored Nov 21, 2019
2 parents c5fd109 + 4de3a0a commit 7fa5c61
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 7 deletions.
3 changes: 2 additions & 1 deletion include/pros/misc.h
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,8 @@ int32_t controller_clear_line(controller_id_e_t id, uint8_t line);
* Clears all of the lines on the controller screen.
*
* \note Controller text setting is currently in beta, so continuous, fast
* updates will not work well.
* updates will not work well. On vexOS version 1.0.0 this function will block
* for 110ms.
*
* This function uses the following values of errno when an error state is
* reached:
Expand Down
3 changes: 2 additions & 1 deletion include/pros/misc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,8 @@ class Controller {
* Clears all of the lines on the controller screen.
*
* \note Controller text setting is currently in beta, so continuous, fast
* updates will not work well.
* updates will not work well. On vexOS version 1.0.0 this function will
* block for 110ms.
*
* This function uses the following values of errno when an error state is
* reached:
Expand Down
33 changes: 28 additions & 5 deletions src/devices/controller.c
Original file line number Diff line number Diff line change
Expand Up @@ -206,9 +206,14 @@ int32_t controller_set_text(controller_id_e_t id, uint8_t line, uint8_t col, con

char* buf = strndup(str, CONTROLLER_MAX_COLS + 1);

vexControllerTextSet(id, line, col, buf);
uint32_t rtn_val = vexControllerTextSet(id, line, col, buf);
free(buf);
internal_port_mutex_give(port);

if (!rtn_val) {
errno = EAGAIN;
return PROS_ERR;
}
return 1;
}

Expand Down Expand Up @@ -240,11 +245,16 @@ int32_t controller_print(controller_id_e_t id, uint8_t line, uint8_t col, const
char* buf = (char*)malloc(CONTROLLER_MAX_COLS + 1);
vsnprintf(buf, CONTROLLER_MAX_COLS + 1, fmt, args);

vexControllerTextSet(id, line, col, buf);
uint32_t rtn_val = vexControllerTextSet(id, line, col, buf);
free(buf);
va_end(args);

internal_port_mutex_give(port);

if (!rtn_val) {
errno = EAGAIN;
return PROS_ERR;
}
return 1;
}

Expand All @@ -268,14 +278,27 @@ int32_t controller_clear_line(controller_id_e_t id, uint8_t line) {
line++;

const char* const blank = " ";
vexControllerTextSet(port, line, 0, blank);
uint32_t rtn_val = vexControllerTextSet(port, line, 0, blank);
internal_port_mutex_give(port);

if (!rtn_val) {
errno = EAGAIN;
return PROS_ERR;
}
return 1;
}

int32_t controller_clear(controller_id_e_t id) {
for (int i = 0; i < 3; i++) controller_clear_line(id, i);
return 1;
if (vexSystemVersion() > 0x01000000) {
return controller_print(id, 0, 0, "");
} else {
for (int i = 0; i < 3; i++) {
int32_t rtn = controller_clear_line(id, i);
if (rtn == PROS_ERR) return PROS_ERR;
if (i != 2) delay(55);
}
return 1;
}
}

int32_t controller_rumble(controller_id_e_t id, const char* rumble_pattern) {
Expand Down

0 comments on commit 7fa5c61

Please sign in to comment.