Example #1
0
void TopMenuItemProgram(void){
    
    char menu_item, EXIT_FLAG, pw_test;
    int pw_test_result;
    
    menu_item = 1;
    EXIT_FLAG = 0;
    
    /* Clear all rows and update icon row */
    EPD_Init();
    ClearDisplayRow(2);
    ClearDisplayRow(3);
    ClearDisplayRow(4);
    ClearDisplayRow(5);
    //SetUpIconRow();
    //EPD_Init();
    //EPD_Update(ROW1_START, ROW1_END);
    EPD_PowerOff();
    
    while(!EXIT_FLAG){
        
        switch(menu_item){
            case 1:
                /* Display "Configuration" in 3rd row */
                EPD_Init();
                ClearDisplayRow(3);
                SetUpDisplayString(ARROW_NO, prog_config_str, 14);
                EPD_Update(ROW3_START, ROW3_END);
                EPD_PowerOff();
                break;
              
            case 2:    
                /* Display "Calibration" in 3rd row */
                EPD_Init();
                ClearDisplayRow(3);
                SetUpDisplayString(ARROW_NO, prog_calibrate_str, 10);
                EPD_Update(ROW3_START, ROW3_END);
                EPD_PowerOff();
                break;
                
            case 3:    
                /* Display "Exit" in 3rd row */
                EPD_Init();
                ClearDisplayRow(3);
                SetUpDisplayString(ARROW_NO, prog_exit_str, 5);
                EPD_Update(ROW3_START, ROW3_END);
                EPD_PowerOff();
                break;    
        }
        
        /* Wait for key press */
        while(!BUTTON_PRESS_OK);    // only way to get out is with key press!
        
        BUTTON_PRESS_OK = 0;
        
        if(UP_BUTTON_PRESSED){
            UP_BUTTON_PRESSED = 0;
            menu_item--;
            
            if(menu_item < 1){
                menu_item = 1;
            }            
        }
        
        if(SHIFT_BUTTON_PRESSED){
            SHIFT_BUTTON_PRESSED = 0;
            menu_item++;
            
            if(menu_item > 3){
                menu_item = 1;
            }            
        }
        
        if(ENTER_BUTTON_PRESSED){
            ENTER_BUTTON_PRESSED = 0;
            
            switch(menu_item){
                case 1: // configuration
                    break;
                    
                case 2: // calibration
                    PasswordEnter();
                    
                    /* Check which of the three passwords was entered */
                    pw_test = 0;
                    
                    while(pw_test == 0){
                        pw_test_result = strcmp(input_pw, calibrate_pw_1);
                        
                        if(pw_test_result == 0){
                            pw_test = 1;    // first password match
                            break;
                        }
                        
                        pw_test_result = strcmp(input_pw, calibrate_pw_2);
                        
                        if(pw_test_result == 0){
                            pw_test = 2;    // 2nd password match
                            break;
                        }
                        
                        pw_test_result = strcmp(input_pw, calibrate_pw_3);
                        
                        if(pw_test_result == 0){
                            pw_test = 3;    // 3rd password match
                            break;
                        }
                        
                    }
                    
                    /* Carry out appropriate calibration function */
                    switch(pw_test){
                        case 1:
                            CalibrateMain();
                            break;
                            
                        case 2:
                            CalibrateFactor();
                            break;
                            
                        case 3:
                            CalibrateZero();
                            break;    
                    }
                    break;
                    
                case 3: // exit
                    EXIT_FLAG = 1;
            }
            
        }
    }
}
Example #2
0
/*!
 * @brief Main function
 */
