Commit 2f05af05 authored by Federico Vaga's avatar Federico Vaga

freewatch: apply Linux style step 3 - reduce indentation levels

Signed-off-by: 's avatarFederico Vaga <federico.vaga@gmail.com>
parent d1ff29c0
......@@ -54,7 +54,7 @@ static void digital_watch_redraw(struct ui_widget *w) {
}
static void digital_watch_event(struct ui_widget *w, const struct event *evt) {
// Hour has changed, it is /* TODO: */ime to redraw the clock
// Hour has changed, it is time to redraw the clock
if(evt->type == RTC_TICK) {
rtc = rtc_get_time();
localtime_r((time_t*) &rtc.epoch, &cur_time);
......@@ -82,6 +82,7 @@ struct ui_widget clock_screen = {
void clock_main(void* params) {
(void)(params); // suppress unused parameter warning
struct event evt;
int ret;
// Restore clock
rtc = rtc_get_time();
......@@ -105,18 +106,21 @@ void clock_main(void* params) {
// Event loop
while(1) {
if(xQueueReceive(appQueue, &evt, portMAX_DELAY)) {
switch(evt.type) {
case BUTTON_PRESSED:
if (evt.data.button == BUT_TR ||
evt.data.button == BUT_TL)
return; // go back to the main menu
// no break; fall through
default: // suppress warnings
ui_update(&evt); // forward event to widgets
break;
}
ret = xQueueReceive(appQueue, &evt, portMAX_DELAY);
if(ret == pdFALSE)
continue;
// Handle clock's events
switch(evt.type) {
case BUTTON_PRESSED:
if (evt.data.button == BUT_TR ||
evt.data.button == BUT_TL)
return; /* Quit Application */
// no break; fall through
default: // suppress warnings
ui_update(&evt); // forward event to widgets
break;
}
}
}
......
......@@ -65,22 +65,29 @@ static void compass_redraw(struct ui_widget *w)
gfx_clear(&w->dc, 0);
//gfx_line(&w->dc, COMP_X0, COMP_Y0, x_lcd, y_lcd, 1);
if(!calib) {
gfx_draw_bitmap(&w->dc, COMP_X0-cir_w/2, COMP_Y0-cir_h/2, &comp_circle2);
gfx_draw_bitmap_rotate(&w->dc, COMP_X0-arr_w/2, COMP_Y0-arr_h/2, &comp_arrow2,
COMP_X0, COMP_Y0, angle, sina, cosa);
}
if(calib==1) {
switch (calib) {
case 0:
gfx_draw_bitmap(&w->dc,
COMP_X0-cir_w/2, COMP_Y0-cir_h/2,
&comp_circle2);
gfx_draw_bitmap_rotate(&w->dc,
COMP_X0-arr_w/2, COMP_Y0-arr_h/2,
&comp_arrow2,
COMP_X0, COMP_Y0,
angle, sina, cosa);
break;
case 1:
sprintf(buf, "Calibration");
gfx_centered_text(&w->dc, &font_helv17, 60, buf, COLOR_BLACK);
}
if(calib==2) {
break;
case 2:
sprintf(buf, "ix: %d", iron.x);
gfx_text(&w->dc, &font_helv17, 10, 30, buf, COLOR_BLACK);
sprintf(buf, "iy: %d", iron.y);
gfx_text(&w->dc, &font_helv17, 10, 60, buf, COLOR_BLACK);
sprintf(buf, "iz: %d", iron.z);
gfx_text(&w->dc, &font_helv17, 10, 90, buf, COLOR_BLACK);
break;
}
}
......@@ -116,6 +123,7 @@ void compass_main(void *params)
/*unsigned int x2, y2, z2;*/
float xy_mean;
char buf[50];
int ret;
/*lsm303 init, we need both ACC & MAG for tilt/roll compensation*/
lsm303_init();
......@@ -132,12 +140,13 @@ void compass_main(void *params)
/*main loop*/
while(1) {
if(xQueueReceive(appQueue, &evt, 50 / portTICK_RATE_MS)) {
ret = xQueueReceive(appQueue, &evt, 50 / portTICK_RATE_MS);
if(ret == pdTRUE) {
switch(evt.type) {
case BUTTON_PRESSED:
if (evt.data.button == BUT_TR ||
evt.data.button == BUT_TL)
return;
return; /* Quit application */
/*if(evt.data.button == BUT_BR) {
c_min.x = 0x7fff;
......@@ -156,20 +165,11 @@ void compass_main(void *params)
calib = 0;
}*/
}
}
else {
} else {
lsm303_get_sample(DEV_ACC, &acc);
lsm303_get_sample(DEV_MAG, &mag);
if(calib==1) {
/* we try to find min and max for axis to calibrate */
if(mag.x > c_max.x) c_max.x = mag.x;
if(mag.x < c_min.x) c_min.x = mag.x;
if(mag.y > c_max.y) c_max.y = mag.y;
if(mag.y < c_min.y) c_min.y = mag.y;
if(mag.z > c_max.z) c_max.z = mag.z;
if(mag.z < c_min.z) c_min.z = mag.z;
}
if(!calib) {
switch (calib) {
case 0:
/* calculate pitch and roll from accelerometer */
/*x2 = acc.x * acc.x;*/
/*y2 = acc.y * acc.y;*/
......@@ -178,8 +178,8 @@ void compass_main(void *params)
roll = small_atan(acc.y, small_sqrt(acc.x*acc.x + acc.z*acc.z));
sprintf(buf, "p: %d, r: %d\n\r", pitch, roll);
#if defined(DEBUG)
// NOTE: usbdbg_init() called in main.c
usbdbg_puts(buf);
// NOTE: usbdbg_init() called in main.c
usbdbg_puts(buf);
#endif
/* work with compass readout, first revert it because magnetic south is north */
mag.x *= -1;
......@@ -203,6 +203,22 @@ void compass_main(void *params)
/* we need sina and cosa to rotate compass arrow */
sina = (float)yh/xy_mean;
cosa = (float)xh/xy_mean;
break;
case 1:
/* we try to find min and max for axis to calibrate */
if(mag.x > c_max.x)
c_max.x = mag.x;
if(mag.x < c_min.x)
c_min.x = mag.x;
if(mag.y > c_max.y)
c_max.y = mag.y;
if(mag.y < c_min.y)
c_min.y = mag.y;
if(mag.z > c_max.z)
c_max.z = mag.z;
if(mag.z < c_min.z)
c_min.z = mag.z;
break;
}
ui_update(&evt);
}
......
......@@ -100,6 +100,7 @@ void game_main(void *params)
int fakap = 0;
int old_x, old_y;
int fact;
int ret;
lsm303_init();
buzzer_set_freq(4000);
......@@ -126,14 +127,15 @@ void game_main(void *params)
/*main loop*/
while(1) {
if(xQueueReceive(appQueue, &evt, 30 / portTICK_RATE_MS)) {
ret = xQueueReceive(appQueue, &evt, portMAX_DELAY);
if(ret == pdTRUE) {
switch(evt.type) {
case BUTTON_PRESSED:
if (evt.data.button == BUT_TR ||
evt.data.button == BUT_TL) {
if (evt.data.button == BUT_TR ||
evt.data.button == BUT_TL) {
vibra_disable();
buzzer_disable();
return;
return; /* Quit application */
}
if(evt.data.button == BUT_BR)
mode = MODE_HIGH;
......@@ -141,6 +143,7 @@ void game_main(void *params)
mode = MODE_NORM;
}
}
lsm303_get_sample(DEV_ACC, &acc);
ball_x -= acc.x/100;
ball_y -= acc.y/100;
......
......@@ -70,7 +70,8 @@ static void gps_redraw(struct ui_widget *w)
/* Display latitude and longitude depending on format */
if (gpsscreen == 0) {
if (coord_format == 0) {
switch (coord_format) {
case 0:
/* raw [deg][min].[sec/60] */
sprintf(buf, "L: %d deg", (int)latdeg);
gfx_text(&w->dc, &font_helv22b, 0, 0, buf, 0);
......@@ -81,7 +82,7 @@ static void gps_redraw(struct ui_widget *w)
gfx_text(&w->dc, &font_helv22b, 0, 50, buf, 0);
sprintf(buf, "%2.4f'", lonmin);
gfx_text(&w->dc, &font_helv22b, 15, 70, buf, 0);
} else if (coord_format == 1) {
case 1:
/* [deg] [min] [sec] */
sprintf(buf, "L: %d deg", (int)latdeg);
gfx_text(&w->dc, &font_helv22b, 0, 0, buf, 0);
......@@ -92,7 +93,7 @@ static void gps_redraw(struct ui_widget *w)
gfx_text(&w->dc, &font_helv22b, 0, 50, buf, 0);
sprintf(buf, "%d'%2.2f\"", (int)lonmin, 100 * lonsec);
gfx_text(&w->dc, &font_helv22b, 5, 70, buf, 0);
} else if (coord_format == 2) {
case 2:
/* [deg].[min/60] */
sprintf(buf, "L: %2.4f", coord.lat);
gfx_text(&w->dc, &font_helv22b, 0, 0, buf, 0);
......@@ -137,6 +138,7 @@ void gpscoord_main(void *params)
(void) params;
struct event evt;
int ret;
/* Init UI */
ui_clear();
......@@ -154,12 +156,15 @@ void gpscoord_main(void *params)
ui_update(NULL);
while (1) {
if (xQueueReceive(appQueue, &evt, portMAX_DELAY)) {
switch (evt.type) {
case BUTTON_PRESSED:
if (evt.data.button == BUT_TR ||
evt.data.button == BUT_TL)
return;
ret = xQueueReceive(appQueue, &evt, portMAX_DELAY);
if(ret != pdTRUE)
continue;
switch (evt.type) {
case BUTTON_PRESSED:
if (evt.data.button == BUT_TR ||
evt.data.button == BUT_TL)
return; /* Quit application */
// else if (evt.data.button == BUT_BR) {
// /*
// * Toggle between coordinate and
......@@ -170,11 +175,11 @@ void gpscoord_main(void *params)
// }
/* fall through */
case GPS_TICK:
ui_update(&evt);
default:
break;
}
case GPS_TICK:
/* Update GPS UI with event content */
ui_update(&evt);
default:
break;
}
}
}
......
......@@ -52,13 +52,12 @@ static void menu_ui_init();
static void menu_screen_redraw(struct ui_widget *w)
{
int i;
int i, pos;
int menu_limit = (menu_size < MAX_ENTRIES ? menu_size : MAX_ENTRIES);
gfx_clear(&w->dc, 0);
for(i = 0; i < menu_limit; ++i)
{
int pos = offset + i;
for(i = 0; i < menu_limit; ++i) {
pos = offset + i;
// draw a white background for the selected entry
if(pos == selected_item) {
......@@ -85,7 +84,7 @@ static void menu_screen_redraw(struct ui_widget *w)
i * LINE_HEIGHT, l->name, i != selected_item);
} else if (ent->type == SETTING) {
char s[16];
setting_t *set = ent->#define ata.setting;
setting_t *set = ent->data.setting;
sprintf(s, "%s: %d", set->name, set->val);
// strcat(s, ": ")
// strcat(s, set->val);
......@@ -98,35 +97,32 @@ static void menu_screen_redraw(struct ui_widget *w)
static void menu_screen_event(struct ui_widget *w, const struct event *evt)
{
// scroll through the menu if a button was pressed
if(evt->type == BUTTON_PRESSED) {
if(evt->data.button == BUT_BR) {
if(selected_item < menu_size - 1) {
++selected_item;
if(selected_item >= MAX_ENTRIES)
offset = selected_item - MAX_ENTRIES + 1;
} else {
selected_item = 0;
offset = 0;
}
w->flags |= WF_DIRTY;
} else if(evt->data.button == BUT_BL) {
if(selected_item > 0) {
--selected_item;
if(selected_item < offset)
offset = selected_item;
} else {
selected_item = menu_size - 1;
if (menu_size < MAX_ENTRIES)
offset = selected_item - menu_size + 1;
else
offset = selected_item - MAX_ENTRIES + 1;
}
w->flags |= WF_DIRTY;
if(evt->type != BUTTON_PRESSED)
return;
if(evt->data.button == BUT_BR) {
if(selected_item < menu_size - 1) {
++selected_item;
if(selected_item >= MAX_ENTRIES)
offset = selected_item - MAX_ENTRIES + 1;
} else {
selected_item = 0;
offset = 0;
}
w->flags |= WF_DIRTY;
} else if(evt->data.button == BUT_BL) {
if(selected_item > 0) {
--selected_item;
if(selected_item < offset)
offset = selected_item;
} else {
selected_item = menu_size - 1;
if (menu_size < MAX_ENTRIES)
offset = selected_item - menu_size + 1;
else
offset = selected_item - MAX_ENTRIES + 1;
}
w->flags |= WF_DIRTY;
}
}
......@@ -187,6 +183,7 @@ static void go_back() {
void menu_main(void* params) {
(void)(params); // suppress unused parameter warning
struct event evt;
int ret;
battery_update();
menu_size = get_menu_size(*current_menu);
......@@ -197,23 +194,25 @@ void menu_main(void* params) {
// Once it is deactivated - display the menu
while(1) {
if(xQueueReceive(appQueue, &evt, portMAX_DELAY)) {
switch(evt.type) {
case BUTTON_PRESSED:
if(evt.data.button == BUT_TL) {
go_back();
} else if(evt.data.button == BUT_TR) {
// run the selected application or submenu
run(&(*current_menu)->entries[selected_item]);
} else {
ui_update(&evt);
}
break;
default: // suppress warnings
ret = xQueueReceive(appQueue, &evt, portMAX_DELAY);
if(ret != pdTRUE)
continue;
switch(evt.type) {
case BUTTON_PRESSED:
if(evt.data.button == BUT_TL) {
go_back();
} else if(evt.data.button == BUT_TR) {
// run the selected application or submenu
run(&(*current_menu)->entries[selected_item]);
} else {
ui_update(&evt);
break;
}
break;
default: // suppress warnings
ui_update(&evt);
break;
}
}
}
......
......@@ -33,7 +33,8 @@ int get_menu_size(const menu_list *menu) {
const menu_entry* ptr = menu->entries;
// Look for sentinel
while((*ptr++).type != END) ++len;
while((*ptr++).type != END)
++len;
return len;
}
......
......@@ -52,6 +52,7 @@ void reset_main(void *params)
{
(void) params; // suppress warnings
struct event evt;
int ret;
/* Init UI */
ui_clear();
......@@ -62,26 +63,29 @@ void reset_main(void *params)
ui_update(NULL);
while(1) {
if (xQueueReceive(appQueue, &evt, portMAX_DELAY)) {
switch (evt.type) {
case BUTTON_PRESSED:
if (evt.data.button == BUT_TR ||
evt.data.button == BUT_TL)
return;
/* Reset on bottom right and bottom left buttons
* pressed */
if (evt.data.button == BUT_BR)
SCB->AIRCR = 0x05FA0004;
// Turn GPS off if setting is ON, to prepare it for
// the turn-on pulse on reset
if (setting_get(&setting_gps_on)) {
int i;
gps_on_off_pulse();
for (i = 0; i < 1000000; i++)
;
}
break;
ret = xQueueReceive(appQueue, &evt, portMAX_DELAY);
if (ret != pdTRUE)
continue;
switch (evt.type) {
case BUTTON_PRESSED:
if (evt.data.button == BUT_TR ||
evt.data.button == BUT_TL)
return; /* Quit application */
/* Reset on bottom right and bottom left buttons
* pressed */
if (evt.data.button == BUT_BR)
SCB->AIRCR = 0x05FA0004;
// Turn GPS off if setting is ON, to prepare it for
// the turn-on pulse on reset
if (setting_get(&setting_gps_on)) {
int i;
gps_on_off_pulse();
for (i = 0; i < 1000000; i++)
;
}
break;
}
}
}
......
......@@ -144,7 +144,7 @@ static void load(void)
void set_date_main(void* params) {
(void)(params); // suppress unused parameter warning
struct event evt;
int i;
int i, ret;
// initialize user interface
ui_clear();
......@@ -179,34 +179,36 @@ void set_date_main(void* params) {
// event loop
while(1) {
if(xQueueReceive(appQueue, &evt, portMAX_DELAY)) {
switch(evt.type) {
case BUTTON_PRESSED:
if(evt.data.button == BUT_TL) {
return; // go back to the main menu
} else if(evt.data.button == BUT_TR) {
if(sb_index < SPINBOX_NUMBER - 1) {
spinbox_set_active(&sb_date[sb_index], false);
spinbox_set_active(&sb_date[++sb_index], true);
} else if(is_valid()) {
save();
return;
} else {
// the set hour is invalid, start from the beginning
spinbox_set_active(&sb_date[sb_index], false);
sb_index = D1;
spinbox_set_active(&sb_date[D1], true);
}
ret = xQueueReceive(appQueue, &evt, portMAX_DELAY);
if(ret != pdTRUE)
continue;
switch(evt.type) {
case BUTTON_PRESSED:
if(evt.data.button == BUT_TL) {
return; // go back to the main menu
} else if(evt.data.button == BUT_TR) {
if(sb_index < SPINBOX_NUMBER - 1) {
spinbox_set_active(&sb_date[sb_index], false);
spinbox_set_active(&sb_date[++sb_index], true);
} else if(is_valid()) {
save();
return;
} else {
// the set hour is invalid, start from the beginning
spinbox_set_active(&sb_date[sb_index], false);
sb_index = D1;
spinbox_set_active(&sb_date[D1], true);
}
}
ui_update(&evt);
break;
ui_update(&evt);
break;
/* Update UI on any event, so the status bar is updated */
default:
ui_update(&evt);
break;
}
/* Update UI on any event, so the status bar is updated */
default:
ui_update(&evt);
break;
}
}
}
......
......@@ -130,7 +130,7 @@ static void load(void)
void set_gmt_ofs_main(void* params) {
(void)(params); // suppress unused parameter warning
struct event evt;
int i;
int i, ret;
// initialize user interface
ui_clear();
......@@ -165,34 +165,36 @@ void set_gmt_ofs_main(void* params) {
// event loop
while(1) {
if(xQueueReceive(appQueue, &evt, portMAX_DELAY)) {
switch(evt.type) {
case BUTTON_PRESSED:
if(evt.data.button == BUT_TL) {
return; // go back to the main menu
} else if(evt.data.button == BUT_TR) {
if(sb_index < SPINBOX_NUMBER - 1) {
spinbox_set_active(&sb_time[sb_index], false);
spinbox_set_active(&sb_time[++sb_index], true);
} else if(is_valid()) {
save();
return;
} else {
// the set hour is invalid, start from the beginning
spinbox_set_active(&sb_time[sb_index], false);
sb_index = S;
spinbox_set_active(&sb_time[S], true);
}
ret = xQueueReceive(appQueue, &evt, portMAX_DELAY);
if(ret != pdTRUE)
continue;
switch(evt.type) {
case BUTTON_PRESSED:
if(evt.data.button == BUT_TL) {
return; // go back to the main menu
} else if(evt.data.button == BUT_TR) {
if(sb_index < SPINBOX_NUMBER - 1) {
spinbox_set_active(&sb_time[sb_index], false);
spinbox_set_active(&sb_time[++sb_index], true);
} else if(is_valid()) {
save();
return;
} else {
// the set hour is invalid, start from the beginning
spinbox_set_active(&sb_time[sb_index], false);
sb_index = S;
spinbox_set_active(&sb_time[S], true);
}
}
ui_update(&evt);
break;
ui_update(&evt);
break;
/* Update UI on any event, so the status bar is updated */
default:
ui_update(&evt);
break;
}
/* Update UI on any event, so the status bar is updated */
default:
ui_update(&evt);
break;
}
}
}
......
......@@ -107,7 +107,7 @@ static void load(void)
void set_time_main(void* params) {
(void)(params); // suppress unused parameter warning
struct event evt;
int i;
int i, ret;
// initialize user interface
ui_clear();
......@@ -142,34 +142,36 @@ void set_time_main(void* params) {
// event loop
while(1) {
if(xQueueReceive(appQueue, &evt, portMAX_DELAY)) {
switch(evt.type) {
case BUTTON_PRESSED:
if(evt.data.button == BUT_TL) {
return; // go back to the main menu
} else if(evt.data.button == BUT_TR) {
if(sb_index < SPINBOX_NUMBER - 1) {
spinbox_set_active(&sb_time[sb_index], false);
spinbox_set_active(&sb_time[++sb_index], true);
} else if(is_valid()) {
save();
return;
} else {
// the set hour is invalid, start from the beginning
spinbox_set_active(&sb_time[sb_index], false);
sb_index = H1;
spinbox_set_active(&sb_time[H1], true);
}
ret = xQueueReceive(appQueue, &evt, portMAX_DELAY);
if(ret != pdTRUE)
continue;
switch(evt.type) {
case BUTTON_PRESSED:
if(evt.data.button == BUT_TL) {
return; // go back to the main menu
} else if(evt.data.button == BUT_TR) {
if(sb_index < SPINBOX_NUMBER - 1) {
spinbox_set_active(&sb_time[sb_index], false);
spinbox_set_active(&sb_time[++sb_index], true);
} else if(is_valid()) {
save();
return;
} else {
// the set hour is invalid, start from the beginning
spinbox_set_active(&sb_time[sb_index], false);
sb_index = H1;
spinbox_set_active(&sb_time[H1], true);
}
}
ui_update(&evt);
break;
ui_update(&evt);
break;
/* Update UI on any event, so the status bar is updated */
default:
ui_update(&evt);
break;
}
/* Update UI on any event, so the status bar is updated */
default:
ui_update(&evt);
break;
}
}
}
......
......@@ -69,6 +69,7 @@ struct ui_widget usb_ms_screen = {
void usb_ms_main(void* params) {
(void)(params); // suppress unused parameter warning
struct event evt;
int ret;
ui_clear();
......@@ -90,27 +91,29 @@ void usb_ms_main(void* params) {
while(1) {
if(xQueueReceive(appQueue, &evt, 0)) {
switch(evt.type) {
case BUTTON_PRESSED:
if (evt.data.button == BUT_TR ||
evt.data.button == BUT_TL) {
if (mutexours) {
mutexours = 0;
USBD_Stop();
xSemaphoreGive(mutexSdCardAccess);
}
return; // go back to the main menu
}
break;
ret = xQueueReceive(appQueue, &evt, 0);
if (ret != pdTRUE) {
MSDD_Handler();
continue;
}
default: // suppress warnings
// ignore events that were not mentioned above
ui_update(&evt);
break;
switch(evt.type) {
case BUTTON_PRESSED:
if (evt.data.button == BUT_TR ||
evt.data.button == BUT_TL) {
if (mutexours) {
mutexours = 0;
USBD_Stop();
xSemaphoreGive(mutexSdCardAccess);
}
return; /* Quit application */
}
} else if (mutexours) {
MSDD_Handler();
break;
default: // suppress warnings
// ignore events that were not mentioned above
ui_update(&evt);
break;
}
}
}
......
......@@ -36,22 +36,23 @@ static void spinbox_event(struct ui_widget *w, const struct event *evt)
{
struct spinbox *s = (struct spinbox*) w->data;
if(s->active && evt->type == BUTTON_PRESSED) {
if(evt->data.button == BUT_BR) {
if(s->chars[s->value_idx + 1] != 0) {
++s->value_idx;
} else {
s->value_idx = 0;
}
w->flags |= WF_DIRTY;
} else if(evt->data.button == BUT_BL) {
if(s->value_idx > 0) {
--s->value_idx;
} else {
s->value_idx = strlen(s->chars) - 1;
}
w->flags |= WF_DIRTY;
if(s->active && evt->type != BUTTON_PRESSED)
return;
if(evt->data.button == BUT_BR) {
if(s->chars[s->value_idx + 1] != 0) {
++s->value_idx;
} else {
s->value_idx = 0;
}
w->flags |= WF_DIRTY;
} else if(evt->data.button == BUT_BL) {
if(s->value_idx > 0) {
--s->value_idx;
} else {
s->value_idx = strlen(s->chars) - 1;
}
w->flags |= WF_DIRTY;
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment