Example #1
0
/**
 * @Function RunKeyboardInput(ES_Event ThisEvent)
 * @param ThisEvent - the event (type and param) to be responded.
 * @return ES_NO_EVENT
 * @brief Keyboard input only accepts the ES_KEYINPUT event and will always return
 * ES_NO_EVENT. it parses strings of the form EVENTNUM->EVENTPARAMHEX or
 * EVENTNUM and passes them to the state machine defined by
 * POSTFUNCTION_FOR_KEYBOARD_INPUT.
 * @note WARNING: you must have created the EventNames Array to use this module
* @author Max Dunne , 2013.09.26 */
ES_Event RunKeyboardInput(ES_Event ThisEvent)
{
#ifdef USE_KEYBOARD_INPUT
    ES_Event GeneratedEvent;
    uint8_t stringPos = 0;
    uint8_t numbersParsed = 0;
    static uint8_t curCommandLength = 0;
    GeneratedEvent.EventType = ES_NO_EVENT;
    GeneratedEvent.EventParam = 0;
    /********************************************
     in here you write your service code
     *******************************************/
    switch (ThisEvent.EventType) {
    case ES_INIT:
        for (stringPos = 0; stringPos < COMMANDSTRINGLENGTH; stringPos++) {
            CommandString[stringPos] = 0;
        }
        curCommandLength = 0;
        while (!IsTransmitEmpty());
        KeyboardInput_PrintEvents();
        while (!IsTransmitEmpty());
        printf("Keyboard input is active, no other events except timer activations will be processed. You can redisplay the event list by sending a %d event\r\n", ES_LISTEVENTS);
        break;

    case ES_KEYINPUT:
        if (ThisEvent.EventParam < 127) {
            CommandString[curCommandLength] = (char) ThisEvent.EventParam;
            curCommandLength++;
            if (ThisEvent.EventParam == TERMINATION_CHARACTER) {
                numbersParsed = sscanf(CommandString, "%d -> %X", &GeneratedEvent.EventType, &GeneratedEvent.EventParam);
                if (numbersParsed != 0) {

                    if (GeneratedEvent.EventType < NUMBEROFEVENTS) {
                        switch (GeneratedEvent.EventType) {
                        case ES_LISTEVENTS:
                            KeyboardInput_PrintEvents();
                            break;
                        default:
                            printf("\r\n\r\n%s with parameter %X was passed to %s\r\n", EventNames[GeneratedEvent.EventType], GeneratedEvent.EventParam, STRINGIFY(POSTFUNCTION_FOR_KEYBOARD_INPUT));
                            POSTFUNCTION_FOR_KEYBOARD_INPUT(GeneratedEvent);
                            break;
                        }
                    } else {
                        printf("Event #%d is Invalid, Please try again\r\n", GeneratedEvent.EventType);
                    }
                }
                for (stringPos = 0; stringPos < COMMANDSTRINGLENGTH; stringPos++) {
                    CommandString[stringPos] = 0;

                }
                curCommandLength = 0;
            }
        }
    default:
        break;
    }
#endif
    return (NO_EVENT);
}
Example #2
0
/**
 * @Function ADCIntHandler
 * @param None
 * @return None
 * @brief  Interrupt Handler for A/D. Reads all used pins into buffer.
 * @note  This function is not to be called by the user
 * @author Max Dunne, 2013.08.25 */
void __ISR(_ADC_VECTOR, ipl1) ADCIntHandler(void)
{
    unsigned char CurPin = 0;
    INTClearFlag(INT_AD1);
    for (CurPin = 0; CurPin <= PinCount; CurPin++) {
        ADValues[CurPin] = ReadADC10(CurPin); //read in new set of values
    }
    //calculate new filtered battery voltage
    Filt_BatVoltage = (Filt_BatVoltage * KEEP_FILT + AD_ReadADPin(BAT_VOLTAGE_MONITOR) * ADD_FILT) >> SHIFT_FILT;

    SampleCount++;
    if (SampleCount > PointsPerBatSamples) {//if sample time has passed
        PrevFilt_BatVoltage = CurFilt_BatVoltage;
        CurFilt_BatVoltage = Filt_BatVoltage;
        SampleCount = 0;
        //check for battery undervoltage check
        if ((CurFilt_BatVoltage <= BAT_VOLTAGE_LOCKOUT) && (PrevFilt_BatVoltage <= BAT_VOLTAGE_LOCKOUT) && (AD_ReadADPin(BAT_VOLTAGE_MONITOR) > BAT_VOLTAGE_NO_BAT)) {
            BOARD_End();
            while (1) {
                printf("Battery is undervoltage with reading %d, Stack is inoperable until charging\r\n", AD_ReadADPin(BAT_VOLTAGE_MONITOR));
                while (!IsTransmitEmpty());
            }
        }
    }
    //if pins are changed add pins
    if (PinsToAdd | PinsToRemove) {
        AD_SetPins();
    }
    ADNewData = TRUE;
}
Example #3
0
int main(void) {

    SERIAL_Init();
    TIMERS_Init();
    char i, j = 0;
    int k, l = 0;
    int time = GetTime();
    INTEnableSystemMultiVectoredInt();
    AD_Init(IR_PINS);
    IR_Init();

    while (1) {
        k = ReadADPin(IR_LEFT);
        l = ReadADPin(IR_RIGHT);
		char leftTrig = '_';
		char rightTrig = '_';
		if (IR_LeftTriggered())
			leftTrig = 'x';
		if (IR_RightTriggered())
			rightTrig = 'x';
			
        //if (time > GetTime() + 500) {
            if (IsTransmitEmpty()) {
                printf("\n %cLeft : %d \n %cRight : %d",leftTrig, k, rightTrig, l);
            }
                wait();
            //time = GetTime();
        //}
        //while (!IsTransmitEmpty()); // bad, this is blocking code
    }
    return 0;
}
int main(void)
{
    BOARD_Init();
    unsigned char asciiSpray;
    unsigned int i;
    printf("\r\nUno Serial Test Harness\r\nAfter this Message the terminal should mirror any single character you type.\r\n");
    // while(!IsTransmitEmpty());
    unsigned int NopCount = 0;
    unsigned char CharCount = 0;
#ifdef INUNDATION_TEST
    while (1) {
        NopCount = rand() % MAX_RAND + 1;
        //printf("%X\r\n",rand());
        for (i = 0; i < NopCount; i++) {
            asm("Nop");
        }
        for (CharCount = 32; CharCount < 128; CharCount++) {
            //printf("%c", CharCount);
            putchar(CharCount);
        }

    }
#endif
    GetChar();
    unsigned char ch = 0;
    while (1) {
        if (IsTransmitEmpty() == TRUE)
            if (IsReceiveEmpty() == FALSE)
                PutChar(GetChar());
    }

    return 0;
}
Example #5
0
int main(void) {
    SERIAL_Init();
    INTEnableSystemMultiVectoredInt();
    printf("\r\nUno Serial Test Harness\r\nAfter this Message the terminal should mirror anything you type.\r\n");

    unsigned char ch = 0;
    while (1) {
        if (IsTransmitEmpty() == TRUE)
            if (IsReceiveEmpty() == FALSE)
                PutChar(GetChar());
    }

    return 0;
}
Example #6
0
int main(void) {
    SERIAL_Init();
    int Real_Rate=0;
    char data_out=0;
    Real_Rate=I2C_Init(400000);
    //TRISGbits.TRISG9=0;
   // _RG9=0;
    //PORTClearBits(IOPORT_G,BIT_9);
    INTEnableSystemMultiVectoredInt();
    printf("\r\nAnima Sensor Test Board I2C driver test\r\nThis will verify I2C operation through use of a logic analyzer\r\n");
    printf("Rate returned from I2C Module: %d\r\n",Real_Rate);

    data_out=I2C_ReadReg(0x40,0x02);
    printf("\r\n%d\r\n",data_out);
    while(1);
    unsigned char ch = 0;
    while (1) {
        if (IsTransmitEmpty() == TRUE)
            if (IsReceiveEmpty() == FALSE)
                PutChar(GetChar());
    }

    return 0;
}
Example #7
0
int main(void) {

    //unsigned char size = 0, i;

    SERIAL_Init();
    INTEnableSystemMultiVectoredInt();

    
    //UART2PutChar('a');
    printf("sUno32 analog Accelerometer test\r\nAfter confirming settings reading will be taken\r\n");
    analog_accel_init();


    //while(1);

    //printf("Scale is set to %d \r\n",analog_GetScale());
    //analog_SetScale(analog_3GSCALE);
    //while(1);

    //printf("Scale is set to %d and should be %d\r\n", analog_GetScale(), analog_3GSCALE);
    //analog_SetScale(analog_2GSCALE);
    //printf("Scale is set to %d and should be %d\r\n", analog_GetScale(), analog_2GSCALE);


    printf("Rate is set to %d \r\n", analog_GetRate());

    //analog_SetRate(analog_300HERTZ);
    printf("Rate is set to %d and should be %d\r\n", analog_GetRate(), analog_300HERTZ);
    /*
    analog_SetRate(analog_800HERTZ);
    printf("Rate is set to %d and should be %d\r\n",analog_GetRate(),analog_800HERTZ);
     */
    char humanread = 1;
    int maxX = analog_GetXData(), maxY = analog_GetYData(), maxZ = analog_GetZData();
    int minX = maxX, minY = maxY, minZ = maxZ;
    int curval=0;
    int i, j, data;
    /*for(i=0; i!=-1; i++)
            for(j=0; j!=100; j++)
                    Nop();
    printf("Scale is set to %d and should be %d\r\n",analog_GetScale(),analog_3GSCALE);*/
    for (i = 0; i != 1000; i++)
        for (j = 0; j != 100; j++)
            Nop();

    while (1) {
        if (IsTransmitEmpty()){
        if (humanread == 1) {
            printf("Cur X: %d \tCur Y: %d \tCur Z: %d\r\n", analog_GetXData(), analog_GetYData(), analog_GetZData());
            //printf("combined z: %D\t\t",analog_GetZData());
        } else {
            printf("max X: %d \tmax Y: %d \tmax Z: %d \tmin X: %d \tmin Y: %d min Z: %d\r\n", maxX, maxY, maxZ, minX, minY, minZ);
            curval = analog_GetXData();
            if (curval < minX) {
                minX = curval;
            }
            if (curval > maxX) {
                maxX = curval;
            }
            curval = analog_GetYData();
            if (curval < minY) {
                minY = curval;
            }
            if (curval > maxY) {
                maxY = curval;
            }
            curval = analog_GetZData();
            if (curval < minZ) {
                minZ = curval;
            }
            if (curval > maxZ) {
                maxZ = curval;
            }
        }
        }
        /*while(!UART2IsEmpty())
                UART2PutChar(UART2GetChar());*/
    }

}
Example #8
0
int main(void) {

    //unsigned char size = 0, i;

    BOARD_Init();

    printf("Anima Small Scale FreeScale Accelerometer test\r\n");
    TIMERS_Init();
    LED_Init(LED_BANK1);
    int count=0;
//    while (1) {
//        if (!IsTimerActive(0)) {
//            // LATCbits.LATC5 ^= 1;
//            //LATBbits.LATB9 ^= 1;
//            InitTimer(0, 500);
//            printf("TOP: %X\r\n", count);
//            LED_SetBank(LED_BANK1, count);
//            count++;
//
//        }
//    }
//
//    while (1);
    free_accel_init();
    printf("Scale is set to %d \r\n", free_GetScale());
    free_SetScale(FREE_8GSCALE);
    printf("Scale is set to %d and should be %d\r\n", free_GetScale(), FREE_4GSCALE);
    free_SetScale(FREE_2GSCALE);
    printf("Scale is set to %d and should be %d\r\n", free_GetScale(), FREE_2GSCALE);
    printf("Rate is set to %d \r\n", free_GetRate());
    free_SetRate(FREE_200HERTZ);
    printf("Rate is set to %d and should be %d\r\n", free_GetRate(), FREE_200HERTZ);
    free_SetRate(FREE_800HERTZ);
    printf("Rate is set to %d and should be %d\r\n", free_GetRate(), FREE_800HERTZ);
    //free_SetRate(FREE_1P56HERTZ);
    //while(1);
    char humanread = 1;
    short dataArray[3];
    int i, j, data;
    for (i = 0; i != 1000; i++)
        for (j = 0; j != 500; j++)
            Nop();

    while (1) {
        //if (UART2HalfEmpty()){
        if (humanread == 1) {
            if (IsTransmitEmpty()) {
                free_GetTriplet(dataArray);
                printf("Accel: Cur X: %d \tCur Y: %d \tCur Z: %d\r\n", dataArray[0], dataArray[1], dataArray[2]);
            }
        } else {
            data = free_GetXData();
            //UART2PutChar('$');
            //UART2PutChar('#');
            // UART2PutChar(data >> 8);
            // UART2PutChar(data & 0x00FF);

            //UART2PutChar('\r');
            //UART2PutChar('\n');

        }
        //for (i = 0; i != -1; i++)
        //  Nop();
        //}
        /*while(!UART2IsEmpty())
                UART2PutChar(UART2GetChar());*/
    }

}
Example #9
0
int main(void)
{
    unsigned int wait = 0;
    int readcount = 0;
    unsigned int CurPin = 0;
    unsigned int PinListing = 0;
    char FunctionResponse = 0;
    char TestFailed = FALSE;
    //SERIAL_Init();
    //INTEnableSystemMultiVectoredInt();
    BOARD_Init();
    mJTAGPortEnable(0);
    printf("\r\nUno A/D Test Harness\r\nThis will initialize all A/D pins and read them %d times\r\n", TIMES_TO_READ);
    //printf("Value of pcfg before test: %X\r\n", AD1PCFG);
    // while(!IsTransmitEmpty());
    //AD_Init(BAT_VOLTAGE);
    //AD_Init();
    printf("Testing functionality before initialization\r\n");

    /*adding pins individually */
    printf("AD_AddPins on each pin indvidually which results in failure: ");
    for (CurPin = 1; CurPin < ALLADPINS; CurPin <<= 1) {
        FunctionResponse = AD_AddPins(CurPin);
        if (FunctionResponse != ERROR) {
            TestFailed = TRUE;
            break;
        }
    }
    if (TestFailed) {
        printf("FAIL\r\n");
    } else {
        printf("PASSED\r\n");
    }
    TestFailed = FALSE;
    /*removing pins individually*/
    printf("AD_RemovePins on each pin indvidually which results in failure: ");
    for (CurPin = 1; CurPin < ALLADPINS; CurPin <<= 1) {
        FunctionResponse = AD_RemovePins(CurPin);
        if (FunctionResponse != ERROR) {
            TestFailed = TRUE;
            break;
        }
    }
    if (TestFailed) {
        printf("FAIL\r\n");
    } else {
        printf("PASSED\r\n");
    }
    TestFailed = FALSE;
    /*listing pins while inactive*/
    printf("AD_ActivePins which should return 0: ");
    PinListing = AD_ActivePins();
    if (PinListing != 0x0) {
        printf("FAILED\r\n");

    } else {
        printf("PASSED\r\n");
    }
    //    /*calling ned when inactive*/
    //        printf("AD_End which should fail: ");
    //        FunctionResponse = AD_End();
    //        if (FunctionResponse != ERROR) {
    //            printf("FAILED\r\n");
    //        } else {
    //            printf("PASSED\r\n");
    //        }
    /*activating module*/
    printf("initializing using AD_Init: ");
    FunctionResponse = AD_Init();
    if (FunctionResponse != SUCCESS) {
        printf("FAILED\r\n");
    } else {
        printf("PASSED\r\n");
    }
    /*attempting to reactivate*/
    printf("initializing using AD_Init again returns error: ");
    FunctionResponse = AD_Init();
    if (FunctionResponse != ERROR) {
        printf("FAILED\r\n");
    } else {
        printf("PASSED\r\n");
    }
    printf("Testing Functionality after initialization\r\n");
    /*active pins after activation only has battery*/
    printf("Ad_ActivePins should only return BAT_VOLTAGE: ");
    PinListing = AD_ActivePins();
    if (PinListing == BAT_VOLTAGE) {
        printf("PASSED\r\n");
    } else {
        printf("FAILED\r\n");
    }
    /*each pin added should succeed*/
    printf("Adding each pin using AD_AddPins indivdually: ");
    for (CurPin = 1; CurPin < ALLADMINUSBATT; CurPin <<= 1) {
        PinListing = AD_ActivePins();
        FunctionResponse = AD_AddPins(CurPin);
        if (FunctionResponse != SUCCESS) {
            TestFailed = TRUE;
            break;
        }
        while (AD_ActivePins() != (PinListing | CurPin));
    }
    if (TestFailed) {
        printf("FAIL\r\n");
    } else {
        printf("PASSED\r\n");
    }
    /*removing each pin should succeed */
    printf("Removing each pin using AD_RemovePins indivdually: ");
    for (CurPin = 1; CurPin < ALLADMINUSBATT; CurPin <<= 1) {
        PinListing = AD_ActivePins();
        FunctionResponse = AD_AddPins(CurPin);
        if (FunctionResponse != SUCCESS) {
            TestFailed = TRUE;
            break;
        }
        while (AD_ActivePins() != (PinListing | CurPin));
    }
    if (TestFailed) {
        printf("FAIL: %X\r\n", 0xFEED);
    } else {
        printf("PASSED\r\n");
    }
    while (1);
    printf("We will now add the odd pins and wait for them to be activated");
    AD_AddPins(ODD_ACTIVE);
    while (!(AD_ActivePins() & ODD_ACTIVE)) {
        if (IsTransmitEmpty()) {
            printf("%X\r\n", AD_ActivePins());
        }
    }
    printf("The Odd pins are now active as shown by Active pins: %X\r\n", AD_ActivePins());
    printf("We will now enable the even pins and wait for them to be activated");
    AD_AddPins(EVEN_ACTIVE);
    while (!(AD_ActivePins() & EVEN_ACTIVE));
    printf("The Even pins are now active as shown by Active pins: %X\r\n", AD_ActivePins());


    char numtoread = NUM_AD_PINS;
    unsigned char cur = 0;
    DELAY(400000)
    while (readcount <= TIMES_TO_READ) {
        DELAY(100000);
        printf("\r\n");
        for (cur = 0; cur < numtoread; cur++) {
            printf("%d\t", AD_ReadADPin(1 << cur));
        }
        printf("\r\n");
        readcount++;
    }
    printf("Done Reading Them\r\n");
    AD_End();
    printf("Value of pcfg after test: %X", AD1PCFG);
    return 0;
}
Example #10
0
int main(void) {

    //unsigned char size = 0, i;



    SERIAL_Init();
    INTEnableSystemMultiVectoredInt();
    TIMERS_Init();
    printf("Uno32 FreeScale Magnetometer test\r\n");
    printf("Size of short:%d\r\n", sizeof (short));
    printf("Size of char:%d\r\n", sizeof (char));
    printf("Size of int:%d\r\n", sizeof (int));
    //while(1);
    free_mag_init();
    //printf("Scale is set to %d \r\n",free_mag_GetScale());
    //free_mag_SetScale(free_mag_4GSCALE);
    //printf("Scale is set to %d and should be %d\r\n",free_mag_GetScale(),free_mag_4GSCALE);
    //free_mag_SetScale(free_mag_2GSCALE);
    //printf("Scale is set to %d and should be %d\r\n",free_mag_GetScale(),free_mag_2GSCALE);
    printf("Rate is set to %d \r\n", free_mag_GetRate());
    free_mag_SetRate(FREE_MAG_0P08HERTZ_128_OVERRATIO);
    printf("Rate is set to %d and should be %d\r\n", free_mag_GetRate(), FREE_MAG_0P08HERTZ_128_OVERRATIO);
    //InitTimer(0, 1000);
    //while (!IsTimerExpired(0));

    free_mag_SetRate(FREE_MAG_40HERTZ_32_OVERRATIO);
    printf("Rate is set to %d and should be %d\r\n", free_mag_GetRate(), FREE_MAG_40HERTZ_32_OVERRATIO);
    while (1);
    char humanread = 1;
    int i, j, data;
    //for (i = 0; i != 1600; i++)
    //for (j = 0; j != 100; j++)
    //Nop();
    DELAY();
    short AxisData[3];
    while (1) {
        //if (UART2HalfEmpty()){
        //printf("%d",IsTransmitEmpty());
        //DELAY();
        if (humanread == 1) {
            if (IsTransmitEmpty()) {
                //                printf("Cur X: %d \tCur Y: %d \tCur Z: %d\r\n", free_mag_GetXData(), free_mag_GetYData(), free_mag_GetZData());
                free_mag_GetTriplet(AxisData);
                printf("Cur X: %d \tCur Y: %d \tCur Z: %d\tTotal: %d\r\n", AxisData[0], AxisData[1], AxisData[2], AxisData[0] * AxisData[0] + AxisData[1] * AxisData[1] + AxisData[2] * AxisData[2]);
            }
        } else {
            //data=free_mag_GetXData();
            //UART2PutChar('$');
            //UART2PutChar('#');
            //UART2PutChar(data >> 8);
            //UART2PutChar(data & 0x00FF);

            //UART2PutChar('\r');
            //UART2PutChar('\n');

        }
        //for (i = 0; i != -1; i++)
        //Nop();
        //}
        /*while(!UART2IsEmpty())
                UART2PutChar(UART2GetChar());*/
    }

}
Example #11
0
int main(void) {

    // ----------------- Initialization --------------
    SERIAL_Init();
    AD_Init(POT_INPUT);

    // Initialize interrupts
    INTEnableSystemMultiVectoredInt();

    RC_Init(RC_PORT);
    unsigned int wait = 0;
    for (wait = 0; wait <= 1000000; wait++)
        asm("nop");
    RC_SetPulseTime(RC_PORT, 2000);

    printf("\nHello,...");

    while (1) {
        
        // Read and print potentiometer
        unsigned int potValue = ReadPotentiometer();
        //printf("\nPot. reading: %x", potValue);

        // Pause if desired
        #ifdef ADC_PAUSE
        
        #endif

        unsigned int newSpeed = potValue +1000;
        printf("\nPot value to %u", potValue);

        // bound it
        newSpeed = max(newSpeed,MINPULSE);
        newSpeed = min(newSpeed,MAXPULSE);
        // effect the motor
        if (RC_SetPulseTime(RC_PORT, newSpeed) == SUCCESS) {
            printf("\nSuccessfully set PWM to %u", newSpeed);
        }
        else {
            printf("\nFailed to set PWM to %u", newSpeed);
        }
         
/*
        char keyPressed = GetChar();
        if (keyPressed != 0) {
            /*
            if (keyPressed == 'f') {
                // forward
                printf("\nforward");
                if (DIRECTION != FORWARD)
                    DIRECTION = FORWARD;
            }
            else if(keyPressed == 'r') {
                 // reverse
                printf("\nreverse");
                if (DIRECTION != REVERSE)
                    DIRECTION = REVERSE;
            }
            else if(keyPressed == 'q') {
                printf("\nGoodbye!");
                PWM_End();
                return 0;
            }
             
            if(keyPressed == 't') {
                unsigned short int stringMax = 4;
                unsigned short int i = 0;
                char charNumber[1];
                charNumber[0] = 0;
                char stringNumber[stringMax+1];
                printf("\nPlease enter a frequency:");

                while(charNumber[0] != 46) {
                        charNumber[0] = GetChar();
                        //printf("\nGot %s", charNumber);
                        if ((charNumber[0] <= 57 && charNumber[0] >= 48)) {
                            stringNumber[i] = charNumber[0];
                            stringNumber[i+1] = '\0';
                            //printf("\nAppended %c to '%s'",charNumber[0],stringNumber);
                            //stringNumber = strcat(stringNumber, charNumber);
                            i++;
                        }

                        if (i >= stringMax)
                            break;
                        
                }
                //printf("\ni=%u stmax=%u", i, stringMax);
                printf("\nDone");

                unsigned int newFreq = atoi(stringNumber);
                newFreq = max(newFreq,MINPULSE);
                newFreq = min(newFreq,MAXPULSE);
                printf("\nPulse width set to %u",newFreq);
                RC_SetPulseTime(RC_PORT,newFreq);
                
            }
        } // end of keyPressed
        */
 
        while (!IsTransmitEmpty()); // bad, this is blocking code
    } // end of while loop

    return 0;
}