void main_app_handle_button_up() { if (!button_held) { pulse_cancel_timer(&button_timer_id); if (current_screen == SCREEN_CLOCK) { cancel_sleep(); reset_game(); pulse_blank_canvas(); current_screen = SCREEN_GAME_OVER; printf("Click to start.\n\n\nClick while \nyou're in the \nair to do a \ndouble jump!"); prepare_to_sleep(); } else if (current_screen == SCREEN_GAME_OVER) { time_now_ms = pulse_get_millis(); if (time_now_ms - time_last_box_drawn_ms >= 500) { cancel_sleep(); pulse_blank_canvas(); current_screen = SCREEN_GAMEPLAY; } } else if (current_screen == SCREEN_GAMEPLAY) press = false; } else button_held = false; }
void main_app_handle_button_down() { pulse_blank_canvas(); if (state == 0) get_ready(); else if (state == 1) { pulse_cancel_timer(&hold_timer_value); state = 0; printf("XXX Too soon XXX\n\n"); printf("click to try \nagain"); printf("\n\n\n\n\n\n\n\n\n\n\nBest: %dms",best_time); } else if (state == 2) { state = 0; int reaction_time = (int)pulse_get_millis() - start_time; printf("You reacted in \n\n%d millisecs\n\n",reaction_time); printf("Click to try \nagain"); if (reaction_time < best_time) best_time = reaction_time; printf("\n\n\n\n\n\n\n\n\n\nBest: %dms",best_time); } }
void main_app_handle_button_up() { if (!button_held) { pulse_cancel_timer(&button_timer_id); if (current_screen == SCREEN_CLOCK) { cancel_sleep(); pulse_blank_canvas(); reset_game(); current_screen = SCREEN_GAME_OVER; printf("\n\n\n\n\n Click to start"); prepare_to_sleep(); } else if (current_screen == SCREEN_GAME_OVER) { time_now_ms = pulse_get_millis(); // Check if it's been at least 500 ms since the game ended to prevent accidental clicks if (time_now_ms - time_last_box_drawn_ms > 500) { cancel_sleep(); pulse_blank_canvas(); current_screen = SCREEN_GAMEPLAY; } } else if (current_screen == SCREEN_GAMEPLAY) press = false; } else button_held = false; }
void display_message(string message) { uint32_t interval = pulse_get_millis(); pulse_blank_canvas(); printf("%s\n", message); printf("Main timer:\n%d\n", interval); }
static void wakeup(void *arg) { pulse_oled_set_brightness(100); pulse_blank_canvas(); not_charging = pulse_get_millis(); shutdown_scheduled = 0; //srand(pulse_get_millis()); }
void main_app_loop() { now_ms = pulse_get_millis(); if (now_ms - interval_start_time_ms > interval_length_ms) { if (display_mode == ANSWER_MODE) { set_time_mode(); } update_time_display(); } }
void main_app_handle_hardware_update( enum PulseHardwareEvent event ) { switch (event) { case BATTERY_CHARGING: // Erase the last non-charging time to avoid flakey power not_charging = 0; break; case BATTERY_NOT_CHARGING: // Record the time that the state was toggled. not_charging = pulse_get_millis(); break; default: break; } }
void go(int t) { state = 2; printf("GO",t); start_time = (int)pulse_get_millis(); }
void main_app_loop() { if (current_screen == SCREEN_GAMEPLAY) { time_now_ms = pulse_get_millis(); if (time_now_ms - time_last_box_drawn_ms >= game_speed) { score++; move_surfaces(); int this_height = ball_y; ceiling = false; if (jump_ticks > 0) { clear_ball(ball_x, ball_y); if (ball_y-15 >=2) { ball_y = ball_y - 2; jump_ticks--; } else { jump_ticks--; ceiling = true; } } else if (ball_y < SCREEN_HEIGHT-112) { if ((ball_y+1 < SCREEN_HEIGHT-112) || ((surface_start_x[6]-4 > 20) || (surface_length_x[6]+surface_start_x[6] < 20))) { clear_ball(ball_x, ball_y); ball_y = ball_y + 2; } } else if (ball_y < SCREEN_HEIGHT-96) { if ((ball_y+1 < SCREEN_HEIGHT-96) || ((surface_start_x[5]-4 > 20) || (surface_length_x[5]+surface_start_x[5] < 20))) { clear_ball(ball_x, ball_y); ball_y = ball_y + 2; } } else if (ball_y < SCREEN_HEIGHT-80) { if ((ball_y+1 < SCREEN_HEIGHT-80) || ((surface_start_x[4]-4 > 20) || (surface_length_x[4]+surface_start_x[4] < 20))) { clear_ball(ball_x, ball_y); ball_y = ball_y + 2; } } else if (ball_y < SCREEN_HEIGHT-64) { if ((ball_y+1 < SCREEN_HEIGHT-64) || ((surface_start_x[3]-4 > 20) || (surface_length_x[3]+surface_start_x[3] < 20))) { clear_ball(ball_x, ball_y); ball_y = ball_y + 2; } } else if (ball_y < SCREEN_HEIGHT-48) { if ((ball_y+1 < SCREEN_HEIGHT-48) || ((surface_start_x[2]-4 > 20) || (surface_length_x[2]+surface_start_x[2] < 20))) { clear_ball(ball_x, ball_y); ball_y = ball_y + 2; } } else if (ball_y < SCREEN_HEIGHT-32) { if ((ball_y+1 < SCREEN_HEIGHT-32) || ((surface_start_x[1]-4 > 20) || (surface_length_x[1]+surface_start_x[1] < 20))) { clear_ball(ball_x, ball_y); ball_y = ball_y + 2; } } else if (ball_y < SCREEN_HEIGHT-16) { if ((ball_y+1 < SCREEN_HEIGHT-16) || ((surface_start_x[0]-4 > 20) || (surface_length_x[0]+surface_start_x[0] < 20))) { clear_ball(ball_x, ball_y); ball_y = ball_y + 2; } } else { clear_ball(ball_x, ball_y); ball_y = ball_y + 2; } draw_ball(ball_x, ball_y, green); if ((this_height == ball_y) && (!ceiling)) { jumps_available = 2; } if (ball_y >= SCREEN_HEIGHT-1) { game_over(); } time_last_box_drawn_ms = time_now_ms; } else if (current_screen == SCREEN_CLOCK) { pulse_get_time_date(¤t_time); } } }
void set_answer_mode() { display_mode = ANSWER_MODE; interval_length_ms = ANSWER_INTERVAL_LENGTH_MS; interval_start_time_ms = pulse_get_millis(); }
void set_time_mode() { display_mode = TIME_MODE; interval_length_ms = TIME_UPDATE_INTERVAL_LENGTH_MS; interval_start_time_ms = pulse_get_millis(); }
// Main loop. void main_app_loop() { if (current_screen == SCREEN_GAMEPLAY) { // Find out how long the processor has been active (since boot or since sleep) time_now_ms = pulse_get_millis(); // Check if it's been at least 10 ms since the box was last drawn if (time_now_ms - time_last_box_drawn_ms >= game_speed) { score++; // Change the color and speed up the walls when certain scores are reached switch(score) { case 800: wall_color = teal; game_speed-=2; break; case 1600: wall_color = blue; game_speed-=2; break; case 2400: wall_color = purple; game_speed-=2; break; case 3200: wall_color = pink; game_speed-=2; break; case 4000: wall_color = orange; game_speed-=2; break; case 4800: wall_color = red; game_speed-=2; break; } // Erase the old ball and walls by drawing over them draw_ball(ball_x,ball_y, COLOR_BLACK24); for (int i = 0; i < NUM_WALLS; i++) draw_wall(wall_y[i],wall_gap_x[i], COLOR_BLACK24); // Move the ball based on user input if(press && ball_x < SCREEN_WIDTH - BALL_SIZE) ball_x++; else if (!press && ball_x > 0) ball_x--; // Move the walls up for (int i = 0; i < NUM_WALLS; i++) move_wall(i); // Check for collisions between the ball and the wall bool collision = false; for (int i = 0; i < NUM_WALLS; i++) { if ((ball_y == wall_y[i] - BALL_SIZE + 1 || ball_y == wall_y[i] - BALL_SIZE)&& (ball_x < wall_gap_x[i] || ball_x > wall_gap_x[i] + GAP_WIDTH - BALL_SIZE)) { ball_y = wall_y[i] - BALL_SIZE; collision = true; } } // check if ball reached the top if (ball_y == start_y) game_over(); else { if (!collision && ball_y < SCREEN_HEIGHT-BALL_SIZE-1) ball_y = (ball_y + 1); // Draw the new box and walls draw_game_elements(); // update the time_last_box_draw_ms variable time_last_box_drawn_ms = time_now_ms; } } } else if (current_screen == SCREEN_CLOCK) pulse_get_time_date(¤t_time); }
void main_app_loop(void) { uint8_t umpl_got; const uint64_t millis = pulse_get_millis(); // If the not-charging state has not been toggled in the last // 30 seconds, schedule a power down soon. if (not_charging && millis - not_charging > 60000) { if (!shutdown_scheduled) pulse_update_power_down_timer(1); shutdown_scheduled = 1; return; } /* The umpl_input_handler is nonblocking. * It will read a packet off the debug serial * port, and copy the rotation matrix payload * to the provided buffer. */ umpl_got = umpl_input_handler(default_m); if (umpl_got) dbg_putc((char)0); // (for debugging) camera_setup_rmat(&camera, 4000, rmats[selected_mat]); #if 1 pixel_t temp_pixels[ARRAY_COUNT(pixels)]; wireframe_draw( &camera, ARRAY_COUNT(vertices), vertices, ARRAY_COUNT(edges), edges, pixels, temp_pixels ); #else for (int i = 0 ; i < ARRAY_COUNT(vertices) ; i++) { const vertex_t * const v = &vertices[i]; pixel_t * const p = &pixels[i]; draw_pixel(COLOR_BLACK24, p->x, p->y); camera_project(&camera, v, p); draw_pixel(COLOR_GREEN, p->x, p->y); } #endif // Update the clock once per minute struct pulse_time_tm now; pulse_get_time_date(&now); if (last_sec == now.tm_sec) return; last_sec = now.tm_sec; if (last_min != now.tm_min) pulse_blank_canvas(); last_min = now.tm_min; char buf[16]; sprintf(buf, "%02d:%02d", now.tm_hour, now.tm_min ); draw_monostring(8, VSCREEN_HEIGHT - FONT_HEIGHT - 1, COLOR_GREEN, buf); }