void app_surface_event(u8 type, u8 padIndex, u8 value) { if (game_state == GameState_INIT) { game_state = GameState_RUNNING; update_score_LEDs(); update_LEDs(); } else if (game_state == GameState_RUNNING) { handle_input(type, padIndex, value); } }
void app_timer_event() { static int completionTimer = 0; if (game_state == GameState_RUNNING) { for (int i = 0 ; i < GrabType_NBR_ELT ; i++) { if (grabbers[i].tick >= 0) { grabbers[i].tick++; if (grabbers[i].tick > GRABBER_TICKS) { grabbers[i].tick = 0; switch (grabbers[i].state) { case GrabberState_STOPPED: { break; } case GrabberState_EXTENDING: { ProgressResult result = can_progress((GrabType)i); if (result == ProgressResult_OK) { grabbers[i].length++; } else if (result == ProgressResult_COMPLETE) { score(grabbers[i].type); if (((scores[GrabType_TOP] >= 8) || (scores[GrabType_BOTTOM] >= 8) || (scores[GrabType_LEFT] >= 8) || (scores[GrabType_RIGHT] >= 8))) { /* Nb. This -- a return function in the middle of a function -- is horrible. I'll refactor at some point in the future! */ game_complete(grabbers[i].type); return; } setup_nugget(); grabbers[i].state = GrabberState_RETRACTING; grabbers[i].tick = GRABBER_TICKS; } else { grabbers[i].state = GrabberState_RETRACTING; grabbers[i].tick = GRABBER_TICKS; } break; } case GrabberState_RETRACTING: { if (grabbers[i].length > 0) { grabbers[i].length--; } if (grabbers[i].length == 0) { grabbers[i].state = GrabberState_STOPPED; grabbers[i].tick = -1; } break; } case GrabberState_RETRACTING_RESTART: { if (grabbers[i].length > 0) { grabbers[i].length--; } if (grabbers[i].length == 0) { grabbers[i].index = grabbers[i].next_index; grabbers[i].state = GrabberState_EXTENDING; } break; } } update_cells(); update_LEDs(); } } } } else if (game_state == GameState_INIT) { reset_cells(); setup_nugget(); } else if (game_state == GameState_GAME_COMPLETE) { completionTimer ++; if (completionTimer > COMPLETION_TICKS) { reset_game(); update_LEDs(); update_score_LEDs(); completionTimer = 0; } } }
void timer2_int_handler(void) { uint8_t loopFlags = 0xFF; int i; // Clear the interrupt flag ROM_TimerIntClear(TIMER2_BASE, TIMER_TIMA_TIMEOUT); // Increment the counter ulTempoTimestamp = (ulTempoTimestamp+1) % TEMPO_MULTIPLIER; // Check looping conditions (and blink the tempo LED) if (ulTempoTimestamp == 0) { // All possible loop intervals fire loopFlags = LOOP_1ON1; // TOGGLE THE TEMPO LED ON ROM_GPIOPinWrite(LED_TEMPO, 0xFF); } else if (ulTempoTimestamp % TEMPO_MULTIPLIER/2 == 0) { loopFlags = LOOP_1ON2; } else if (ulTempoTimestamp % TEMPO_MULTIPLIER/4 == 0) { loopFlags = LOOP_1ON4; } else if (ulTempoTimestamp % TEMPO_MULTIPLIER/8 == 0) { loopFlags = LOOP_1ON8; // TOGGLE THE TEMPO LED OFF ROM_GPIOPinWrite(LED_TEMPO, 0x00); } else if (ulTempoTimestamp % TEMPO_MULTIPLIER/16 == 0) { loopFlags = LOOP_1ON16; } else if (ulTempoTimestamp % TEMPO_MULTIPLIER/32 == 0) { loopFlags = LOOP_1ON32; } // Update looping tracks for (i = 0; i < 16; i++) { if (!!(looping & (1 << i)) && btnLoopMode[i] >= loopFlags) { // Track is looping UARTprintf("Looping track %d\n", i); whereLastPress[i] = 0; sdcard_resetFile(&fPtrs[i]); pressed |= (1 << i); loopMod |= (1 << i); } } // Update the LED array update_LEDs(); // // Debugging // if (g_ulTimeStamp % 100 == 0) // { // if (testTimer2) // { // testTimer2 = 0; //// pressed = (1 << testSample); //// //pressed = 0x2000; //// testSample = (testSample+1)%16; //// UARTprintf("Playing Sample %d\n", testSample, pressed, ulTempoTimestamp); // } // } // else // { // testTimer2 = 1; // } }