int main (void)
{
    /* enable clock for PORTs */
    CLOCK_SYS_EnablePortClock(PORTA_IDX);
    //CLOCK_SYS_EnablePortClock(PORTB_IDX);
    CLOCK_SYS_EnablePortClock(PORTC_IDX);
    CLOCK_SYS_EnablePortClock(PORTD_IDX);
    CLOCK_SYS_EnablePortClock(PORTE_IDX);

    /* Set allowed power mode, allow all. */
    SMC_HAL_SetProtection(SMC, kAllowPowerModeAll);

    /* Set system clock configuration. */
    CLOCK_SYS_SetConfiguration(&g_defaultClockConfigVlpr);

    /* Initialize LPTMR */
    lptmr_state_t lptmrState;
    LPTMR_DRV_Init(LPTMR0_IDX, &lptmrState, &g_lptmrConfig);
    LPTMR_DRV_SetTimerPeriodUs(LPTMR0_IDX, 100000);
    LPTMR_DRV_InstallCallback(LPTMR0_IDX, lptmr_call_back);

    /* Initialize DMA */
    dma_state_t dma_state;
    DMA_DRV_Init(&dma_state);

    /* Initialize PIT */
    PIT_DRV_Init(0, false);
    PIT_DRV_InitChannel(0, 0, &g_pitChan0);

    /* Initialize CMP */
    CMP_DRV_Init(0, &g_cmpState, &g_cmpConf);
    CMP_DRV_ConfigDacChn(0, &g_cmpDacConf);
    PORT_HAL_SetMuxMode(g_portBase[GPIOC_IDX], 0, kPortMuxAlt5);
    CMP_DRV_Start(0);

    /* Buttons */
    GPIO_DRV_InputPinInit(&g_switch1);
    GPIO_DRV_InputPinInit(&g_switch2);
    GPIO_DRV_InputPinInit(&g_switchUp);
    GPIO_DRV_InputPinInit(&g_switchDown);
    GPIO_DRV_InputPinInit(&g_switchLeft);
    GPIO_DRV_InputPinInit(&g_switchRight);
    GPIO_DRV_InputPinInit(&g_switchSelect);

    /* Start LPTMR */
    LPTMR_DRV_Start(LPTMR0_IDX);

    /* Setup LPUART1 */
    LPUART_DRV_Init(1, &g_lpuartState, &g_lpuartConfig);
    LPUART_DRV_InstallRxCallback(1, lpuartRxCallback, rxBuff, NULL, true);
    LPUART_DRV_InstallTxCallback(1, lpuartTxCallback, NULL, NULL);
    LPUART_BWR_CTRL_TXINV(g_lpuartBase[1], 1);
    PORT_HAL_SetMuxMode(g_portBase[GPIOE_IDX], 0, kPortMuxAlt3);
    PORT_HAL_SetMuxMode(g_portBase[GPIOE_IDX], 1, kPortMuxAlt3);

    /* Setup FlexIO for the WS2812B */
    FLEXIO_Type *fiobase = g_flexioBase[0];
    CLOCK_SYS_SetFlexioSrc(0, kClockFlexioSrcMcgIrClk);
    FLEXIO_DRV_Init(0, &g_flexioConfig);
    FLEXIO_HAL_ConfigureTimer(fiobase, 0, &g_timerConfig);
    FLEXIO_HAL_ConfigureShifter(fiobase, 0, &g_shifterConfig);
    PORT_HAL_SetMuxMode(g_portBase[GPIOE_IDX], 20, kPortMuxAlt6);
    FLEXIO_DRV_Start(0);

    FLEXIO_HAL_SetShifterStatusDmaCmd(fiobase, 1, true);
    DMA_DRV_RequestChannel(kDmaAnyChannel, kDmaRequestMux0FlexIOChannel0,
            &g_fioChan);
    DMA_DRV_RegisterCallback(&g_fioChan, fioDmaCallback, NULL);

    /* Connect buzzer to TPM0_CH3 */
    PORT_HAL_SetMuxMode(g_portBase[GPIOE_IDX], 30, kPortMuxAlt3);
    tpm_general_config_t tmpConfig = {
        .isDBGMode = false,
        .isGlobalTimeBase = false,
        .isTriggerMode = false,
        .isStopCountOnOveflow = false,
        .isCountReloadOnTrig = false,
        .triggerSource = kTpmTrigSel0,
    };
    TPM_DRV_Init(0, &tmpConfig);
    TPM_DRV_SetClock(0, kTpmClockSourceModuleMCGIRCLK, kTpmDividedBy1);

    /* Blank LED just in case, saves power */
    led(0x00, 0x00, 0x00);

    /* Init e-paper display */
    EPD_Init();

    /* Throw up first image */
    int ret = EPD_Draw(NULL, images[current_image]);
    if (-1 == ret) {
        led(0xff, 0x00, 0x00);
    } else if (-2 == ret) {
        led(0xff, 0xff, 0x00);
    } else if (-3 == ret) {
        led(0x00, 0x00, 0xff);
    } else {
        led(0x00, 0xff, 0x00);
    }
    blank_led = 30;

    /* Deinit so we can mess around on the bus pirate */
    //EPD_Deinit();

    /* We're done, everything else is triggered through interrupts */
    for(;;) {
        if (cue_next_image) {
            int old_image = current_image;
            current_image = (current_image + 1) % image_count;
            EPD_Draw(images[old_image], images[current_image]);
            cue_next_image = 0;
        }
#ifndef DEBUG
        SMC_HAL_SetMode(SMC, &g_idlePowerMode);
#endif
    }
}
Example #3
0
//char PasswordEnter(char *pw_string){
void PasswordEnter(void){    
    
    char digit_posn, ENTER_FLAG;
    char digit;
    
    digit_posn = 0;
    digit = 0;
    ENTER_FLAG = 0;
    BUTTON_PRESS_OK = 0;
    
    /* Display "Password" on row 3 and "0000" on row 4. */
    EPD_Init();
    ClearDisplayRow(3);
    ClearDisplayRow(4);
    SetUpDisplayString(ARROW_NO, password_str, 9);
    EPD_Update(ROW3_START, ROW3_END);
    SetUpDisplayString(ARROW_NO, pw_str, 5);
    EPD_Update(ROW4_START, ROW4_END);
    EPD_PowerOff();
    
    /* Get the new password */
    while(!ENTER_FLAG){
         /* Wait for key press */
        while(!BUTTON_PRESS_OK);    // only way to get out is with key press!
        
        BUTTON_PRESS_OK = 0;
        
        if(UP_BUTTON_PRESSED){  // increment the digit in the current position
            UP_BUTTON_PRESSED = 0;
            
            digit++;
            
            if(digit > 9){  // roll over to 0
                digit = 0;
            }
            
            input_pw[digit_posn] = digit | 0x30;    // convert to ASCII
            
            /* Update pw_string */
            switch(digit){
                case 0: pw_str[digit_posn + 1] = char_zero;
                break;
                
                case 1: pw_str[digit_posn + 1] = char_one;
                break;
                
                case 2: pw_str[digit_posn + 1] = char_two;
                break;
                
                case 3: pw_str[digit_posn + 1] = char_three;
                break;
                
                case 4: pw_str[digit_posn + 1] = char_four;
                break;
                
                case 5: pw_str[digit_posn + 1] = char_five;
                break;
                
                case 6: pw_str[digit_posn + 1] = char_six;
                break;
                
                case 7: pw_str[digit_posn + 1] = char_seven;
                break;
                
                case 8: pw_str[digit_posn + 1] = char_eight;
                break;
                
                case 9: pw_str[digit_posn + 1] = char_nine;
                break;
            }
            
            EPD_Init();
            //ClearDisplayRow(4);
            SetUpDisplayString(ARROW_NO, pw_str, 5);
            EPD_Update(ROW4_START, ROW4_END);
            EPD_PowerOff();
                        
        }
        
        if(SHIFT_BUTTON_PRESSED){ // move right to next digit position
            SHIFT_BUTTON_PRESSED = 0;
            digit_posn++;
            
            if(digit_posn > 3){
               digit_posn = 0; 
            }
            
            digit = 0;
        }
        
        if(ENTER_BUTTON_PRESSED){   // check if passwords match
            ENTER_BUTTON_PRESSED = 0;
           // pw_result = 0;
            //pw_result = 1;
            ENTER_FLAG = 1;
            EPD_Init();
            ClearDisplayRow(4);
            EPD_PowerOff();
        }
        
    }
}