void fsm_left_button(){ switch (g_state) { case STATE_MENU: if(menu_home()){ play_melody(MENU_SOUND); } g_state = STATE_MENU; break; case STATE_GAME: menu_home(); g_state = STATE_MENU; play_melody(MENU_SOUND); _delay_ms(50); send_state(g_state); break; case STATE_GAME_OVER: break; case STATE_CALIBRATE: menu_home(); g_state = STATE_MENU; break; case STATE_DEBUG: menu_home(); g_state = STATE_MENU; break; case STATE_PID: break; default: break; } }
int main(void) { uint8_t app_index = 0; init_hw(); // cycle through apps for(;;) { reset_hw(); run_app(&apps[app_index]); reset_hw(); if(app_direction > 0) { play_melody(up_mldy, ARRAY_SIZE(up_mldy), 4, 100); app_index++; if(apps[app_index].run == NULL) { app_index = 0; } } else { play_melody(down_mldy, ARRAY_SIZE(down_mldy), 4, 100); if(app_index == 0) { app_index = MAX_APPS - 1; while(apps[app_index].run == NULL) --app_index; } else { app_index--; } } } }
void fsm_right_button(){ switch (g_state) { case STATE_MENU: if(menu_next()){ play_melody(MENU_SOUND); } _delay_ms(50); if(menu_get_index() == 0){ if(menu_get_arrow_position == 2){ oled_print_pong(); } else if(menu_get_arrow_position() == 3){ oled_print_game_over(); } } else if(menu_get_index() == 4){ g_state = STATE_CALIBRATE; } else if(menu_get_index() == 6){ g_state = STATE_DEBUG; } else if(menu_get_index() == 7){ g_game_melody = menu_get_arrow_position(); play_melody(g_game_melody); } else if(menu_get_index() == 2){ new_game(JOYSTICK); } else if(menu_get_index() == 3){ new_game(PLAYSTATION); } break; case STATE_GAME: // Send pulse to solenoid set_bit(DDRD, PD4); _delay_ms(200); clear_bit(DDRD,PD4); break; case STATE_GAME_OVER: break; case STATE_CALIBRATE: joy_calibrate(); break; case STATE_DEBUG: if(menu_get_arrow_position() == 1){ send_state(STATE_DEBUG); printf("Debug Mode\n"); } break; case STATE_PID: break; default: break; } }
void fsm_joy_right(){ switch (g_state) { case STATE_MENU: if(menu_next()){ play_melody(MENU_SOUND); } if(menu_get_index() == 0){ if(menu_get_arrow_position == 2){ oled_print_pong(); } else if(menu_get_arrow_position() == 3){ oled_print_game_over(); } } else if(menu_get_index() == 4){ g_state = STATE_CALIBRATE; } else if(menu_get_index() == 6){ g_state = STATE_DEBUG; } else if(menu_get_index() == 7){ g_game_melody = menu_get_arrow_position(); play_melody(g_game_melody); } else if(menu_get_index() == 2){ new_game(JOYSTICK); } else if(menu_get_index() == 3){ new_game(PLAYSTATION); } break; case STATE_GAME: break; case STATE_GAME_OVER: break; case STATE_CALIBRATE: break; case STATE_DEBUG: if(menu_get_arrow_position() == 1){ send_state(STATE_DEBUG); printf("Debug Mode\n"); } break; case STATE_PID: break; default: break; } }
void fsm_joy_up(){ switch (g_state) { case STATE_MENU: if(menu_get_choices() != 0){ if(menu_get_arrow_position() != 1){ play_melody(MENU_SOUND); } menu_set_arrow_position(menu_get_arrow_position() -1); menu_print_arrow(); } break; case STATE_GAME: break; case STATE_GAME_OVER: break; case STATE_CALIBRATE: 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 fsm_joy_left(){ switch (g_state) { case STATE_MENU: if(menu_back()){ play_melody(MENU_SOUND); } break; case STATE_GAME: break; case STATE_GAME_OVER: g_state = STATE_MENU; menu_home(); break; case STATE_CALIBRATE: break; case STATE_DEBUG: menu_back(); g_state = STATE_MENU; break; case STATE_PID: g_state = STATE_MENU; break; default: break; } }
static void new_game(uint8_t controller){ g_state = STATE_GAME; g_game_controller = controller; send_controller(g_game_controller); play_melody(g_game_melody); reset_score(); print_score(); send_state(g_state); }
void fsm_init(){ oled_print_pong(); g_game_melody = 1; g_score = 0; g_state = STATE_MENU; // Play start-up tune play_melody(STARTUP_SOUND); _delay_ms(5000); menu_init(); menu_print(); menu_print_arrow(); }
/* * Play a song and wait for its completion in idle mode */ static void play_song_and_wait(const struct note *song, uint8_t size) { play_melody(song, size); sleep_until_melody_completes(); }
int recieve_string (void) { unsigned char start, stop; unsigned char buff; unsigned int i = 0; unsigned short kol_vo_not; unsigned char good_or_bad; unsigned char num_page; start = read_max(2, 0x102); stop = read_max(2, 0x103); buff = SBUF; RI = 0; if (!if_ri()) return 0; buff = SBUF; RI = 0; if (!(buff & 0x80)) { good_or_bad = buff & 0x40; kol_vo_not = (buff & 0x3f) << 8; if (!if_ri()) return 0; buff = SBUF; RI = 0; kol_vo_not += buff; while (kol_vo_not) { if (!if_ri()) return 0; buff = SBUF; RI = 0; if ((buff != start) && (buff != stop)) { write_max(4, 0x102+i, buff); i++; kol_vo_not--; } } write_max(4, 0x102+i, 0); if (good_or_bad) { num_page = 5; is_good_melody = 1; } else { num_page = 6; is_bad_melody = 1; } init_timer(); str_to_notes (num_page); play_melody (num_page); init_uart(); } else { init_timer(); if (buff & 0x40) { write_sram(2, 0x00, "Оки-доки! "); read_sram_to_lsd(2); if (is_good_melody) play_melody (5); else delay(65535); } else { write_sram(2, 0x00, "Фигня какая-то... "); read_sram_to_lsd(2); if (is_bad_melody) play_melody (6); else delay(65535); } write_sram(2, 0x00, "Введите пароль: "); read_sram_to_lsd(2); goto_x(0x40); init_uart(); } return 0; }