uint32_t STATUS_HI_Process(uint32_t Key) { switch(Key) { case KEY_1_DOWN: BeepMilliseconds(300); PWMOutLowLast(); gNextStatus = STATUS_LOW; //為了按鍵後,不會馬上顯示情況的問題加的參數 LCD_Update(); u8_gWaitKey1Up = 1; break; case KEY_1_UP: if(u8_gWaitKey1Up != 0) { u8_gWaitKey1Up = 0; return STATUS_LOW; } break; case KEY_2_DOWN: BeepMilliseconds(300); PWMOutOff(); LCD_Update(); gNextStatus = STATUS_STOP; //為了按鍵後,不會馬上顯示情況的問題加的參數 return STATUS_STOP; } return STATUS_HI; }
/////////////////////////////////////////////////////////////////////////// // InputeBox // /////////////////////////////////////////////////////////////////////////// void InputBoxKbdHandler(unsigned char key) { switch(key){ case KBD_0: case KBD_1: case KBD_2: case KBD_3: case KBD_4: case KBD_5: case KBD_6: case KBD_7: case KBD_8: case KBD_9: if(_ibstr[_ibpos]){ _ibstr[_ibpos]=key; _ibpos++; if(_ibstr[_ibpos]){ if(_ibstr[_ibpos]!=0xBF) _ibpos++; } _TextXY(INPUTBOX_STR_POS,2,_ibstr,VATTR_NONE); _SetTextAttrXY(INPUTBOX_STR_POS+_ibpos,2,"0",MBATTR_INVERSE); LCD_Update(NULL); } break; case KBD_ARROW_H: if(_ibpos){ _SetTextAttrXY(INPUTBOX_STR_POS+_ibpos,2,"0",VATTR_NONE); _ibpos--; if((_ibstr[_ibpos]<KBD_0) | (_ibstr[_ibpos]>KBD_9)){ // if(_ibstr[_ibpos]!=0x20) _ibpos--; if(_ibpos) _ibpos--; } _ibstr[_ibpos]=0xBF; _TextXY(INPUTBOX_STR_POS,2,_ibstr,VATTR_NONE); _SetTextAttrXY(INPUTBOX_STR_POS+_ibpos,2,"0",MBATTR_INVERSE); // _TextXY(4,1,_ibstr,VATTR_NONE); LCD_Update(NULL); } break; case KBD_OK: VCL_SetRetVal(VCL_RET_OK); VCL_FreeMutex(); break; case KBD_CANCEL: VCL_SetRetVal(VCL_RET_CANCEL); VCL_FreeMutex(); break; } }
void Status_ProcessKey(uint32_t Key) { switch(gCurrentStatus) { case STATUS_STOP: gCurrentStatus = STATUS_STOP_Process(Key); break; case STATUS_HI: gCurrentStatus = STATUS_HI_Process(Key); break; case STATUS_STEP: gCurrentStatus = STATUS_STEP_Process(Key); break; case STATUS_LOW: gCurrentStatus = STATUS_LOW_Process(Key); break; } if(gCurrentStatusLast != gCurrentStatus) { gCurrentStatusLast = gCurrentStatus; LCD_Update(); } if(gCurrentStatus == STATUS_HI) { u8_gLastSpeed = LAST_SPEED_HI; } else if(gCurrentStatus == STATUS_LOW) { u8_gLastSpeed = LAST_SPEED_LO; } }
uint32_t STATUS_LOW_Process(uint32_t Key) { switch(Key) { case KEY_1_DOWN: BeepMilliseconds(300); PWMOutHigh(); gNextStatus = STATUS_HI; //為了按鍵後,不會馬上顯示情況的問題加的參數 LCD_Update(); u8_gWaitKey1Up = 1; u32_gKeyCounter = 0; break; case KEY_1_UP: if(u8_gWaitKey1Up != 0) { u8_gWaitKey1Up = 0; return STATUS_HI; } u32_gKeyCounter = 0; break; case KEY_2_DOWN: BeepMilliseconds(300); PWMOutOff(); u32_gKeyCounter = 0; gNextStatus = STATUS_STOP; //為了按鍵後,不會馬上顯示情況的問題加的參數 return STATUS_STOP; case KEY_3_DOWN: if(u32_gKeyCounter == 0) { u32_gKeyCounter = 1; LCD_UpdateSpeed(GetDutyCount() + 1); } else { PWMOutLowDecLevel(); } break; case KEY_4_DOWN: if(u32_gKeyCounter == 0) { u32_gKeyCounter = 1; LCD_UpdateSpeed(GetDutyCount() + 1); } else { PWMOutLowIncLevel(); } break; case KEY_4_UP: case KEY_3_UP: u32_gKeyCounter = 0; break; } return STATUS_LOW; }
int InputBox(const char *Title, char *iostr, int flag) { char ss[MAX_COLS+1]; int _vrmb[MAX_ROWS*MAX_COLS]; FKBDHANDLER prvkbdh; int _mutex; int i,ret; _mutex=VCL_SetMutex(); _ibpos=0; LCD_CopyVram(_vrmb); StrLimitLen((char*)Title,ss,MAX_COLS-2); // for(i=0;i<(MAX_COLS-2);i++){ // ss[i]=Title[i]; // if(Title[i]==0) break; // } // ss[i]=0; LCD_ScreenRect(); _TextXY(1,0,ss,VATTR_NONE); StrToTemplate(_ibstr,iostr,flag); if(strlen(iostr)){ // _ibstr[0]=0; _TextXY(INPUTBOX_STR_POS,1,iostr,VATTR_NONE); _TextXY(INPUTBOX_STR_POS,2,_ibstr,VATTR_NONE); _SetTextAttrXY(INPUTBOX_STR_POS,2,"0",MBATTR_INVERSE); } LCD_Update(NULL); prvkbdh=DISPATCH_SetKbdHandler(InputBoxKbdHandler); VCL_WaitMutex(_mutex); ret=VCL_GetRetVal(); if(ret==VCL_RET_OK){ for(i=0;i<14;i++){ if(_ibstr[i]==0xBF){ _ibstr[i]=0; break; } } strcpy(iostr,_ibstr); } LCD_Update(_vrmb); DISPATCH_SetKbdHandler(prvkbdh); return ret; }
/********************************************************************* * Function: void LCDTRXCount(uint8_t txCount, uint8_t rxCount) * * PreCondition: LCD has been initialized * * Input: txCount - the total number of transmitted messages * rxCount - the total number of received messages * * Output: None * * Side Effects: None * * Overview: This function display the total numbers of TX and * RX messages on the LCD, if applicable. * * Note: This routine is only effective if Explorer16 or * PIC18 Explorer demo boards are used ********************************************************************/ void LCDTRXCount(uint8_t txCount, uint8_t rxCount) { #if defined(SENSOR_PORT_LCD) LCD_Erase(); sprintf((char *)LCDText, (char*)"TX Messages: %3d", txCount); sprintf((char *)&(LCDText[16]), (char*)"RX Messages: %3d", rxCount); LCD_Update(); #endif }
/********************************************************************* * Function: void LCDTRXCount(uint8_t txCount, uint8_t rxCount) * * PreCondition: LCD has been initialized * * Input: txCount - the total number of transmitted messages * rxCount - the total number of received messages * * Output: None * * Side Effects: None * * Overview: This function display the total numbers of TX and * RX messages on the LCD, if applicable. * * Note: This routine is only effective if Explorer16 or * PIC18 Explorer demo boards are used ********************************************************************/ void LCDTRXCount(uint8_t txCount, uint8_t rxCount) { LCD_Erase(); sprintf((char *)LCDText, (char*)"TX Messages: %3d", txCount); sprintf((char *)&(LCDText[16]), (char*)"RX Messages: %3d", rxCount); LCD_Update(); }
int main(void) { init(); while(1) { LCD_Update(); SUP_Update(); LED_Update(); } return 0; }
int Info(char *str1,char *str2,char *str3,char *str4) { int _vrmb[MAX_ROWS*MAX_COLS]; FKBDHANDLER prvkbdh; int _mutex; _mutex=VCL_SetMutex(); LCD_CopyVram(_vrmb); _ClearScreen(); _TextXY(0,0,str1,VATTR_NONE); _TextXY(0,1,str2,VATTR_NONE); _TextXY(0,2,str3,VATTR_NONE); _TextXY(0,3,str4,VATTR_NONE); LCD_Update(NULL); prvkbdh=DISPATCH_SetKbdHandler(OkKbdHandler); VCL_WaitMutex(_mutex); DISPATCH_SetKbdHandler(prvkbdh); LCD_Update(_vrmb); return VCL_RET_OK; }
void MENU_Show(void) { int i; _ClearScreen(); for(i=0;i<_curmenu->Items; i++){ _TextXY(0,i,MENU_ICON,VATTR_NONE); if(*_mindex==i){ _TextXY(1,i,(char*)_curmenu->Item[i].Caption,MEMU_ATTR_INVERSE); }else{ _TextXY(1,i,(char*)_curmenu->Item[i].Caption,VATTR_NONE); } } LCD_Update(NULL); }
/********************************************************************* * Function: void LCD_Display(char *text, uint8_t value, bool delay) * * PreCondition: LCD has been initialized * * Input: text - text message to be displayed on LCD * value - the text message allows up to one byte * of variable in the message * delay - whether need to display the message for * 2 second without change * * Output: None * * Side Effects: None * * Overview: This function display the text message on the LCD, * including up to one uint8_t variable, if applicable. * * Note: This routine is only effective if Explorer16 or * PIC18 Explorer demo boards are used ********************************************************************/ void LCD_Display(char *text, uint8_t value, bool delay) { LCD_Erase(); sprintf((char *)LCDText, (char*)text, value); LCD_Update(); // display the message for 2 seconds if( delay ) { uint8_t i; for(i = 0; i < 8; i++) { DELAY_ms(250); } } }
void ListBox_Show(void) { int i,ii; _ClearScreen(); ii=MAX_ROWS; if(_lines<ii) ii=_lines; for(i=0; i<ii; i++){ _TextXY(0,i,LISTBOX_ICON,VATTR_NONE); if(i!=_indpos){ _TextXY(1,i,(char*)_ptext[_indx+i],VATTR_NONE); }else{ _TextXY(1,i,(char*)_ptext[_indx+i],VATTR_INVERSE); } } LCD_Update(NULL); }
/********************************************************************* * Function: void LCDDisplay(char *text, uint8_t value, bool delay) * * PreCondition: LCD has been initialized * * Input: text - text message to be displayed on LCD * value - the text message allows up to one byte * of variable in the message * delay - whether need to display the message for * 2 second without change * * Output: None * * Side Effects: None * * Overview: This function display the text message on the LCD, * including up to one uint8_t variable, if applicable. * * Note: This routine is only effective if Explorer16 or * PIC18 Explorer demo boards are used ********************************************************************/ void LCDDisplay(char *text, uint8_t value, bool delay) { #if defined(SENSOR_PORT_LCD) LCD_Erase(); sprintf((char *)LCDText, (char*)text, value); LCD_Update(); // display the message for 2 seconds if( delay ) { uint8_t i; for(i = 0; i < 8; i++) { DELAY_ms(250); } } #endif }
void MainMenuKbdHandler(U8 key) { switch(key){ case KBD_ARROW_V: _SetTextAttrXY(1,*_mindex,(char*)_curmenu->Item[*_mindex].Caption,VATTR_NONE); *_mindex +=1; if(*_mindex>=_curmenu->Items) *_mindex=0; _SetTextAttrXY(1,*_mindex,(char*)_curmenu->Item[*_mindex].Caption,MEMU_ATTR_INVERSE); LCD_Update(NULL); break; case KBD_ARROW_H: case KBD_OK: if(_curmenu->Item[*_mindex].MenuHandler){ _curmenu->Item[*_mindex].MenuHandler(); } break; case KBD_ON_REP: VCL_FreeMutex(); break; } }
char *ListBox(char **text,U8 lines) { int _vrmb[MAX_ROWS*MAX_COLS]; FKBDHANDLER prvkbdh; int _mutex,ret; _mutex=VCL_SetMutex(); LCD_CopyVram(_vrmb); _ptext=text; _indx=0; _lines=lines; _indpos=0; ListBox_Show(); prvkbdh=DISPATCH_SetKbdHandler(ListBoxKbdHandler); VCL_WaitMutex(_mutex); ret=VCL_GetRetVal(); LCD_Update(_vrmb); DISPATCH_SetKbdHandler(prvkbdh); if(ret==VCL_RET_CANCEL){ return 0; }else{ return _ptext[_indx+_indpos]; } }
/*! ******************************************************************************* * main program ******************************************************************************/ int main(void) { bool last_state_mnt; //!< motor mounted bool state_mnt; //!< motor mounted bool err; //!< error bool ref_pos_changed; //!< ref Position changed uint8_t last_statekey; //!< state of keys on last loop uint8_t last_second; //!< RTC-second of last main cycle uint8_t ref_position; //!< desired position in percent motor_speed_t speed; //!< motor speed (fast or quiet) uint8_t display_mode; //!< desired display output uint16_t value16; //!< 16 Bit value int16_t value16s; //!< signed 16 Bit value uint8_t value8; //!< 8 Bit value //! initalization init(); //! load/set default values load_defauls(); //! Enable interrupts sei(); //! show POST Screen LCD_AllSegments(LCD_MODE_ON); // all segments on delay(1000); LCD_AllSegments(LCD_MODE_OFF); LCD_PrintDec(REVHIGH, 1, LCD_MODE_ON); // print version LCD_PrintDec(REVLOW, 0, LCD_MODE_ON); LCD_Update(); delay(1000); LCD_AllSegments(LCD_MODE_OFF); // all off //! \todo Send Wakeup MSG state_mnt=false; ref_pos_changed=true; last_second=99; speed=full; last_statekey = 0; last_state_mnt = false; m_key_action = true; ref_position = 10; display_mode=3; ISR(PCINT1_vect); // get keystate // We should do the following once here to have valid data from the start ADC_Measure_Ub(); ADC_Measure_Temp(); /*! **************************************************************************** * main loop * * 1) process keypresses * - m_state_keys and m_wheel are set from IRQ, only process them * - you can set m_wheel to a new value * - controll content of LCD * 2) \todo calc new valveposition if new temp available * - temp is measured by IRQ * 3) calibrate motor * - start calibration is valve mounted changed to on * (during calibration the main loop stops at least for 10 seconds) * - reset calibration is valve mounted changed to off * 4) start motor if * - actual valveposition != desired valveposition && motor is off * 5) if motor is on call MOTOR_CheckBlocked at least once a second * - that switches motor of if it is blocked * 6) store keystate at end of loop before going to sleep * 7) Check for serial command to process * 8) \todo goto sleep if * - motor is of * - no key is pressed (AUTO, C, PROG) * - no serial communication active ***************************************************************************/ for (;;){ // change displaystate every 10 seconds 0 to 5 // Activate Auto Mode // setautomode(true); // 1) process keypresses if (m_key_action){ m_key_action = false; state_mnt = !(m_state_keys & KEYMASK_MOUNT); // State of keys AUTO, C and PROG and valve mounted if ((m_state_keys & KEYMASK_AUTO) != 0){ display_mode--; LCD_SetHourBarVal(display_mode, LCD_MODE_ON); ref_pos_changed = true; LCD_SetSeg(LCD_SEG_AUTO, LCD_MODE_ON); } else { LCD_SetSeg(LCD_SEG_AUTO, LCD_MODE_OFF); } if ((m_state_keys & KEYMASK_C) != 0){ if (display_mode==9){ m_reftemp = input_temp(m_reftemp); } //LCD_SetHourBarVal(display_mode, LCD_MODE_ON); //ref_pos_changed = true; //LCD_SetSeg(LCD_SEG_MANU, LCD_MODE_ON); } else { LCD_SetSeg(LCD_SEG_MANU, LCD_MODE_OFF); } if ((m_state_keys & KEYMASK_PROG)!= 0){ display_mode++; LCD_SetHourBarVal(display_mode+1, LCD_MODE_ON); ref_pos_changed = true; LCD_SetSeg(LCD_SEG_PROG, LCD_MODE_ON); } else { LCD_SetSeg(LCD_SEG_PROG, LCD_MODE_OFF); } } // 2) calc new valveposition if new temp available // - temp is measured by IRQ // 3) calibrate motor // - start calibration if valve is now mounted // TODO: // (during calibration the main loop stops for a long time // maybe add global var to cancel callibration, e.g.: if // HR20 removed from ther gear) // - reset calibration is valve mounted changed to off if (last_state_mnt != state_mnt) { MOTOR_SetMountStatus(state_mnt); if (state_mnt) { LCD_ClearNumbers(); LCD_PrintChar(LCD_CHAR_C, 3, LCD_MODE_ON); LCD_PrintChar(LCD_CHAR_A, 2, LCD_MODE_ON); LCD_PrintChar(LCD_CHAR_L, 1, LCD_MODE_ON); LCD_Update(); // DEBUG: if next line is disabled, not calibration and no // motor control is done // MOTOR_Calibrate(ref_position, speed); LCD_ClearNumbers(); } } // 4) start motor if // - actual valveposition != desired valveposition // - motor is off // - motor is calibrated if ((ref_pos_changed) && (MOTOR_IsCalibrated())){ err = MOTOR_Goto(ref_position, speed); ref_pos_changed = false; } // 5) if motor is on call MOTOR_CheckBlocked at least once a second // - that switches motor of if it is blocked if (MOTOR_On()){ if (last_second != RTC_GetSecond()){ MOTOR_CheckBlocked(); last_second = RTC_GetSecond(); } } // 6) store keystate at end of loop before going to sleep last_statekey = m_state_keys; last_state_mnt = state_mnt; // 7) Check if there is a serial command to process // Loop until all is processed e_meassure(); // test call to sample values and send them to serial port while( (COM_Process() == true) ){}; // 8) goto sleep if // - motor is of // - no key is pressed (AUTO, C, PROG) // - no serial communication active if (display_mode==1) { // Ub: ADC Value Hex ADC_Measure_Ub(); value16 = ADC_Get_Bat_Val(); LCD_PrintHexW(value16, LCD_MODE_ON); }else if (display_mode==2) { // Ub: ADC Value Decimal ADC_Measure_Ub(); value16 = ADC_Get_Bat_Val(); LCD_PrintDecW(value16, LCD_MODE_ON); }else if (display_mode==3) { // Ub: Voltage [mV] ADC_Measure_Ub(); value16 = ADC_Get_Bat_Voltage(); LCD_PrintDecW(value16, LCD_MODE_ON); }else if (display_mode==4) { // Temp: ADC Value Hex ADC_Measure_Temp(); value16 = ADC_Get_Temp_Val(); LCD_PrintHexW(value16, LCD_MODE_ON); }else if (display_mode==5) { // Temp: ADC Value Decimal ADC_Measure_Temp(); value16 = ADC_Get_Temp_Val(); LCD_PrintDecW(value16, LCD_MODE_ON); }else if (display_mode==6) { // Temp: Temperature (Degree) ADC_Measure_Temp(); value16s = ADC_Get_Temp_Degree(); LCD_PrintTempInt(value16s, LCD_MODE_ON); }else if (display_mode==7) { // - 9,87 °C value16s = -987; LCD_PrintTempInt(value16s, LCD_MODE_ON); }else if (display_mode==8) { // 98,76 °C value16s = 9876; LCD_PrintTempInt(value16s, LCD_MODE_ON); }else{ value16 = display_mode; LCD_PrintDecW(value16, LCD_MODE_ON); } /* // Bar 24 on if calibrated if (MOTOR_IsCalibrated()) { LCD_SetSeg(LCD_SEG_BAR24, LCD_MODE_ON); } else { LCD_SetSeg(LCD_SEG_BAR24, LCD_MODE_OFF); } // Hour 0 on if state_mnt if (state_mnt) { LCD_SetSeg(LCD_SEG_B0, LCD_MODE_ON); } else { LCD_SetSeg(LCD_SEG_B0, LCD_MODE_OFF); } // Hour 1 on if last_state_mnt if (last_state_mnt) { LCD_SetSeg(LCD_SEG_B1, LCD_MODE_ON); } else { LCD_SetSeg(LCD_SEG_B1, LCD_MODE_OFF); } if (!MOTOR_IsCalibrated()) { LCD_PrintChar(LCD_CHAR_E, 3, LCD_MODE_ON); LCD_PrintChar(LCD_CHAR_2, 2, LCD_MODE_ON); } else { LCD_PrintDec(ref_position, 1, LCD_MODE_ON); LCD_PrintDec(MOTOR_GetPosPercent(), 0, LCD_MODE_ON); } */ // impulses = MOTOR_GetImpulses(); // update Display each main loop LCD_Update(); } //End Main loop return 0; }
/*! ******************************************************************************* * main program ******************************************************************************/ int main(void) { //! initalization init(); task=0; //! Enable interrupts sei(); /* check EEPROM layout */ if (EEPROM_read((uint16_t)&ee_layout)!=EE_LAYOUT) { LCD_PrintStringID(LCD_STRING_EEPr,LCD_MODE_ON); task_lcd_update(); for(;;) {;} //fatal error, stop startup } COM_init(); // We should do the following once here to have valid data from the start /*! **************************************************************************** * main loop ***************************************************************************/ for (;;){ // go to sleep with ADC conversion start asm volatile ("cli"); if ( ! task && ((ASSR & (_BV(OCR2UB)|_BV(TCN2UB)|_BV(TCR2UB))) == 0) // ATmega169 datasheet chapter 17.8.1 ) { // nothing to do, go to sleep if(timer0_need_clock() || RS_need_clock()) { SMCR = (0<<SM1)|(0<<SM0)|(1<<SE); // Idle mode } else { if (sleep_with_ADC) { SMCR = (0<<SM1)|(1<<SM0)|(1<<SE); // ADC noise reduction mode } else { SMCR = (1<<SM1)|(1<<SM0)|(1<<SE); // Power-save mode } } if (sleep_with_ADC) { sleep_with_ADC=0; // start conversions ADCSRA |= (1<<ADSC); } DEBUG_BEFORE_SLEEP(); asm volatile ("sei"); // sequence from ATMEL datasheet chapter 6.8. asm volatile ("sleep"); asm volatile ("nop"); DEBUG_AFTER_SLEEP(); SMCR = (1<<SM1)|(1<<SM0)|(0<<SE); // Power-save mode } else { asm volatile ("sei"); } // update LCD task if (task & TASK_LCD) { task&=~TASK_LCD; task_lcd_update(); continue; // on most case we have only 1 task, iprove time to sleep } if (task & TASK_ADC) { task&=~TASK_ADC; if (task_ADC()==0) { // ADC is done // TODO } continue; // on most case we have only 1 task, iprove time to sleep } // communication if (task & TASK_COM) { task&=~TASK_COM; COM_commad_parse(); continue; // on most case we have only 1 task, iprove time to sleep } // motor stop if (task & TASK_MOTOR_STOP) { task&=~TASK_MOTOR_STOP; MOTOR_timer_stop(); continue; // on most case we have only 1 task, iprove time to sleep } // update motor possition if (task & TASK_MOTOR_PULSE) { task&=~TASK_MOTOR_PULSE; MOTOR_updateCalibration(mont_contact_pooling()); MOTOR_timer_pulse(); continue; // on most case we have only 1 task, iprove time to sleep } //! check keyboard and set keyboards events if (task & TASK_KB) { task&=~TASK_KB; task_keyboard(); } if (task & TASK_RTC) { task&=~TASK_RTC; { bool minute = RTC_AddOneSecond(); valve_wanted = CTL_update(minute,valve_wanted); if (minute && (RTC_GetDayOfWeek()==6) && (RTC_GetHour()==10) && (RTC_GetMinute()==0)) { // every sunday 10:00AM // TODO: improve this code! // valve protection / CyCL MOTOR_updateCalibration(0); } } MOTOR_updateCalibration(mont_contact_pooling()); MOTOR_Goto(valve_wanted); task_keyboard_long_press_detect(); if ((MOTOR_Dir==stop) || (config.allow_ADC_during_motor)) start_task_ADC(); if (menu_auto_update_timeout>=0) { menu_auto_update_timeout--; } menu_view(false); // TODO: move it, it is wrong place LCD_Update(); // TODO: move it, it is wrong place // do not use continue here (menu_auto_update_timeout==0) } // menu state machine if (kb_events || (menu_auto_update_timeout==0)) { bool update = menu_controller(false); if (update) { menu_controller(true); // menu updated, call it again } menu_view(update); // TODO: move it, it is wrong place LCD_Update(); // TODO: move it, it is wrong place } } //End Main loop
/*! ******************************************************************************* * \brief menu View ******************************************************************************/ void menu_view(bool clear) { switch (menu_state) { case menu_startup: LCD_AllSegments(LCD_MODE_ON); // all segments on break; case menu_version: clr_show1(LCD_SEG_COL1); LCD_PrintHexW(VERSION_N,LCD_MODE_ON); break; #if (! REMOTE_SETTING_ONLY) case menu_set_year: LCD_AllSegments(LCD_MODE_OFF); // all segments off LCD_PrintDecW(RTC_GetYearYYYY(),LCD_MODE_BLINK_1); break; case menu_set_month: case menu_set_day: clr_show1(LCD_SEG_COL1); // decimal point LCD_PrintDec(RTC_GetMonth(), 0, ((menu_state==menu_set_month)?LCD_MODE_BLINK_1:LCD_MODE_ON)); LCD_PrintDec(RTC_GetDay(), 2, ((menu_state==menu_set_day)?LCD_MODE_BLINK_1:LCD_MODE_ON)); break; case menu_set_hour: case menu_set_minute: case menu_home4: // time #if HAVE_NEWLCD if (clear) clr_show1(LCD_SEG_COL2); #else if (clear) clr_show2(LCD_SEG_COL1,LCD_SEG_COL2); #endif LCD_PrintDec(RTC_GetHour(), 2, ((menu_state == menu_set_hour) ? LCD_MODE_BLINK_1 : LCD_MODE_ON)); LCD_PrintDec(RTC_GetMinute(), 0, ((menu_state == menu_set_minute) ? LCD_MODE_BLINK_1 : LCD_MODE_ON)); break; #else case menu_home4: // time #if HAVE_NEWLCD if (clear) clr_show1(LCD_SEG_COL2); #else if (clear) clr_show2(LCD_SEG_COL1,LCD_SEG_COL2); #endif LCD_PrintDec(RTC_GetHour(), 2, LCD_MODE_ON); LCD_PrintDec(RTC_GetMinute(), 0, LCD_MODE_ON); break; #endif #if MENU_SHOW_BATTERY case menu_home5: // battery LCD_AllSegments(LCD_MODE_OFF); LCD_PrintDec(bat_average/100, 2, LCD_MODE_ON); LCD_PrintDec(bat_average%100, 0, LCD_MODE_ON); break; #endif case menu_home: // wanted temp / error code / adaptation status if (MOTOR_calibration_step>0) { clr_show1(LCD_SEG_BAR24); LCD_PrintChar(LCD_CHAR_A,3,LCD_MODE_ON); if (MOTOR_ManuCalibration==-1) LCD_PrintChar(LCD_CHAR_d,2,LCD_MODE_ON); LCD_PrintChar(LCD_CHAR_0 + (MOTOR_calibration_step%10), 0, LCD_MODE_ON); goto MENU_COMMON_STATUS; // optimization } else { if (clear) clr_show1(LCD_SEG_BAR24); if (CTL_error!=0) { #if HAVE_NEWLCD==0 if (CTL_error & CTL_ERR_BATT_LOW) { LCD_PrintStringID(LCD_STRING_BAtt,LCD_MODE_BLINK_1); } else #endif if (CTL_error & CTL_ERR_MONTAGE) { LCD_PrintStringID(LCD_STRING_E2,LCD_MODE_ON); } else if (CTL_error & CTL_ERR_MOTOR) { LCD_PrintStringID(LCD_STRING_E3,LCD_MODE_ON); } else #if HAVE_NEWLCD==0 if (CTL_error & CTL_ERR_BATT_WARNING) { LCD_PrintStringID(LCD_STRING_BAtt,LCD_MODE_ON); } else #endif if (CTL_error & CTL_ERR_RFM_SYNC) { LCD_PrintStringID(LCD_STRING_E4,LCD_MODE_ON); } goto MENU_COMMON_STATUS; // optimization } else { if (mode_window()) { LCD_PrintStringID(LCD_STRING_OPEn,LCD_MODE_ON); goto MENU_COMMON_STATUS; // optimization } } } // do not use break at this position / optimization case menu_home_no_alter: // wanted temp if (clear) clr_show1(LCD_SEG_BAR24); LCD_PrintTemp(CTL_temp_wanted,LCD_MODE_ON); //! \note hourbar status calculation is complex we don't want calculate it every view, use chache MENU_COMMON_STATUS: LCD_SetSeg(LCD_SEG_AUTO, (CTL_test_auto()?LCD_MODE_ON:LCD_MODE_OFF)); LCD_SetSeg(LCD_SEG_MANU, (CTL_mode_auto?LCD_MODE_OFF:LCD_MODE_ON)); #if HAVE_NEWLCD if (CTL_error & (CTL_ERR_BATT_LOW | CTL_ERR_BATT_WARNING)) LCD_SetSeg(LCD_SEG_BAT, (CTL_error & CTL_ERR_BATT_LOW)?LCD_MODE_BLINK_1:LCD_MODE_ON); #endif LCD_HourBarBitmap(hourbar_buff); break; case menu_home2: // real temperature if (clear) LCD_AllSegments(LCD_MODE_OFF); LCD_PrintTempInt(temp_average,LCD_MODE_ON); break; case menu_home3: // valve pos if (clear) LCD_AllSegments(LCD_MODE_OFF); // LCD_PrintDec3(MOTOR_GetPosPercent(), 1 ,LCD_MODE_ON); // LCD_PrintChar(LCD_CHAR_2lines,0,LCD_MODE_ON); { uint8_t prc = MOTOR_GetPosPercent(); if (prc<=100) { LCD_PrintDec3(MOTOR_GetPosPercent(), 0 ,LCD_MODE_ON); } else { LCD_PrintStringID(LCD_STRING_minusCminus,LCD_MODE_ON); } } break; #if (! REMOTE_SETTING_ONLY) case menu_set_timmer_dow: clr_show1(LCD_SEG_PROG); // all segments off LCD_PrintDayOfWeek(menu_set_dow, LCD_MODE_BLINK_1); break; case menu_set_timmer: //! \todo calculate "hourbar" status, actual position in mode LCD_MODE_BLINK_1 // clr_show3(LCD_SEG_COL1,LCD_SEG_COL2,LCD_SEG_PROG); clr_show2(LCD_SEG_COL1,LCD_SEG_COL2); timmers_patch_offset=timers_get_raw_index(menu_set_dow, menu_set_slot); timmers_patch_data = menu_set_time + ((uint16_t)menu_set_mode<<12); LCD_HourBarBitmap(RTC_DowTimerGetHourBar(menu_set_dow)); timmers_patch_offset=0xff; LCD_SetHourBarSeg(menu_set_time/60, LCD_MODE_BLINK_1); if (menu_set_time < 24*60) { LCD_PrintDec(menu_set_time/60, 2, LCD_MODE_BLINK_1); LCD_PrintDec(menu_set_time%60, 0, LCD_MODE_BLINK_1); } else { LCD_PrintStringID(LCD_STRING_4xminus,LCD_MODE_BLINK_1); } show_selected_temperature_type(menu_set_mode,LCD_MODE_BLINK_1); break; #endif case menu_lock: // "bloc" message LCD_AllSegments(LCD_MODE_OFF); // all segments off LCD_PrintStringID(LCD_STRING_bloc,LCD_MODE_ON); break; case menu_service1: case menu_service2: // service menu; left side index, right value LCD_AllSegments(LCD_MODE_ON); LCD_PrintHex(service_idx, 2, ((menu_state == menu_service1) ? LCD_MODE_BLINK_1 : LCD_MODE_ON)); LCD_PrintHex(config_raw[service_idx], 0, ((menu_state == menu_service2) ? LCD_MODE_BLINK_1 : LCD_MODE_ON)); break; case menu_service_watch: LCD_AllSegments(LCD_MODE_ON); LCD_PrintHexW(watch(service_watch_n),LCD_MODE_ON); LCD_SetHourBarSeg(service_watch_n, LCD_MODE_BLINK_1); break; #if (! REMOTE_SETTING_ONLY) case menu_preset_temp0: case menu_preset_temp1: case menu_preset_temp2: case menu_preset_temp3: LCD_AllSegments(LCD_MODE_OFF); LCD_PrintTemp(menu_set_temp,LCD_MODE_BLINK_1); show_selected_temperature_type(menu_state-menu_preset_temp0,LCD_MODE_ON); #endif default: break; } LCD_Update(); }
/******************************************************************************* * Function Name : WavePlayer_StartSpeaker * Description : Starts the wave player application. * Input : None * Output : None * Return : None *******************************************************************************/ void WavePlayer_StartSpeaker(void) { uint8_t MyKey = 0; uint32_t err = 0, Counter = 0x0; LCD_Clear(White); /* Disable the JoyStick interrupts */ IntExtOnOffConfig(DISABLE); while(ReadKey() != NOKEY) { } /* Display the welcome screen and the commands */ LCD_Update(ALL); /* Choose number of repetitions: 0 => infinite repetitions */ I2S_CODEC_ReplayConfig(0); I2S_CODEC_Init(OutputDevice_SPEAKER, AUDIO_FILE_ADDRESS); /* Endless loop */ while(1) { /* Check which key is pressed */ MyKey = ReadKey(); if(Counter == 0) { /* Mask All Interrupts */ __disable_irq(); /* Update the displayed progression information */ LCD_Update(PROGRESS); Counter = 0x5FFFF; /* Disable mask of all interrupts */ __enable_irq(); } Counter--; /* If "UP" pushbutton is pressed */ if(MyKey == UP) { /* Mask All Interrupts */ __disable_irq(); /* Check if the Codec is PLAYING audio file */ if (GetVar_AudioPlayStatus() == AudioPlayStatus_PLAYING) { I2S_CODEC_ControlVolume(VolumeDirection_HIGH, VOLStep); /* Update the display information */ LCD_Update(VOL); } /* UP bottomn pushed in PAUSE mode => Enable the Speaker device output ---*/ else { /* Update the display information */ LCD_Update(PLAY); /* Configure the Speaker as output and reinitialize all devices */ err = I2S_CODEC_SpeakerHeadphoneSwap(OutputDevice_SPEAKER, AUDIO_FILE_ADDRESS); /* Error message display if failure */ if (err != 0) { LCD_DisplayError(err); /* Enable the FSMC that share a pin w/ I2C1 (LBAR) */ RCC_AHBPeriphClockCmd(RCC_AHBPeriph_FSMC, ENABLE); /* Clear the LCD */ LCD_Clear(White); /* Display the previous menu */ DisplayMenu(); /* Disable mask of all interrupts */ __enable_irq(); /* Enable the JoyStick interrupts */ IntExtOnOffConfig(ENABLE); return; } } /* Disable mask of all interrupts */ __enable_irq(); } /* If "DOWN" pushbutton is pressed */ if(MyKey == DOWN) { /* Mask All Interrupts */ __disable_irq(); /* If the Codec is PLAYING => Decrease Volume*/ if (GetVar_AudioPlayStatus() == AudioPlayStatus_PLAYING) { /* Increase the audio codec digital volume */ I2S_CODEC_ControlVolume(VolumeDirection_LOW, VOLStep); /* Update the LCD display */ LCD_Update(VOL); } else /* If the Codec is PAUSED => Headphone Enable */ { /* Update the LCD display */ LCD_Update(PLAY); /* Enable the Headphone output and reinitialize all devices */ err = I2S_CODEC_SpeakerHeadphoneSwap(OutputDevice_HEADPHONE, AUDIO_FILE_ADDRESS); /* Error message display if failure */ if (err != 0) { LCD_DisplayError(err); /* Enable the FSMC that share a pin w/ I2C1 (LBAR) */ RCC_AHBPeriphClockCmd(RCC_AHBPeriph_FSMC, ENABLE); /* Clear the LCD */ LCD_Clear(White); /* Display the previous menu */ DisplayMenu(); /* Disable mask of all interrupts */ __enable_irq(); /* Enable the JoyStick interrupts */ IntExtOnOffConfig(ENABLE); return; } } /* Disable mask of all interrupts */ __enable_irq(); } /* If "RIGHT" pushbutton is pressed */ if(MyKey == RIGHT) { /* Mask All Interrupts */ __disable_irq(); /* Check if the Codec is PLAYING audio file */ if (GetVar_AudioPlayStatus() == AudioPlayStatus_PLAYING) { I2S_CODEC_ForwardPlay(STEP_FORWARD); /* Update the display information */ LCD_Update(FRWD); } /* Disable mask of all interrupts */ __enable_irq(); } /* If "LEFT" pushbutton is pressed */ if(MyKey == LEFT) { /* Mask All Interrupts */ __disable_irq(); /* Check if the Codec is PLAYING audio file */ if (GetVar_AudioPlayStatus() == AudioPlayStatus_PLAYING) { I2S_CODEC_RewindPlay(STEP_BACK); /* Update the display information */ LCD_Update(FRWD); } /* Disable mask of all interrupts */ __enable_irq(); } /* If "SEL" pushbutton is pressed */ if(MyKey == SEL) { /* Mask All Interrupts */ __disable_irq(); /* Update the display information */ LCD_Update(STOP); /* Command the Stop of the current audio stream */ SetVar_AudioPlayStatus(AudioPlayStatus_STOPPED); /* Disable mask of all interrupts */ __enable_irq(); I2S_CODEC_Stop(); SPI_I2S_ITConfig(SPI2, SPI_I2S_IT_TXE, DISABLE); /* Enable the FSMC that share a pin w/ I2C1 (LBAR) */ RCC_AHBPeriphClockCmd(RCC_AHBPeriph_FSMC, ENABLE); /* Clear the LCD */ LCD_Clear(White); /* Display the previous menu */ DisplayMenu(); /* Enable the JoyStick interrupts */ IntExtOnOffConfig(ENABLE); return; } /* If "KEY" pushbutton is pressed */ if(MyKey == KEY) { /* Mask All Interrupts */ __disable_irq(); /* If the Codec is Playing => PAUSE */ if (GetVar_AudioPlayStatus() == AudioPlayStatus_PLAYING) { /* Update the display information */ LCD_Update(PAUSE); /* Command the Pause of the current stream */ SetVar_AudioPlayStatus(AudioPlayStatus_PAUSED); } /* If the Codec is PAUSED => Resume PLAYING */ else if (GetVar_AudioPlayStatus() == AudioPlayStatus_PAUSED) { /* Update the LCD display */ LCD_Update(PLAY); /* Start playing from the last saved position */ I2S_CODEC_Play(GetVar_AudioDataIndex()); } /* If the Codec is STOPPED => PLAY from the file start address */ else if (GetVar_AudioPlayStatus() == AudioPlayStatus_STOPPED) { /* Update the display information */ LCD_Update(PLAY); /* Initialize all devices w/choosen parameters */ err = I2S_CODEC_Init(GetVar_CurrentOutputDevice(), AUDIO_FILE_ADDRESS); /* Error message display if failure */ if (err != 0) { LCD_DisplayError(err); /* Enable the FSMC that share a pin w/ I2C1 (LBAR) */ RCC_AHBPeriphClockCmd(RCC_AHBPeriph_FSMC, ENABLE); /* Clear the LCD */ LCD_Clear(White); /* Display the previous menu */ DisplayMenu(); /* Disable mask of all interrupts */ __enable_irq(); /* Enable the JoyStick interrupts */ IntExtOnOffConfig(ENABLE); return; } /* Enable Playing the audio file */ I2S_CODEC_Play(GetVar_DataStartAddr()); } /* Disable mask of all interrupts */ __enable_irq(); } } }
void run_star_demo(void) { #if defined(PROTOCOL_STAR) t1 = MiWi_TickGet(); LCDDisplay((char *)"Sleeping!!", 0, false); while(1) { t2 = MiWi_TickGet(); // Calculate the Time for Sleeping device if((MiWi_TickGetDiff(t2,t1) > (ONE_SECOND * 20))) { awake = true; #if !defined(EIGHT_BIT_WIRELESS_BOARD) LCD_BacklightON(); #endif MiApp_TransceiverPowerState(POWER_STATE_WAKEUP_DR); LCDDisplay((char *)"Woke Up!!!", 0, false); DELAY_ms(1000); STAR_DEMO_OPTIONS_MESSAGE (false); tt1 = MiWi_TickGet(); } while(awake) { tt2 = MiWi_TickGet(); if((MiWi_TickGetDiff(tt2,tt1) > (ONE_SECOND * 10))) { // The Indirect Message for a Sleeping RFD is stored in PAN CO // We periodically send Data Requests for the Indirect Message to // not loose a message. CheckForData(); tt1 = MiWi_TickGet(); } /*******************************************************************/ // Function MiApp_MessageAvailable returns a boolean to indicate if // a packet has been received by the transceiver. If a packet has // been received, all information will be stored in the rxFrame, // structure of RECEIVED_MESSAGE. /*******************************************************************/ if( MiApp_MessageAvailable()) { /*******************************************************************/ // If a packet has been received, update the information available // in rxMessage. /*******************************************************************/ DemoOutput_UpdateTxRx(TxNum, ++RxNum); DELAY_ms(2000); // Toggle LED2 to indicate receiving a packet. LED_2 ^= 1; /*******************************************************************/ // Function MiApp_DiscardMessage is used to release the current // received packet. // After calling this function, the stack can start to process the // next received frame /*******************************************************************/ MiApp_DiscardMessage(); /****************************************/ } else { /*******************************************************************/ // If no packet received, now we can check if we want to send out // any information. // Function ButtonPressed will return if any of the two buttons // has been pushed. /*******************************************************************/ uint8_t PressedButton = ButtonPressed(); if ( PressedButton == 1 || PressedButton == 2) { uint8_t select_ed =0; bool update_ed = true; while(update_ed == true) { //User Selected Change end device LCD_Erase(); if (myConnectionIndex_in_PanCo == select_ed) { // if END_device displays itself , "me" is added in display to denote itself sprintf((char *)LCDText, (char*)"RB0:%02d-%02x%02x%02x-me",END_DEVICES_Short_Address[select_ed].connection_slot,END_DEVICES_Short_Address[select_ed].Address[0], END_DEVICES_Short_Address[select_ed].Address[1],END_DEVICES_Short_Address[select_ed].Address[2] ); } else { sprintf((char *)LCDText, (char*)"RB0:%02d-%02x%02x%02x",END_DEVICES_Short_Address[select_ed].connection_slot,END_DEVICES_Short_Address[select_ed].Address[0], END_DEVICES_Short_Address[select_ed].Address[1],END_DEVICES_Short_Address[select_ed].Address[2] ); } sprintf((char *)LCDText, (char*)"RB0:%02d-%02x%02x%02x",END_DEVICES_Short_Address[select_ed].connection_slot,END_DEVICES_Short_Address[select_ed].Address[0], END_DEVICES_Short_Address[select_ed].Address[1],END_DEVICES_Short_Address[select_ed].Address[2] ); sprintf((char *)&(LCDText[16]), (char*)"RB2: Change node"); LCD_Update(); chk_sel_status = true; bool sw_layer_ack_status , mac_ack_status; while(chk_sel_status) { uint8_t switch_val = ButtonPressed(); if(switch_val == 1) { update_ed = false; chk_sel_status = false; update_ed = false; // Star_User_Data is defined in star_demo.c // Its user data , in case of Star Network 60 bytes of // Data can be sent at a time from one END_DEVICE_TO_ANOTHER // Edx --> Pan CO --> EDy if (myConnectionIndex_in_PanCo == select_ed) { MiApp_FlushTx(); for (i = 0 ; i < 21 ; i++) { MiApp_WriteData(MiWi[(TxSynCount%6)][i]); } // IF on the demo , a END_Device displays its own Connection Detail // We unicast data packet to just PAN COR , No forwarding #if defined(ENABLE_SECURITY) mac_ack_status = MiApp_UnicastConnection (0, true); #else mac_ack_status = MiApp_UnicastConnection (0, false); #endif TxNum++; } else { // Data can be sent at a time from one END_DEVICE_TO_ANOTHER // Edx --> Pan CO --> EDy // To forward a Packet from one ED to another ED , the first 4 bytes should holding // a CMD and end dest device short address (3 bytes) MiApp_FlushTx(); MiApp_WriteData(CMD_FORWRD_PACKET); MiApp_WriteData(END_DEVICES_Short_Address[select_ed].Address[0]);// sending the first byte payload as the destination nodes MiApp_WriteData(END_DEVICES_Short_Address[select_ed].Address[1]);// sending the first byte payload as the destination nodes MiApp_WriteData(END_DEVICES_Short_Address[select_ed].Address[2]);// sending the first byte payload as the destination nodes for (i = 4 ; i < 25 ; i++) { MiApp_WriteData(MiWi[(TxSynCount%6)][i-4]); } #if defined(ENABLE_SECURITY) sw_layer_ack_status = MiApp_UnicastStar (true); #else sw_layer_ack_status = MiApp_UnicastStar (false); #endif #if defined(ENABLE_APP_LAYER_ACK) if (sw_layer_ack_status) { TxNum++; // Tx was successful } else { LCDDisplay((char *)"Data_Sending_Fail!!", 0, false); } #else TxNum++; #endif } } // end of switch_val == 1 else if(switch_val == 2) { if (select_ed > end_nodes-1) { select_ed = 0; } else { select_ed = select_ed+1; } chk_sel_status = false; } // end of switch_val == 2 } // end of chk_sel_status } // end of updating the LCD info STAR_DEMO_OPTIONS_MESSAGE (false); } // end of actions on button press } // end of check for user inputs (button press check) t3 = MiWi_TickGet(); if((MiWi_TickGetDiff(t3,t2) > (ONE_SECOND * 40))) { awake = false; #if !defined(EIGHT_BIT_WIRELESS_BOARD) LCD_BacklightOFF(); #endif MiApp_TransceiverPowerState(POWER_STATE_SLEEP); LCDDisplay((char *)"Sleeping!!!", 0, false); DELAY_ms(1000); t1 = t3; } if (lost_connection && !role) { MiApp_EstablishConnection(0xFF, CONN_MODE_DIRECT); lost_connection = false; } } // end of actions performed while node is awake } // end of while(1) #endif }
void main (void) { uint8_t i; SYSTEM_Initialize(); CONSOLE_Initialize(); /*******************************************************************/ // Initialize the system /*******************************************************************/ /*******************************************************************/ // Following block display demo information on LCD of Explore 16 or // PIC18 Explorer demo board. /*******************************************************************/ LCDDisplay((char *)"Chat Demo", 0, true); // Clear the screen (VT100) Printf("\x1b[2J"); // Send the cursor home (VT100) Printf("\x1b[H"); Printf("\r\nChat Demo"); #if defined(MRF24J40) Printf("\r\nRF Transceiver: MRF24J40"); #elif defined(MRF49XA) Printf("\r\nRF Transceiver: MRF49XA"); #elif defined(MRF89XA) Printf("\r\nRF Transceiver: MRF89XA"); #endif Printf("\r\n\r\nDemo Instruction:"); Printf("\r\nUse Console to Chat with the Peer Device"); Printf("\r\n"); LED_1 = 0; LED_2 = 0; /******************************************************************/ // Read the MAC address from the MAC EEPROM on the PICTail Card ReadMacAddress(); // ..and display on terminal Printf("\r\n\r\nMy MAC Address: 0x"); for(i = 0; i < MY_ADDRESS_LENGTH; i++) { CONSOLE_PrintHex(myLongAddress[MY_ADDRESS_LENGTH-1-i]); } /*******************************************************************/ // Initialize Microchip proprietary protocol. Which protocol to use // depends on the configuration in ConfigApp.h /*******************************************************************/ /*******************************************************************/ // Function MiApp_ProtocolInit initialize the protocol stack. The // only input parameter indicates if previous network configuration // should be restored. In this simple example, we assume that the // network starts from scratch. /*******************************************************************/ MiApp_ProtocolInit(false); // Set default channel if(MiApp_SetChannel(myChannel) == false) { Printf("\r\nERROR: Unable to program the channel\r\n"); Printf("\r\nPress MCLR to start again\r\n"); LCDDisplay((char *)"Error: Unable to Program Channel ", 0, TRUE); while(1); //Display error message on LCD and Console } /*******************************************************************/ // Function MiApp_ConnectionMode defines the connection mode. The // possible connection modes are: // ENABLE_ALL_CONN: Enable all kinds of connection // ENABLE_PREV_CONN: Only allow connection already exists in // connection table // ENABL_ACTIVE_SCAN_RSP: Allow response to Active scan // DISABLE_ALL_CONN: Disable all connections. /*******************************************************************/ MiApp_ConnectionMode(ENABLE_ALL_CONN); /*******************************************************************/ // Display current opertion on LCD of demo board, if applicable /*******************************************************************/ LCDDisplay((char *)"Connecting Peer on Channel %d ", myChannel, true); Printf("\r\n\r\nConnecting to Peer...\r\n"); /*******************************************************************/ // Function MiApp_StartConnection will enable a node to start operating // in a variety of ways. Usually, this fucntion is called by the // PAN Coordinator who is the first in the PAN. // // The first parameter defines the mode to start the PAN in // // The second parameter defines the scan duration (if energy/carrier // sense scan is enabled). 0 if START_CONN_DIRECT used. // // The third parameter is a bit map of of the channels to perform the // noise scan on. 0 if START_CONN_DIRECT used. /*******************************************************************/ MiApp_StartConnection(START_CONN_DIRECT, 0, 0) ; /*******************************************************************/ // Function MiApp_EstablishConnection try to establish a new // connection with peer device. // The first parameter is the index to the active scan result, // which is acquired by discovery process (active scan). If // the value of the index is 0xFF, try to establish a // connection with any peer. // The second parameter is the mode to establish connection, // either direct or indirect. Direct mode means connection // within the radio range; indirect mode means connection // may or may not in the radio range. /*******************************************************************/ #ifdef ENABLE_HAND_SHAKE i = 0xFF; while(i == 0xFF) { i = MiApp_EstablishConnection(0xFF, CONN_MODE_DIRECT); } #endif /*******************************************************************/ // Display current opertion on LCD of demo board, if applicable /*******************************************************************/ LCDDisplay((char *)"Joined Network Successfully..", 0, true); /*******************************************************************/ // Function DumpConnection is used to print out the content of the // Connection Entry on the hyperterminal. It may be useful in // the debugging phase. // The only parameter of this function is the index of the // Connection Entry. The value of 0xFF means to print out all // valid Connection Entry; otherwise, the Connection Entry // of the input index will be printed out. /*******************************************************************/ #ifdef ENABLE_DUMP DumpConnection(0xFF); #endif #ifndef ENABLE_POWERSAVE // Turn on LED 1 to indicate P2P connection established LED_1 = 1; #endif DELAY_ms(100); LCDBacklightON(); LCD_Erase(); sprintf((char *)LCDText, (char *)"MyAddr: %02x%02x%02x", myLongAddress[2], myLongAddress[1], myLongAddress[0]); sprintf((char *) &(LCDText[16]), (char *)"PeerAddr: %02x%02x%02x", ConnectionTable[i].Address[2], ConnectionTable[i].Address[1], ConnectionTable[i].Address[0]); LCD_Update(); /*******************************************************************/ // Following block display demo instructions on LCD based on the // demo board used. /*******************************************************************/ Printf("-------------------------------------------------------\r\n"); Printf("Chat Window: \r\n"); Printf("-------------------------------------------------------\r\n"); Printf("$$"); while(1) { if(MiApp_MessageAvailable()) { ProcessRxMessage(); } if(CONSOLE_IsGetReady()) { FormatTxMessage(); } if(messagePending) { tickCurrent = MiWi_TickGet(); if ( (MiWi_TickGetDiff(tickCurrent, tickPrevious) > (ONE_SECOND * 30)) || (TxMessageSize >= MAX_MESSAGE_LEN) || (transmitPending == true) ) { TransmitMessage(); } } // Display connection table if RB0 is pressed if(PUSH_BUTTON_1 == 0) { while(PUSH_BUTTON_1 == 0); Printf("\r\n\r\nDumping Connection Table...\r\n"); DumpConnection(0xFF); Printf("-------------------------------------------------------\r\n"); Printf("Chat Window: \r\n"); Printf("-------------------------------------------------------\r\n"); Printf("$$ "); } } //Enable device to foward the received packet information to the console } //end of main
void print(unsigned char* msg) { LCD_String_5X7( myconsolex*6, myconsoley*8, msg, 1); myconsolex = myconsolex + strlen((char*)msg); LCD_Update(); }
uint32_t STATUS_STOP_Process(uint32_t Key) { uint32_t u32Meter; uint32_t u32MaxMeter; if(u32UpdateCount > 0) { u32UpdateCount--; } else { u32UpdateCount = 30000; LCD_Update(); } switch(Key) { case KEY_1_DOWN: LCD_Update(); u32Meter = GetMeterCount(); u32MaxMeter = GetMaxMeterCount(); //有以下情況時停止Key 1 if( (u32MaxMeter >= 100 && u32Meter <= 5 && u32Meter != 0) //100米以上5米停 ||(u32MaxMeter >= 75 && u32MaxMeter < 100 && u32Meter <= 4 && u32Meter != 0) //100~75米含75米不含100米,4米停 ||(u32MaxMeter >= 50 && u32MaxMeter < 75 && u32Meter <= 3 && u32Meter != 0) //75~50米含50米不含75米,3米停 ||(u32MaxMeter < 50 && u32Meter <= 2 && u32Meter != 0) //50米以下,2米停 ) { return STATUS_STOP; } else { BeepMilliseconds(300); PWMOutLowLast(); gNextStatus = STATUS_LOW; //為了按鍵後,不會馬上顯示情況的問題加的參數 LCD_Update(); u8_gWaitKey1Up = 1; } break; case KEY_1_UP: if(u8_gWaitKey1Up != 0) { u8_gWaitKey1Up = 0; return STATUS_LOW; } break; case KEY_2_DOWN: BeepMilliseconds(300); if(u8_gLastSpeed == LAST_SPEED_LO) { PWMOutLowLast(); } else { PWMOutHigh(); } gNextStatus = STATUS_STEP; //為了按鍵後,不會馬上顯示情況的問題加的參數 LCD_Update(); return STATUS_STEP; case KEY_3_DOWN: LCD_Update(); if(u8_gKey3_LongKey_Setted == 0) { u8_gKey3_Down++; if(u8_gKey3_Down > 3) { // 長按 u8_gKey3_LongKey_Setted = 1; backLightOnOff(); LCD_Update(); } } //短按無動作,所以marked // else // { // // } break; case KEY_3_UP: u8_gKey3_Down = 0; // 如果前一個已經放了但是還是設定EL的,還是不動作。 if(u8_gKey3_LongKey_Setted == 0) { //短按 BottomSet(); gNextStatus = STATUS_STOP; //為了按鍵後,不會馬上顯示情況的問題加的參數 return STATUS_STOP; } //長按動作不在KeyUP, 以下marked. // else // { // } u8_gKey3_LongKey_Setted = 0;//可以接受下一次LED設定。 break; case KEY_4_DOWN: u32Meter = GetMeterCount(); if(u32Meter != 0) { BeepMilliseconds(300); LCD_Update(); u8_gKey4_Down = 0; CounterClear(); } break; } return STATUS_STOP; }