/** * Compares two times and acts on match (deadline) */ static void check_for_deadline(Time* current_time_struct, Time* target_time_struct) { if ((current_time_struct->hours == target_time_struct->hours) && (current_time_struct->minutes == target_time_struct->minutes) && (current_time_struct->seconds == target_time_struct->seconds)) { debug_printf (DEBUG_INFO, "* Alarm has been activated, decide what action to take!"); /* Decide what action to take from the selected item in the combo */ switch (cfg_get_single_value_as_int_with_default (config, "alarm-plugin", "action-id", 0)) { case 0: debug_printf (DEBUG_INFO, "* Attempting to play/pause"); play_song (); break; case 1: debug_printf (DEBUG_INFO, "* Attempting to stop"); stop_song (); break; case 2: debug_printf (DEBUG_INFO, "* Stopping and closing gmpc"); stop_song (); main_quit (); break; case 3: debug_printf (DEBUG_INFO, "* Closing gmpc only"); /* Friendly way of closing gmpc */ main_quit (); break; case 4: debug_printf (DEBUG_INFO, "* Shutting down system"); /* TODO: Nice way of halting a system */ break; case 5: debug_printf (DEBUG_INFO, "* Toggling random"); random_toggle (); break; } /* Disable timer, and thus the ticking timeout */ alarm_stop(); } }
uint8_t handle_fire(){ static uint16_t timer = 0; // for holdoff static uint16_t counter = 0; // for power uint16_t a; a=ADC_read(); if (a > config.fire_cheating){ cheat(); } if (a > config.fire_threshold && a < config.fire_cheating) { while(!my_random_number){ my_random_number = TMR0; } if(timer < config.fire_holdoff) { timer ++; } else { if(!config.power || counter <= config.power) { if(!counter) { green_led_on(); play_song((uint16_t*)fire_song,sizeof(fire_song)/sizeof(uint16_t),3000,!(config.power)); } Send_Byte(config.id); counter++; } else { led_off(); } } } else { led_off(); if(!config.power && counter) stop_song(); timer = 0; counter = 0; return 0; } return 1; }
void handle_music() { if(!PIR1bits.TMR1IF) return; if(cur_song_ptr >= cur_song_length) { if(cur_song_repeat) { cur_song_ptr=0; } else { stop_song(); return; } } tone(cur_song[cur_song_ptr]); TMR1 = -cur_song_duration; cur_song_ptr++; PIR1bits.TMR1IF=0; }
void jukebox( void ) { bool trigger_quit = false, // true when user wants to quit quitting = false; bool hide_text = false; bool fade_looped_songs = true, fading_song = false; bool stopped = false; bool fx = false; int fx_num = 0; int palette_fade_steps = 15; int diff[256][3]; init_step_fade_palette(diff, vga_palette, 0, 255); JE_starlib_init(); int fade_volume = tyrMusicVolume; for (; ; ) { if (!stopped && !audio_disabled) { if (songlooped && fade_looped_songs) fading_song = true; if (fading_song) { if (fade_volume > 5) { fade_volume -= 2; } else { fade_volume = tyrMusicVolume; fading_song = false; } set_volume(fade_volume, fxVolume); } if (!playing || (songlooped && fade_looped_songs && !fading_song)) play_song(mt_rand() % MUSIC_NUM); } setdelay(1); SDL_FillRect(VGAScreenSeg, NULL, 0); // starlib input needs to be rewritten JE_starlib_main(); push_joysticks_as_keyboard(); service_SDL_events(true); if (!hide_text) { char buffer[60]; if (fx) snprintf(buffer, sizeof(buffer), "%d %s", fx_num + 1, soundTitle[fx_num]); else snprintf(buffer, sizeof(buffer), "%d %s", song_playing + 1, musicTitle[song_playing]); const int x = VGAScreen->w / 2; #ifdef ANDROID draw_font_hv(VGAScreen, x, 170, "Press the Back button to quit the jukebox.", small_font, centered, 1, 0); draw_font_hv(VGAScreen, x, 180, "Touch to change the song being played.", small_font, centered, 1, 0); #else draw_font_hv(VGAScreen, x, 170, "Press ESC to quit the jukebox.", small_font, centered, 1, 0); draw_font_hv(VGAScreen, x, 180, "Arrow keys change the song being played.", small_font, centered, 1, 0); #endif draw_font_hv(VGAScreen, x, 190, buffer, small_font, centered, 1, 4); } if (palette_fade_steps > 0) step_fade_palette(diff, palette_fade_steps--, 0, 255); JE_showVGA(); wait_delay(); #ifdef ANDROID if (mousedown) { wait_noinput(true, true, true); newkey = true; if (mouse_x < 160) lastkey_sym = SDLK_LEFT; else lastkey_sym = SDLK_RIGHT; } #else // quit on mouse click Uint16 x, y; if (JE_mousePosition(&x, &y) > 0) trigger_quit = true; #endif if (newkey) { switch (lastkey_sym) { case SDLK_ESCAPE: // quit jukebox case SDLK_q: trigger_quit = true; break; case SDLK_SPACE: hide_text = !hide_text; break; case SDLK_f: fading_song = !fading_song; break; case SDLK_n: fade_looped_songs = !fade_looped_songs; break; case SDLK_SLASH: // switch to sfx mode fx = !fx; break; case SDLK_COMMA: if (fx && --fx_num < 0) fx_num = SAMPLE_COUNT - 1; break; case SDLK_PERIOD: if (fx && ++fx_num >= SAMPLE_COUNT) fx_num = 0; break; case SDLK_SEMICOLON: if (fx) JE_playSampleNum(fx_num + 1); break; case SDLK_LEFT: case SDLK_UP: case SDLK_LCTRL: play_song((song_playing > 0 ? song_playing : MUSIC_NUM) - 1); stopped = false; break; case SDLK_RETURN: case SDLK_RIGHT: case SDLK_DOWN: case SDLK_LALT: play_song((song_playing + 1) % MUSIC_NUM); stopped = false; break; case SDLK_s: // stop song stop_song(); stopped = true; break; case SDLK_r: // restart song restart_song(); stopped = false; break; default: break; } } // user wants to quit, start fade-out if (trigger_quit && !quitting) { palette_fade_steps = 15; SDL_Color black = { 0, 0, 0 }; init_step_fade_solid(diff, black, 0, 255); quitting = true; } // if fade-out finished, we can finally quit if (quitting && palette_fade_steps == 0) break; } set_volume(tyrMusicVolume, fxVolume); }