/*! \brief Get UART data with timeout (8 bit character). * * \param usart The USART module. * \param timout The timeout.. * \param data The data to receive. */ bool USART_GetByte_Timeout(USART_t * usart, uint16_t timeout, uint8_t *pdata) { uint32_t ms_old_time, ms_time; RTC_GetCurrentTime(&ms_old_time); ms_time = ms_old_time; while( !USART_IsRXComplete(usart) && ms_time-ms_old_time < timeout ) { RTC_GetCurrentTime(&ms_time); //timeout_reg++; } if (!USART_IsRXComplete(usart) && ms_time-ms_old_time>=timeout) return 0; else *pdata = USART_GetChar(usart); return 1; }
static void DrawClockView(uint16_t context __attribute__ ((unused))) { struct time_t time; RTC_GetCurrentTime(&time); AdjustTimeForView(&time); libUI_Print("%02u:%02u", 45, UI_SINGLE_ROW, time.hour, time.minute); }
static void DrawDetailedTimeView(uint16_t context __attribute__ ((unused))) { struct time_t time; RTC_GetCurrentTime(&time); AdjustTimeForView(&time); libUI_Print("20%02u-%02u-%02u", 25, UI_DOUBLE_ROW_FIRST, time.year, time.month, time.date); libUI_Print("%02u:%02u:%02u", 34, UI_DOUBLE_ROW_SECOND, time.hour, time.minute, time.second); }
static void SendAck(uint8_t target) { struct time_t timestamp; if (RTC_GetCurrentTime(×tamp)) { Com_Send(target, COM_PACKET_TYPE_TIME, ×tamp, sizeof(timestamp)); } else { ErrorHandler_LogError(RTC_FAIL, 0); ERROR("Failed to get timestamp."); } return; }
/** * initialize the watch screen * @param param optional parameter */ void watch_Init( void *param ) { const char *dayOfWeekPtr; const char *monthsOfYearPtr; // Add image which indicate battery level to screen buffer GuiDriver_ImageAddToScr(&watch_imgBattery); // Create time label, initialize to current time, and add to screen GuiDriver_LabelCreate(&watch_labelTime); RTC_GetCurrentTime(&watch_time); snprintf( (char*)watch_labelTime.caption, 6, "%02d:%02d", watch_time.hour, watch_time.minute); GuiDriver_LabelAddToScr(&watch_labelTime); // Create date label, initialize to current date, and add to screen dayOfWeekPtr = watch_GetDayOfweek(&watch_time); monthsOfYearPtr = monthsOfYearStr[watch_time.month - 1]; GuiDriver_LabelCreate(&watch_labelDate); snprintf( (char*)watch_labelDate.caption, 12, "%s, %02d %s", dayOfWeekPtr, watch_time.day, monthsOfYearPtr); GuiDriver_LabelAddToScr(&watch_labelDate); // Create Enter label, and add to screen GuiDriver_LabelCreate(&watch_labelEnter); GuiDriver_LabelSetCaption(&watch_labelEnter, (uint8_t *) "Menu"); GuiDriver_LabelAddToScr(&watch_labelEnter); // Init label containing current temperature if ( ( GUI_STATUS_SUCCESS == GuiDriver_LabelCreate(&watch_labelTemp) ) && ( 0xFF != currTemp ) ) { snprintf( (char*)watch_labelTemp.caption, 4, "%d", currTemp); GuiDriver_LabelAddToScr(&watch_labelTemp); } /** check for the notifications */ if( 0 != Notification_GetUnreadCounter( NOTIF_TYPE_CALL ) ) { watch_imgCall.img = watch_phone_call_bmp; } else { watch_imgCall.img = watch_phone_call_gray_bmp; } if( 0 != Notification_GetUnreadCounter( NOTIF_TYPE_MAIL) ) { watch_imgMail.img = watch_mail_bmp; } else { watch_imgMail.img = watch_mail_gray_bmp; } if( 0 != Notification_GetUnreadCounter( NOTIF_TYPE_SMS ) ) { watch_imgSms.img = watch_sms_bmp; } else { watch_imgSms.img = watch_sms_gray_bmp; } GuiDriver_ImageAddToScr( &watch_imgCall ); GuiDriver_ImageAddToScr( &watch_imgMail); GuiDriver_ImageAddToScr( &watch_imgSms); // Add temp unit to screen GuiDriver_ImageAddToScr(&watch_imgTempUnit); if(watch_linkState == linkState_connected) { watch_imgBluetoothLogo.img = watch_bluetooth_logo_blue_bmp; } else { watch_imgBluetoothLogo.img = watch_bluetooth_logo_white_bmp; } // Add bluetooth icon image to screen GuiDriver_ImageAddToScr(&watch_imgBluetoothLogo); // Register for packets we want to receive if ( false == gui_sensorTag_IsActive() ) { GuiDriver_RegisterMinPollDelay( 100 ); GuiDriver_RegisterForSensors( PACKET_TEMP, 30000, true ); GuiDriver_RegisterForSensors( PACKET_BAT, 31000, false ); } else { GuiDriver_RegisterForSensors( PACKET_BAT, -1, false ); GuiDriver_RegisterForSensors( PACKET_TEMP, -1, true ); } }