Make the app do what it's meant to (alarm now requires correct equation to shut off)
This commit is contained in:
+85
-12
@@ -55,6 +55,9 @@ static GBitmap *s_check_bmp;
|
||||
static GColor s_setter_highlight_color;
|
||||
static uint8_t s_highlight_pos = 0;
|
||||
static struct TheTime s_the_time;
|
||||
//// alarm
|
||||
static uint8_t s_solution_indices[3] = {8, 8, 8};
|
||||
static uint8_t s_selected_indices[3] = {9, 9, 9};
|
||||
|
||||
// constants
|
||||
static const uint8_t s_edge_bar_height = ((PBL_DISPLAY_HEIGHT / 7) * 2);
|
||||
@@ -376,10 +379,9 @@ static void alarm_highlight_layer_update_proc(Layer *layer, GContext *ctx) {
|
||||
}
|
||||
|
||||
static uint16_t menu_get_num_rows(MenuLayer *menu_layer, uint16_t section_index, void *context) {
|
||||
switch (s_highlight_pos) {
|
||||
case 0:
|
||||
if (s_highlight_pos == 0) {
|
||||
return 3;
|
||||
default:
|
||||
} else {
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
@@ -408,6 +410,7 @@ static void menu_select(MenuLayer *menu_layer, MenuIndex *cell_index, void *cont
|
||||
case 2:
|
||||
text_layer_set_text(s_drop_txt_under_layer, s_options_under[cell_index->row]);
|
||||
}
|
||||
s_selected_indices[s_highlight_pos] = cell_index->row;
|
||||
window_stack_remove(s_drop_window, true);
|
||||
}
|
||||
|
||||
@@ -528,33 +531,97 @@ static void alarm_window_load() {
|
||||
//// display 2 side lengths to the user
|
||||
static char side_a_buffer[8], side_b_buffer[8], side_c_buffer[8], angle_A_buffer[8], angle_B_buffer[8], angle_C_buffer[8];
|
||||
uint8_t ignored_side = rand() % 3;
|
||||
uint8_t sin_index = rand() % 2;
|
||||
uint8_t cos_index = rand() % 2;
|
||||
uint8_t tan_index = rand() % 2;
|
||||
switch (ignored_side) {
|
||||
case 0:
|
||||
// APP_LOG(APP_LOG_LEVEL_DEBUG, "b,c");
|
||||
snprintf(side_b_buffer, sizeof(side_b_buffer), "%u", s_triangle_layer->side_b);
|
||||
snprintf(side_c_buffer, sizeof(side_c_buffer), "%u", s_triangle_layer->side_c);
|
||||
s_options_over[0] = side_b_buffer;
|
||||
s_options_over[1] = side_c_buffer;
|
||||
s_options_under[0] = side_b_buffer;
|
||||
s_options_under[1] = side_c_buffer;
|
||||
|
||||
// store solution
|
||||
s_solution_indices[0] = 2; // tan/cot
|
||||
if (s_triangle_layer->theta_angle_is_left) {
|
||||
if (tan_index == 0) { // tan
|
||||
s_solution_indices[1] = 0; // b (opposite)
|
||||
s_solution_indices[2] = 1; // c (adjacent)
|
||||
} else { // cot
|
||||
s_solution_indices[1] = 1; // c (adjacent)
|
||||
s_solution_indices[2] = 0; // b (opposite)
|
||||
}
|
||||
} else {
|
||||
if (tan_index == 0) { // tan
|
||||
s_solution_indices[1] = 1; // c (opposite)
|
||||
s_solution_indices[2] = 0; // b (adjacent)
|
||||
} else { // cot
|
||||
s_solution_indices[1] = 0; // b (adjacent)
|
||||
s_solution_indices[2] = 1; // c (opposite)
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
case 1:
|
||||
// APP_LOG(APP_LOG_LEVEL_DEBUG, "a,c");
|
||||
snprintf(side_a_buffer, sizeof(side_a_buffer), "%u", s_triangle_layer->side_a);
|
||||
snprintf(side_c_buffer, sizeof(side_c_buffer), "%u", s_triangle_layer->side_c);
|
||||
s_options_over[0] = side_a_buffer;
|
||||
s_options_over[1] = side_c_buffer;
|
||||
s_options_under[0] = side_a_buffer;
|
||||
s_options_under[1] = side_c_buffer;
|
||||
|
||||
// store solution
|
||||
if (s_triangle_layer->theta_angle_is_left) {
|
||||
s_solution_indices[0] = 1; // cos/sec
|
||||
if (cos_index == 0) { // cos
|
||||
s_solution_indices[1] = 1; // c (adjacent)
|
||||
s_solution_indices[2] = 0; // a (hypotenuse)
|
||||
} else { // sec
|
||||
s_solution_indices[1] = 0; // a (hypotenuse)
|
||||
s_solution_indices[2] = 1; // c (adjacent)
|
||||
}
|
||||
} else {
|
||||
s_solution_indices[0] = 0; // sin/csc
|
||||
if (sin_index == 0) { // sin
|
||||
s_solution_indices[1] = 1; // c (opposite)
|
||||
s_solution_indices[2] = 0; // a (hypotenuse)
|
||||
} else { // csc
|
||||
s_solution_indices[1] = 0; // a (hypotenuse)
|
||||
s_solution_indices[2] = 1; // c (opposite)
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
case 2:
|
||||
// APP_LOG(APP_LOG_LEVEL_DEBUG, "a,b");
|
||||
snprintf(side_a_buffer, sizeof(side_a_buffer), "%u", s_triangle_layer->side_a);
|
||||
snprintf(side_b_buffer, sizeof(side_b_buffer), "%u", s_triangle_layer->side_b);
|
||||
s_options_over[0] = side_a_buffer;
|
||||
s_options_over[1] = side_b_buffer;
|
||||
s_options_under[0] = side_a_buffer;
|
||||
s_options_under[1] = side_b_buffer;
|
||||
|
||||
// store solution
|
||||
if (s_triangle_layer->theta_angle_is_left) {
|
||||
s_solution_indices[0] = 0; // sin/csc
|
||||
if (sin_index == 0) { // sin
|
||||
s_solution_indices[1] = 1; // b (opposite)
|
||||
s_solution_indices[2] = 0; // a (hypotenuse)
|
||||
} else { // csc
|
||||
s_solution_indices[1] = 0; // a (hypotenuse)
|
||||
s_solution_indices[2] = 1; // b (opposite)
|
||||
}
|
||||
} else {
|
||||
s_solution_indices[0] = 1;
|
||||
if (cos_index == 0) { // cos
|
||||
s_solution_indices[1] = 1; // b (adjacent)
|
||||
s_solution_indices[2] = 0; // a (hypotenuse)
|
||||
} else { // sec
|
||||
s_solution_indices[1] = 0; // a (hypotenuse)
|
||||
s_solution_indices[2] = 1; // b (adjacent)
|
||||
}
|
||||
}
|
||||
}
|
||||
text_layer_set_text(s_side_a_txt_layer, side_a_buffer);
|
||||
text_layer_set_text(s_side_b_txt_layer, side_b_buffer);
|
||||
@@ -562,9 +629,9 @@ static void alarm_window_load() {
|
||||
|
||||
// drop menus
|
||||
//// determine trigonometric function options
|
||||
s_sin = s_sin_arr[rand() % 2];
|
||||
s_cos = s_cos_arr[rand() % 2];
|
||||
s_tan = s_tan_arr[rand() % 2];
|
||||
s_sin = s_sin_arr[sin_index];
|
||||
s_cos = s_cos_arr[cos_index];
|
||||
s_tan = s_tan_arr[tan_index];
|
||||
//// set up menu options
|
||||
s_options_function[0] = s_sin;
|
||||
s_options_function[1] = s_cos;
|
||||
@@ -636,8 +703,14 @@ static void alarm_select_click_handler(void *recognizer, void *ctx) {
|
||||
window_stack_push(s_drop_window, true);
|
||||
}
|
||||
|
||||
// DEBUG: logic will eventually be mapped to when triangle is solved
|
||||
static void alarm_select_hold_handler(void *recognizer, void *ctx) {
|
||||
// check solution
|
||||
for (int i = 0; i < 3; ++i) {
|
||||
if (s_selected_indices[i] != s_solution_indices[i]) {
|
||||
return; // TODO pop-up telling the user they are wrong
|
||||
}
|
||||
}
|
||||
|
||||
wakeup_cancel_all();
|
||||
int8_t status = schedule_main_alarm();
|
||||
while (status < 0) {
|
||||
@@ -651,7 +724,7 @@ static void alarm_select_hold_handler(void *recognizer, void *ctx) {
|
||||
}
|
||||
status = schedule_main_alarm();
|
||||
}
|
||||
window_stack_pop_all(true);
|
||||
window_stack_pop_all(true); // TODO pop-up telling user the answer & their previous 5 times
|
||||
}
|
||||
|
||||
static void alarm_click_config_provider(void *ctx) {
|
||||
@@ -659,7 +732,7 @@ static void alarm_click_config_provider(void *ctx) {
|
||||
window_single_click_subscribe(BUTTON_ID_UP, alarm_up_click_handler);
|
||||
window_single_click_subscribe(BUTTON_ID_DOWN, alarm_down_click_handler);
|
||||
window_single_click_subscribe(BUTTON_ID_SELECT, alarm_select_click_handler);
|
||||
window_long_click_subscribe(BUTTON_ID_SELECT, 5000, alarm_select_hold_handler, NULL);
|
||||
window_long_click_subscribe(BUTTON_ID_SELECT, 2500, alarm_select_hold_handler, NULL);
|
||||
}
|
||||
|
||||
static void init() {
|
||||
|
||||
Reference in New Issue
Block a user