void game_end() { //turns off all communication with Node2 timer_disable(); //can_play_music(); oled_clear_screen(); //print GAME OVER oled_pos(3, 4); oled_printf("GAME OVER"); _delay_ms(1500); oled_clear_screen(); oled_pos(2, 2); oled_printf("Final score:"); oled_pos(4, 7); oled_printf("%d", game_score); printf("Final score: %d\n", game_score); oled_pos(7, 0); oled_printf("press any button"); while ((!button_read(2) && !button_read(1) && button_read(3)) ); //wait for button press _delay_ms(100); oled_clear_screen(); }
void fsm_refresh_screen(){ fsm_send_position(); joy_position_t joy_pos; switch (g_state) { case STATE_MENU: break; case STATE_GAME: if(g_game_controller == JOYSTICK) { fsm_send_position(); } break; case STATE_GAME_OVER: break; case STATE_CALIBRATE: joy_pos = joy_get_position(); oled_pos(1,8); fprintf(FONT5,"X: %d %% \nY: %d %% ", joy_pos.x, joy_pos.y); //fprintf(FONT5,"X: %d %% \nY: %d %% \nLeft: %d \nRight: %d ", // joy_pos.x, joy_pos.y, adc_read(4), adc_read(3)); break; case STATE_DEBUG: break; case STATE_PID: break; default: break; } }
void fsm_can(can_message_t *msg){ switch (msg->id) { case MENU_ID: g_state = msg->data[0]; break; case GAME_ID: break; case SCORE_ID: if(msg->data[0]){ add_score(); print_score(); } else{ g_state = STATE_GAME_OVER; oled_print_game_over(); play_melody(0); } break; case CONTROLLER_ID: break; case SLIDER_ID: if(g_state == STATE_CALIBRATE){ oled_pos(3,8); fprintf(FONT5,"Left: %d %% \nRight: %d %% ", msg->data[0], msg->data[1]); } break; default: break; } }
void game_keep_score() { if (ball_rolling) { game_score_counter++; } if (game_score_counter > 7) { game_score++; game_score_counter = 0; oled_pos(3, 11); oled_printf("%d", game_score); } }
void game_start() { game_reset_score(); game_not_lost = 1; /* oled_clear_screen(); oled_pos(3,2); oled_printf("remove ball"); _delay_ms(1500);*/ oled_clear_screen(); oled_pos(3, 2); oled_printf("Score: "); //flush pending game_lost messages can_data_receive(); can_data_receive(); timer_enable(); ball_rolling = 0; }
static void print_score(){ oled_pos(4,36); fprintf(FONT5, "%d ", g_score); }
int main(void) { dhcp dhcp_session; int dhcp_state; http_server http; http_socket httpsock[4]; http_content httpcontent[4]; char oled_msg[17]; char *pnt; int step; api_init(); uart_puts(" * eCowLogic firmware \r\n"); hw_systick( hw_getfreq() / 1000 ); dhcp_session.socket = 2; dhcp_session.buffer = (u8 *)buffer_dhcp; dhcp_init(&dhcp_session); oled_pos(1, 0); oled_puts("Reseau (DHCP) "); step = 0; while(1) { dhcp_state = dhcp_run(&dhcp_session); if (dhcp_state == DHCP_IP_LEASED) break; step++; oled_pos(1, 13); if (step == 1) oled_puts(". "); if (step == 2) oled_puts(".. "); if (step == 3) oled_puts("..."); if (step == 4) { step = 0; dhcp_session.tick_1s++; uart_putc('.'); oled_puts(" "); } delay(250); } pnt = oled_msg; pnt += b2ds(pnt, dhcp_session.dhcp_my_ip[0]); *pnt++ = '.'; pnt += b2ds(pnt, dhcp_session.dhcp_my_ip[1]); *pnt++ = '.'; pnt += b2ds(pnt, dhcp_session.dhcp_my_ip[2]); *pnt++ = '.'; pnt += b2ds(pnt, dhcp_session.dhcp_my_ip[3]); for ( ; pnt < (oled_msg + 16); pnt++) *pnt = ' '; oled_msg[16] = 0; uart_puts("DHCP: LEASED ! "); uart_puts(oled_msg); uart_puts("\r\n"); oled_pos(1, 0); oled_puts(oled_msg); spi_init(); pld_init(); //net_init(); /* Init HTTP content */ strcpy(httpcontent[0].name, "/pld"); httpcontent[0].wildcard = 0; httpcontent[0].cgi = cgi_ng_pld; httpcontent[0].next = &httpcontent[1]; /* Init HTTP content */ strcpy(httpcontent[1].name, "/spi"); httpcontent[1].wildcard = 0; httpcontent[1].cgi = cgi_spi; httpcontent[1].next = &httpcontent[2]; /* Init HTTP content */ strcpy(httpcontent[2].name, "/infos"); httpcontent[2].wildcard = 0; httpcontent[2].cgi = cgi_info; httpcontent[2].next = &httpcontent[3]; /* Init HTTP content */ strcpy(httpcontent[3].name, "/"); httpcontent[3].wildcard = 1; httpcontent[3].cgi = cgi_ng_page; httpcontent[3].next = 0; /* Init HTTP socket */ httpsock[0].id = 4; httpsock[0].state = 0; httpsock[0].server = &http; httpsock[0].next = &httpsock[1]; /* Init HTTP socket */ httpsock[1].id = 5; httpsock[1].state = 0; httpsock[1].server = &http; httpsock[1].next = &httpsock[2]; /* Init HTTP socket */ httpsock[2].id = 6; httpsock[2].state = 0; httpsock[2].server = &http; httpsock[2].next = &httpsock[3]; /* Init HTTP socket */ httpsock[3].id = 7; httpsock[3].state = 0; httpsock[3].server = &http; httpsock[3].next = 0; /* Init the new HTTP layer */ http.port = 80; http.err404 = 0; http.err403 = 0; http.keepalive = 10; http.socks = &httpsock[0]; http.contents = &httpcontent[0]; http_init(&http); while(1) { http_run(&http); } }
void oled_submenu2(){ volatile position joy_pos; joy_pos.button_pressed = 150; oled_clear_screen(); /*FIRST MENU*/ // header char header[] = "YOU ARE TRAPPED!"; // entry one char entry1[] = "NEVER"; // entry two char entry2[] = "GONNA"; // entry three char entry3[] = "GIVE YOU UP"; // arrow starts on entry one. Movement of joystick along Y axis changes this int arrow = menu_entry_one; int prev_arrow; int navigation_counter = 999; int started = 0; //Define menu pointer oled_pos(menu_entry_one, arrow_column); oled_print("<<"); sound_play(ROLL); while(!started){ oled_goto_line(menu_header); oled_print(header); oled_goto_line(menu_entry_one); oled_print(entry1); oled_goto_line(menu_entry_two); oled_print(entry2); oled_goto_line(menu_entry_three); oled_print(entry3); if(joystickDirY() != NEUTRAL){ navigation_counter++; } else{ navigation_counter = 1; } if(navigation_counter % 100 == 0){ prev_arrow = arrow; if(joystickDirY() == UP){ if(arrow == menu_entry_one){ arrow = menu_entry_three; } else{ arrow--; } } else if(joystickDirY() == DOWN){ if(arrow == menu_entry_three){ arrow = menu_entry_one; } else{ arrow++; } } oled_goto_line(prev_arrow); oled_clear_line(); oled_goto_line(arrow); oled_changeColumn(arrow_column); oled_print("<<"); oled_changeColumn(0); navigation_counter++; } //Handle button presses joy_pos = joystickPos(); if(joy_pos.button_pressed < button_margin){ while(joy_pos.button_pressed < button_margin){ //Prevent button spam joy_pos = joystickPos(); } started = 1; button_pressed = 0; } } return 0; }
int oled_submenu1(){ volatile position joy_pos; joy_pos.button_pressed = 150; oled_clear_screen(); /*FIRST MENU*/ // header char header[] = "MUSIC MENU"; // entry one char entry1[] = "POKEMON"; // entry two char entry2[] = "SUPER MARIO"; // entry three char entry3[] = "ZELDA"; // arrow starts on entry one. Movement of joystick along Y axis changes this int arrow = menu_entry_one; int prev_arrow; int navigation_counter = 999; int started = 0; //Define menu pointer oled_pos(menu_entry_one, arrow_column); oled_print("<<"); sound_play(POKEMON); while(!started){ oled_goto_line(menu_header); oled_print(header); oled_goto_line(menu_entry_one); oled_print(entry1); oled_goto_line(menu_entry_two); oled_print(entry2); oled_goto_line(menu_entry_three); oled_print(entry3); if(joystickDirY() != NEUTRAL){ navigation_counter++; } else{ navigation_counter = 1; } if(navigation_counter % 100 == 0){ prev_arrow = arrow; if(joystickDirY() == UP){ if(arrow == menu_entry_one){ arrow = menu_entry_three; } else{ arrow--; } } else if(joystickDirY() == DOWN){ if(arrow == menu_entry_three){ arrow = menu_entry_one; } else{ arrow++; } } //Let user listen to currently selected song if(arrow == menu_entry_one){ sound_play(POKEMON); } else if(arrow == menu_entry_two){ sound_play(MARIO); } else if(arrow == menu_entry_three){ sound_play(ZELDA); } else { sound_play(ROLL); } oled_goto_line(prev_arrow); oled_clear_line(); oled_goto_line(arrow); oled_changeColumn(arrow_column); oled_print("<<"); oled_changeColumn(0); navigation_counter++; } //Handle button presses joy_pos = joystickPos(); if(joy_pos.button_pressed < button_margin){ while(joy_pos.button_pressed < button_margin){ //Prevent button spam joy_pos = joystickPos(); } if(arrow == menu_entry_one){ ingame_song = POKEMON; } else if(arrow == menu_entry_two){ ingame_song = MARIO; } else if(arrow == menu_entry_three){ ingame_song = ZELDA; } started = 1; button_pressed = 0; } } return 0; }
int oled_navigate(){ volatile position joy_pos; joy_pos.button_pressed = 150; oled_clear_screen(); /*FIRST MENU*/ // header char header[] = "MENU"; // entry one char entry1[] = "Start game"; // entry two char entry2[] = "Change music"; // entry three char entry3[] = "DO NOT PRESS!"; // arrow starts on entry one. Movement of joystick along Y axis changes this int arrow = menu_entry_one; int prev_arrow; int navigation_counter = 999; int started = 0; //Define menu pointer oled_pos(menu_entry_one, arrow_column); oled_print("<<"); sound_play(MENU); while(!started){ oled_goto_line(menu_header); oled_print(header); oled_goto_line(menu_entry_one); oled_print(entry1); oled_goto_line(menu_entry_two); oled_print(entry2); oled_goto_line(menu_entry_three); oled_print(entry3); if(joystickDirY() != NEUTRAL){ navigation_counter++; } else{ navigation_counter = 1; } if(navigation_counter % 100 == 0){ prev_arrow = arrow; if(joystickDirY() == UP){ if(arrow == menu_entry_one){ arrow = menu_entry_three; } else{ arrow--; } } else if(joystickDirY() == DOWN){ if(arrow == menu_entry_three){ arrow = menu_entry_one; } else{ arrow++; } } oled_goto_line(prev_arrow); oled_clear_line(); oled_goto_line(arrow); oled_changeColumn(arrow_column); oled_print("<<"); oled_changeColumn(0); navigation_counter++; } //Handle button presses joy_pos = joystickPos(); if(joy_pos.button_pressed < button_margin){ while(joy_pos.button_pressed < button_margin){ //Prevent button spam joy_pos = joystickPos(); } if(arrow == menu_entry_one){ started = 1; //A game request has been received, so we should stop interfacing } else if(arrow == menu_entry_two){ oled_submenu1(); oled_clear_screen(); //Redefine menu pointer oled_goto_line(arrow); oled_changeColumn(arrow_column); oled_print("<<"); oled_changeColumn(0); sound_play(MENU); } else if(arrow == menu_entry_three){ oled_submenu2(); oled_clear_screen(); //Redefine menu pointer oled_goto_line(arrow); oled_changeColumn(arrow_column); oled_print("<<"); oled_changeColumn(0); sound_play(MENU); } button_pressed = 0; } } return 0; }
static void upd_flash(tftp *tftp) { char str[17]; int tftp_block; u32 waddr; u32 sector, last_sector; int len; tftp_init(tftp); tftp->filename = upd_mem; waddr = 0; last_sector= 0xFFFFFFFF; while(1) { tftp_run(tftp); if ( (tftp->state == 2) || (tftp->state == 3)) { if (tftp->lastblock != tftp_block) { tftp_block = tftp->lastblock; strcpy(str, "Load flash "); b2ds(&str[11], tftp_block); oled_pos(0, 0); oled_puts(str); sector = (tftp_block << 9) & 0xFFFF0000; if (sector != last_sector) { flash_erase(sector); last_sector = sector; } uart_puts(str); uart_putc('\r'); len = 0; if (tftp->length > 4) { u8 *dat; dat = (u8 *)&tftp->data[4]; len = tftp->length - 4; if (len > 256) { flash_write(waddr, dat, 256); len -= 256; /* Update remaining data length */ dat += 256; /* Move the source pointer */ waddr += 256; /* Update the dest address */ /* Wait for the write transfer ends */ while(flash_status() & 1) ; } flash_write(waddr, dat, len); /* Wait for the write transfer ends */ while(flash_status() & 1) ; /* Update write address for next packet */ waddr += len; } } tftp_ack(tftp); } if (tftp->state == 3) { uart_crlf(); break; } if (tftp->state == 98) { uart_puts("TFTP timeout, restart\r\n"); oled_pos(0, 0); oled_puts("TFTP: timeout!"); tftp->timestamp = 0x3000; tftp->state = 0; } if (tftp->state == 99) { uart_puts("upd_firmware() TFTP error 99\r\n"); break; } } }