Skip to content

Commit

Permalink
Match Status
Browse files Browse the repository at this point in the history
Pressing the middle button has been changed from refreshing the watch to displaying the current match status. To get updated match statuses, you must be running at least version 0.9 of the companion app.
  • Loading branch information
333fred committed Feb 6, 2016
1 parent 2f822d3 commit 8ed3f17
Show file tree
Hide file tree
Showing 6 changed files with 109 additions and 11 deletions.
6 changes: 6 additions & 0 deletions appinfo.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@
"projectType": "native",
"resources": {
"media": [
{
"characterRegex": "[A-Za-z0-9\\-]",
"file": "fonts/RobotoCondensed-Bold",
"name": "ROBOTO_CONDENSED_BOLD_38",
"type": "font"
},
{
"file": "images/FIRSTicon_RGB.png",
"menuIcon": true,
Expand Down
Binary file added resources/fonts/RobotoCondensed-Bold
Binary file not shown.
8 changes: 7 additions & 1 deletion src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#define BLUE1_BATT 18
#define BLUE2_BATT 19
#define BLUE3_BATT 20
#define MATCH_STATE 21
#define CHECK_TYPE(type, size) if (type != TUPLE_UINT && size != 1) { \
APP_LOG(APP_LOG_LEVEL_ERROR, "Received nonuint type %d", (int) type); \
t = dict_read_next(iter); \
Expand All @@ -43,6 +44,7 @@ int s_red3_battery = 0;
int s_blue1_battery = 0;
int s_blue2_battery = 0;
int s_blue3_battery = 0;
match_state s_match_state = NOT_READY;
show_type s_show_type = SHOW_STATUS;

status_type s_red1_status = 0;
Expand Down Expand Up @@ -115,6 +117,9 @@ static void inbox_received_callback(DictionaryIterator *iter, void *ctx) {
case BLUE3_BATT:
s_blue3_battery = status;
break;
case MATCH_STATE:
s_match_state = (match_state) status;
break;
}

t = dict_read_next(iter);
Expand All @@ -132,7 +137,8 @@ void request_update() {

// Single click callback
void select_single_click_handler(ClickRecognizerRef recognizer, void *context) {
request_update();
s_show_type = s_show_type == SHOW_MATCH_STATUS ? SHOW_STATUS : SHOW_MATCH_STATUS;
update_text();
}

static void message_dropped_callback(AppMessageResult reason, void *ctx) {
Expand Down
98 changes: 89 additions & 9 deletions src/text.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@ static TextLayer *s_red3_number;
static TextLayer *s_blue1_number;
static TextLayer *s_blue2_number;
static TextLayer *s_blue3_number;
static TextLayer *s_match_state_header;
static TextLayer *s_match_state_layer;
static GFont *s_source_code_pro;
static GFont *s_source_code_pro_number;
static GFont *s_roboto_condensed;
static char *s_red1_text;
static char *s_red2_text;
static char *s_red3_text;
Expand Down Expand Up @@ -43,9 +46,14 @@ extern status_type s_red3_status;
extern status_type s_blue1_status;
extern status_type s_blue2_status;
extern status_type s_blue3_status;

extern match_state s_match_state;

// Constant text strings for the connection statuses
const char *eth = "Eth", *ds = "DS", *radio = "Rd", *rio = "RIO", *code = "Cd", *estop = "Est", *good = "G", *bwu = "BWU", *byp = "BYP", *bat = "Bat";
const char *not_ready = "Not Ready", *timeout = "Time out", *ready_prestart = "Ready to Prestart", *prestart_initiated = "Prestart Initiated",
*prestart_complete = "Prestart Completed", *match_ready = "Match Ready", *auto_mode = "Auto Running", *teleop_mode = "Teleop Running", *over = "Over",
*aborted = "Aborted";

// Updates the text on the screen with the current values. It uses the correct display whether
// the current update type is status or team number.
Expand Down Expand Up @@ -87,45 +95,98 @@ void update_text() {
set_alliance_text(s_blue2_text, false, 2, 2, true);
set_alliance_text(s_blue3_text, false, 2, 3, true);
break;
case SHOW_MATCH_STATUS:
update_match_status();
break;
}
update_visibility();
}

void update_visibility() {
layer_set_hidden((Layer*) s_match_state_layer, s_show_type != SHOW_MATCH_STATUS);
layer_set_hidden((Layer*) s_match_state_header, s_show_type != SHOW_MATCH_STATUS);
layer_set_hidden((Layer*) s_red_header, s_show_type == SHOW_MATCH_STATUS);
layer_set_hidden((Layer*) s_blue_header, s_show_type == SHOW_MATCH_STATUS);
layer_set_hidden((Layer*) s_blue1, s_show_type != SHOW_STATUS);
layer_set_hidden((Layer*) s_blue2, s_show_type != SHOW_STATUS);
layer_set_hidden((Layer*) s_blue3, s_show_type != SHOW_STATUS);
layer_set_hidden((Layer*) s_red1, s_show_type != SHOW_STATUS);
layer_set_hidden((Layer*) s_red2, s_show_type != SHOW_STATUS);
layer_set_hidden((Layer*) s_red3, s_show_type != SHOW_STATUS);
layer_set_hidden((Layer*) s_blue1_number, s_show_type != SHOW_BATTERY && s_show_type != SHOW_NUMBERS);
layer_set_hidden((Layer*) s_blue2_number, s_show_type != SHOW_BATTERY && s_show_type != SHOW_NUMBERS);
layer_set_hidden((Layer*) s_blue3_number, s_show_type != SHOW_BATTERY && s_show_type != SHOW_NUMBERS);
layer_set_hidden((Layer*) s_red1_number, s_show_type != SHOW_BATTERY && s_show_type != SHOW_NUMBERS);
layer_set_hidden((Layer*) s_red2_number, s_show_type != SHOW_BATTERY && s_show_type != SHOW_NUMBERS);
layer_set_hidden((Layer*) s_red3_number, s_show_type != SHOW_BATTERY && s_show_type != SHOW_NUMBERS);
}

void update_match_status() {
const char* match_text;
switch (s_match_state) {
case NOT_READY:
match_text = not_ready;
break;
case READY_PRESTART:
match_text = ready_prestart;
break;
case PRESTART_INITATED:
match_text = prestart_initiated;
break;
case PRESTART_COMPLETED:
match_text = prestart_complete;
break;
case MATCH_READY:
match_text = match_ready;
break;
case AUTO:
match_text = auto_mode;
break;
case TELEOP:
match_text = teleop_mode;
break;
case OVER:
match_text = over;
break;
case TIMEOUT:
match_text = timeout;
break;
case ABORTED:
default:
match_text = aborted;
break;
}

text_layer_set_text(s_match_state_layer, match_text);
}

// Sets the alliance text to be the given text string for the given alliance and team.
void set_alliance_text(const char *text, bool hi_contrast, uint8_t alliance, uint8_t team, bool useNumber) {
uint16_t switch_mult = (alliance << 8) | team;
TextLayer *team_layer;
TextLayer *invisible_layer;
switch (switch_mult) {
case 0x0101:
team_layer = useNumber ? s_red1_number : s_red1;
invisible_layer = !useNumber ? s_red1_number : s_red1;
break;
case 0x0102:
team_layer = useNumber ? s_red2_number : s_red2;
invisible_layer = !useNumber ? s_red2_number : s_red2;
break;
case 0x0103:
team_layer = useNumber ? s_red3_number : s_red3;
invisible_layer = !useNumber ? s_red3_number : s_red3;
break;
case 0x0201:
team_layer = useNumber ? s_blue1_number : s_blue1;
invisible_layer = !useNumber ? s_blue1_number : s_blue1;
break;
case 0x0202:
team_layer = useNumber ? s_blue2_number : s_blue2;
invisible_layer = !useNumber ? s_blue2_number : s_blue2;
break;
case 0x0203:
team_layer = useNumber ? s_blue3_number : s_blue3;
invisible_layer = !useNumber ? s_blue3_number : s_blue3;
break;
default:
return;
}

layer_set_hidden((Layer *) team_layer, false);
layer_set_hidden((Layer *) invisible_layer, true);
text_layer_set_text(team_layer, text);
if (hi_contrast) {
text_layer_set_background_color(team_layer, GColorBlack);
Expand Down Expand Up @@ -226,12 +287,27 @@ void setup_text_window_load(Layer *window_layer) {
setup_alliance_textlayer(&s_blue2_number, window_layer, 0, 66, s_source_code_pro_number);
setup_alliance_textlayer(&s_blue3_number, window_layer, 0, 112, s_source_code_pro_number);

s_match_state_header = text_layer_create(GRect(0, 0, 144, 20));
s_match_state_layer = text_layer_create(GRect(0, 20, 144, 148));
text_layer_set_text_alignment(s_match_state_header, GTextAlignmentCenter);
text_layer_set_text_alignment(s_match_state_layer, GTextAlignmentCenter);
text_layer_set_overflow_mode(s_match_state_layer, GTextOverflowModeWordWrap);
text_layer_set_font(s_match_state_layer, fonts_get_system_font(FONT_KEY_GOTHIC_18_BOLD));
text_layer_set_font(s_match_state_layer, s_roboto_condensed);
text_layer_set_text(s_match_state_header, "Match Status");
layer_add_child(window_layer, text_layer_get_layer(s_match_state_header));
layer_add_child(window_layer, text_layer_get_layer(s_match_state_layer));

set_alliance_status(ETH, 1, 1);
set_alliance_status(ETH, 1, 2);
set_alliance_status(ETH, 1, 3);
set_alliance_status(ETH, 2, 1);
set_alliance_status(ETH, 2, 2);
set_alliance_status(ETH, 2, 3);
s_match_state = NOT_READY;
s_show_type = SHOW_STATUS;
update_match_status();
update_visibility();
}

void destroy_text_window_unload() {
Expand All @@ -249,6 +325,8 @@ void destroy_text_window_unload() {
text_layer_destroy(s_blue1_number);
text_layer_destroy(s_blue2_number);
text_layer_destroy(s_blue3_number);
text_layer_destroy(s_match_state_layer);
text_layer_destroy(s_match_state_header);
}

void setup_text_init() {
Expand All @@ -260,11 +338,13 @@ void setup_text_init() {
s_blue3_text = (char*) malloc(6 * sizeof(char));
s_source_code_pro = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_SOURCE_CODE_PRO_REG_38));
s_source_code_pro_number = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_SOURCE_CODE_PRO_REG_24));
s_roboto_condensed = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_ROBOTO_CONDENSED_BOLD_38));
}

void destroy_text_init() {
fonts_unload_custom_font(s_source_code_pro);
fonts_unload_custom_font(s_source_code_pro_number);
fonts_unload_custom_font(s_roboto_condensed);
free(s_red1_text);
free(s_red2_text);
free(s_red3_text);
Expand Down
4 changes: 3 additions & 1 deletion src/text.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include "utility.h"

typedef enum {
SHOW_STATUS, SHOW_NUMBERS, SHOW_BATTERY
SHOW_STATUS, SHOW_NUMBERS, SHOW_BATTERY, SHOW_MATCH_STATUS
} show_type;

void setup_text_init();
Expand All @@ -13,3 +13,5 @@ void destroy_text_window_unload();
void update_text();
void set_alliance_text(const char *text, bool hi_contrast, uint8_t alliance, uint8_t team, bool useNumber);
void set_alliance_status(status_type status, uint8_t alliance, uint8_t team);
void update_match_status();
void update_visibility();
4 changes: 4 additions & 0 deletions src/utility.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,8 @@ typedef enum {
ETH=0, DS=1, RADIO=2, RIO=3, CODE=4, ESTOP=5, GOOD=6, BWU=7, BYP = 8, BAT = 9
} status_type;

typedef enum {
NOT_READY=0, TIMEOUT=1, READY_PRESTART=2, PRESTART_INITATED=3, PRESTART_COMPLETED=4, MATCH_READY=5, AUTO=6, TELEOP=7, OVER=8, ABORTED=9
} match_state;

char* translate_error(AppMessageResult res);

0 comments on commit 8ed3f17

Please sign in to comment.