Ejemplo n.º 1
0
/*******************************************************************************
* Function Name: int  main( void )
********************************************************************************/
int main(void)
{
    uint32  i;
    
    CyGlobalIntEnable; /* Enable global interrupts. */

    EZI2C_Start();
    #ifdef ENABLE_TUNER
    EZI2C_EzI2CSetBuffer1(sizeof(CapSense_dsRam), sizeof(CapSense_dsRam),(uint8 *)&CapSense_dsRam);        
    #else
    EZI2C_EzI2CSetBuffer1(sizeof(I2Cbuf), RW, (void *) &I2Cbuf);     
    #endif   
    
    SmartIO_Start();    
    VDAC_Start();
    PVref_ALS_Start();
    Opamp_ALS1_Start();
    Opamp_ALS2_Start();
    PVref_Therm_Start();
    Opamp_Therm_Start();    
    ADC_Start();
    ADC_IRQ_Enable();
    
    CapSense_Start();   
    /* Over-ride IDAC values for buttons but keep auto for Prox and Humidity */
    CapSense_BUTTON0_IDAC_MOD0_VALUE =          7u;
    CapSense_BUTTON0_SNS0_IDAC_COMP0_VALUE =    6u;
    CapSense_BUTTON1_IDAC_MOD0_VALUE =          7u;
    CapSense_BUTTON1_SNS0_IDAC_COMP0_VALUE =    7u;
    CapSense_BUTTON2_IDAC_MOD0_VALUE =          9u;
    CapSense_BUTTON2_SNS0_IDAC_COMP0_VALUE =    7u;
    CapSense_BUTTON3_IDAC_MOD0_VALUE =          9u;
    CapSense_BUTTON3_SNS0_IDAC_COMP0_VALUE =    8u;
    /* Setup first widget and run the scan */    
    CapSense_SetupWidget(CapSense_BUTTON0_WDGT_ID);
    CapSense_Scan();      
    
    /* Start SysTick Timer to give a 1ms interrupt */
    CySysTickStart();
    /* Find unused callback slot and assign the callback. */
    for (i = 0u; i < CY_SYS_SYST_NUM_OF_CALLBACKS; ++i)
    {
        if (CySysTickGetCallback(i) == NULL)
        {
            /* Set callback */
            CySysTickSetCallback(i, SysTickISRCallback);
            break;
        }
    }
    
    /* Initialize I2C and local data registers to 0's */
    I2Cbuf.dacVal = 0.0;
    I2Cbuf.ledVal = 0x00;
    I2Cbuf.ledControl = 0x00;
    I2Cbuf.buttonVal = 0x00;
    I2Cbuf.temperature = 0.0;
    I2Cbuf.humidity = 0.0;
    I2Cbuf.illuminance = 0.0;
    I2Cbuf.potVal = 0.0;
    
    LocData.dacVal = 0.0;
    LocData.ledVal = 0x00;
    LocData.ledControl = 0x00;
    LocData.buttonVal = 0x00;
    LocData.temperature = 0.0;
    LocData.humidity = 0.0;
    LocData.illuminance = 0.0;
    LocData.potVal = 0.0;
    
    for(;;)
    {
        processButtons();  /* Mechanical buttons and bootloader entry */
        processCapSense(); /* CapSense Scanning */
        processDAC();      /* VDAC output voltage setting */
        processADC();      /* Process ADC results after each scan completes */
        processI2C();      /* Copy date between I2C registers and local operating registers */
    }
} /* End of main */
Ejemplo n.º 2
0
void main() {
    int i = 0;
    int j = 0;
    char test[2] = {'2', '\0'};

    systemSetup(&globalData);

#if FRONT_NOT_BACK
    TRISAbits.RA0 = 0;
    ANSELAbits.ANSA0 = 0;

    printMainMenu(&globalData);
#else
    //    TRISDbits.RD4 = 0;
    //    ANSELDbits.ANSD4 = 0;
    //    PORTDbits.RD4 = 1;
#endif



    while (1) {
#if FRONT_NOT_BACK


        // get the updated cards
        if (globalData.runGetUpdatedCards == 1) {
            getUpdatedCards();
            globalData.runGetUpdatedCards = FALSE;
        }
#else
        // move the reader -- if we had one -- to the proper location


        /*
         * run LED driver
         */
        if (globalData.updateLEDFlag) {
            globalData.updateLEDFlag = FALSE;
            updateLEDs();
        }
#endif

        // process pending i2c tasks
        if (globalData.sendI2C == 1) {
            sendBytes(i2cData.dataOut, i2cData.outLength);
            globalData.sendI2C = FALSE;
        }
        if (globalData.gotI2C == 1) {
            processI2C();
            globalData.gotI2C = 0;
        }

#if FRONT_NOT_BACK
        if (!globalData.keyFlag) {
            // Check keystroke
            keypad(&globalData);
        }

        if (globalData.keyFlag && !globalData.displayedKey || globalData.myRequestStatus != 0) {
            globalData.keyFlag = FALSE;
            globalData.displayedKey = TRUE;

            switch (globalData.displayPage) {
                case 0: // main menu
                    processPrintCursor(&globalData, 3, BLUE, WHITE);
                    if (globalData.newDisplay == 1) {
                        globalData.newDisplay = 0;
                        switch (globalData.cursorPos) {
                            case 0: // go to singleplayer
                                globalData.displayPage = 1;
                                printSelectGame(&globalData);
                                break;
                            case 1: // multi
                                globalData.displayPage = 2;
                                printSelectGame(&globalData);
                                break;
                            case 2: // build
                                globalData.displayPage = 3;
                                printBuild(&globalData);
                                break;
                            case 0xFF: // back
                                globalData.displayPage = 0;
                                break;
                            default:
                                globalData.displayPage = 0;
                                printMainMenu(&globalData);
                                break;
                        }
                    }
                    break;
                case 1: // display sp game menu
                    processPrintCursor(&globalData, 4, GREEN, BLACK);
                    if (globalData.newDisplay == 1) {
                        globalData.newDisplay = 0;
                        switch (globalData.cursorPos) {
                            case 0: // go to monster game
                                globalData.displayPage = 4;
                                singlePlayer(&globalData);
                                break;
                            case 1: // go to clue
                                globalData.displayPage = 5;
                                clean(BLACK);
                                prints(0, 35, WHITE, BLACK, "In Progress", 1);
                                break;
                            case 2: // go to error
                                globalData.displayPage = 6;
                                printBSOD();
                                break;
                            case 3: // go to error
                                clean(BLACK);
                                prints(0, 35, WHITE, BLACK, "In Progress", 1);
                                globalData.displayPage = 7;
                                break;
                            default:
                                globalData.displayPage = 0;
                                printMainMenu(&globalData);
                                break;
                        }
                        globalData.cursorPos = 0;
                    }
                    break;
                case 2: // display mp game menu
                    processPrintCursor(&globalData, 4, GREEN, BLACK);
                    if (globalData.newDisplay == 1) {
                        globalData.newDisplay = 0;
                        switch (globalData.cursorPos) {
                            case 0: // go to monster game
                                globalData.displayPage = 4;
                                printSelectGame(&globalData);
                                break;
                            case 1: // go to clue
                                globalData.displayPage = 5;
                                clean(BLACK);
                                prints(0, 35, WHITE, BLACK, "In Progress", 1);
                                break;
                            case 2: // go to error
                                globalData.displayPage = 6;
                                printBSOD();
                                break;
                            case 3: // go to error
                                clean(BLACK);
                                prints(0, 35, WHITE, BLACK, "In Progress", 1);
                                globalData.displayPage = 7;
                                break;
                            default:
                                globalData.displayPage = 0;
                                printMainMenu(&globalData);
                                break;
                        }
                        globalData.cursorPos = 0;
                    }
                    break;
                case 3: // build cards
                    processPrintCursor(&globalData, 4, RED, BLACK);
                    if (globalData.newDisplay == 1) {
                        globalData.newDisplay = 0;
                        switch (globalData.cursorPos) {
                            case 0: // go to monster game
                                buildCard(&globalData, 0);
                                prints(140, 35, BLACK, RED, "DONE", 1);
                                globalData.displayPage = 0;
                                printMainMenu(&globalData);
                                break;
                            case 1: // go to clue
                                buildCard(&globalData, 1);
                                prints(140, 35, BLACK, RED, "DONE", 1);
                                globalData.displayPage = 0;
                                printMainMenu(&globalData);
                                break;
                            case 2: // go to error
                                buildCard(&globalData, 2);
                                prints(140, 35, BLACK, RED, "DONE", 1);
                                globalData.displayPage = 0;
                                printMainMenu(&globalData);
                                break;
                            case 3: // go to error
                                buildCard(&globalData, 3);
                                clean(BLACK);
                                prints(140, 35, BLACK, RED, "DONE", 1);
                                globalData.displayPage = 0;
                                printMainMenu(&globalData);
                                break;
                            default:
                                globalData.displayPage = 0;
                                printMainMenu(&globalData);
                                break;
                        }
                        globalData.cursorPos = 0;
                    }
                    break;
                case 4: // singleplayer monster
                    singlePlayer(&globalData);
                    break;
                case 5: // clue sp
                    break;
                case 6: // bsod
                    break;
                case 7: // in progress, b goes back
                    if (globalData.keyPress == 0x0B) {
                        globalData.displayPage = 0;
                        printMainMenu(&globalData);
                    }
                    break;
            }
        }


        //        if (!globalData.keyFlag) {
        //            keypad(&globalData);
        //        }

        //        mainMenu(&globalData);

        //
        //        if (globalData.keyFlag && !globalData.displayedKey) { // TODO this goes into a display function
        //            globalData.keyFlag = FALSE;
        //            globalData.displayedKey = TRUE;
        //
        ////            processDisplay(globalData);
        //
        //        }


#else
        //Doing an inventory command from the Build card menu
        if (globalData.readCard != 0) {

            //            globalData.getInventory = TRUE;
            //        }
            //        if (globalData.getInventory == TRUE) {
            // get the inventory of cards
            inventoryRFID();

            // Print out each on to the LCD
            for (i = 0; i < readerData.availableUIDs; i++) {
                if (readerData.readUID[i][0] != ',') {
                    // Get rid of commas
                    processUID(readerData.readUID[i]);
                    //                    printrs(0, 24 + 8 * i, BLACK, RED, readerData.readUID[i], 1); // print first UID
                }
            }

            // got inventory, tell frontend
            i2cData.dataOut[0] = CARD_CHANGE;
            i2cData.outLength = 1;
            globalData.sendI2C = TRUE;
            i2cData.transmissionNum = 0; // begin counting slots

            // Tell UID to be quiet - Works but needs to have at least one uid in this state
            // quietRFID(readerData.readUID[0]);

            //            if (readerData.availableUIDs > 0) {
            //
            //                // block 0 high bits being 0x0000 indicates factory card, not custom
            //                // block 0 high bits being 0x0001 indicates custom card
            //                // block 0 low bits indicate the game the card is for. 0x0001 is the monster game
            //                writeRFID(readerData.readUID[0], 0x00, 0x0000, 0x0001); // 7654 3210
            //                writeRFID(readerData.readUID[0], 0x01, 0x0010, 0x0001); // hex 7-5 are for level 0x001 is level 1
            //                // hex 4 is for type 0 1 2 3
            //                // 0x0 fire, 0x1 water, 0x3 earth
            //                // last 4 are monster ID
            //
            //                //writes 8 chars in 2 addresses of memory (0x02 and 0x03 here)
            //                char8RFID(readerData.readUID[0], 0x02, "FIREDUDE");
            //                writeRFID(readerData.readUID[0], 0x04, 0x0003, 0x0201); // Move list by id, has moves 03, 02, and 01
            //                readRFID(readerData.readUID[0], 0x00);
            //                printrs(0, 32, BLACK, RED, readerData.readData, 1); // print 1st block
            //                readRFID(readerData.readUID[0], 0x01);
            //                printrs(0, 40, BLACK, RED, readerData.readData, 1); // print 2nd block
            //                readRFID(readerData.readUID[0], 0x02);
            //                printrs(0, 48, BLACK, RED, readerData.readData, 1); // print 3rd block
            //                readRFID(readerData.readUID[0], 0x03);
            //                printrs(0, 56, BLACK, RED, readerData.readData, 1); // print 4th block
            //                readRFID(readerData.readUID[0], 0x04);
            //                printrs(0, 64, BLACK, RED, readerData.readData, 1); // print 5th block
            //            }
            //
            //
            //            readRFID(readerData.readUID[0], 0x01);
            //            // Print out block on to the LCD
            //            for (j = 0; j < readerData.availableUIDs; j++) {
            //                if (readerData.readUID[j][0] != ',') {
            //                    // Get rid of commas
            //                    printrs(0, 24 + 8 * i + 8 * j, BLACK, RED, readerData.readUID[j], 1); // print first UID
            //                }
            //            }
            //
            //            prints(0, H - 8, BLACK, RED, "Press B to go back.", 1);
            //            // Turn off inventory flag

            //            globalData.getInventory = FALSE;
            globalData.readCard = 0;
        }
#endif
    }
    return;


}
Ejemplo n.º 3
0
//pocess serial and I2C interface 
void Interface::process(void)
{
  processSerial();
  processI2C();
}