void cloudMain() {

    uprint("\r\n ************************ BOOT UP (CLOUD) ************************ \r\n");

    configureAudio();
    audioReset();
    
    configureIRSend();
    int sta = configureRadio(0x0A00, 0x0000111111111111);
    uprint_int("Configured radio: ", sta);

    char rxbuf[2];
    int damageToSend, i;

    configureCloudLighting();

    DELAY_MS(400);

    playSound(CS_BOOT);
    DELAY_MS(CS_BOOT_LEN);


    while (1) {

        uprint("Beginning of main loop");
        cloudLightingSetMode(ALGM_BLINK);

        uprint("Waiting for hammer message");
        radioGetMessage(rxbuf, 1);

        uprint("Got message");

        playSound(CS_FIRE);
        // Don't wait for this sound

        // Enter manual lighting mode
        cloudLightingSetMode(ALGM_OFF);
        cloudLightingSetAll(BRIGHTNESS_MAX);
        cloudLightingUpdate();

        damageToSend = rxbuf[0];
        for (i = 0; i < damageToSend; i ++) {
            uprint("Sending damage packet");
            sendDamagePacket();
            if ((i % 10) == 0) {
                cloudLightingSetAll(BRIGHTNESS_MAX);
            } else if ((i % 5) == 0) {
                cloudLightingSetAll(50);
            }
            cloudLightingUpdate();
        }

        uprint("Sending DONE message");
        radioSendMessage("DONE", 0x0A00);

    }
    
}
void TEST_RadioSend() {
    char rx[2];
    while (1) {
        uprint("Enter character to send: ");
        uart1_gets(rx, 1);
        radioSendMessage(rx, 0x0A00);
        uprint("Sent message!");
    }
}
示例#3
0
void posixRadioProcess(void)
{
    const int flags = POLLRDNORM | POLLERR | POLLNVAL | POLLHUP;
    struct pollfd pollfd = { sSockFd, flags, 0 };

    if (poll(&pollfd, 1, 0) > 0 && (pollfd.revents & flags) != 0)
    {
        radioReceive();
    }

    if (sState == kStateTransmit && !sAckWait)
    {
        radioSendMessage();
    }
}
void hammerMain() {

    uprint("\r\n ######################## BOOT UP (HAMMER) ######################## \r\n");

    initHammerState();
    HammerState *hs = getHammerStatePtr();

    configureAccelerometer();

    configureAudio();
    audioReset();

    int sta = configureRadio(0x0A00, 0x0000111111111111);
    uprint_int("Configured radio: ", sta);

    configureIRReceive();

    configureLightMCU_SPI();

    updateLightMCUAll(hs->health, hs->charge);

    char sendString[2] = "x";
    char rxbuf[50];
    char doneString[] = "DONE";

    DELAY_MS(400);

    playSound(HS_BOOT);
    DELAY_MS(HS_BOOT_LEN);
    
    while (1) {

        uprint("Beginning of main loop");
        hs->charge = 0;
        updateLightMCUAll(hs->health, hs->charge);

        uprint("Waiting for spin...");
        startTrackingSpin();
        while (!checkSpinComplete());

        uprint("Spin complete!");
        playSound(HS_SPINCOMPLETE);
        DELAY_MS(HS_SPINCOMPLETE_LEN);

        setVolume(5);
        // Charging is really damn loud

        // This sound is very long, we just start it playing
        playSound(HS_CHARGING);

        uprint("Charging ...");

        hs->charge = 0;
        hs->charging = 1;
        while (hs->charge < 100) {
            hs->charge ++;
            updateLightMCUCharge(hs->charge);
            DELAY_MS((0.9 * hs->health) + 10);
        }
        hs->charging = 0;

        setVolume(8);
        // Back to normal

        playSound(HS_CHARGECOMPLETE);
        DELAY_MS(HS_CHARGECOMPLETE_LEN);

        uprint("Finished charging!");

        uprint("Waiting for thrust...");
        startTrackingThrust();
        while (!checkThrustComplete());

        setLightMCUHitAnim();

        uprint("Thrust complete!");
        playSound(HS_FIRE);
        DELAY_MS(HS_FIRE_LEN);

        setLightMCURainbow();

        // Become invincible
        disableIRReceive();

        uprint("Sending radio message");
        sendString[0] = hs->health;
        radioSendMessage(sendString, 0x0A00);

        uprint("Waiting for cloud message");
        radioGetMessage(rxbuf, 50);

        if (memcmp(rxbuf, doneString, 4) != 0) {
            uprint("Invalid message from cloud!");
        }

        enableIRReceive();
        uprint("Got cloud message");


        setLightMCUOff();
        DELAY_MS(30);

    }

}