/* Send interrupt notification to the phone or * read data from the accelerometer and send it to the phone */ static void AccelerometerSendDataHandler(void) { tMessage Msg = {3, AccelIndMsg, MSG_OPT_NONE, NULL}; if (CreateMessage(&Msg)) { if (Control & DRDYE_DATA_AVAILABLE || (Control & WUF_ENABLE)) { AccelerometerRead(Control & DRDYE_DATA_AVAILABLE ? KIONIX_XOUT_L : KIONIX_XOUT_HPF_L, Data, XYZ_DATA_LENGTH); Msg.pBuffer[0] = Data[1]; Msg.pBuffer[1] = Data[3]; Msg.pBuffer[2] = Data[5]; RouteMsg(&Msg); // PrintQ(Msg.pBuffer, 3); } else if (Control & TILT_ENABLE_TPE) { AccelerometerRead(KIONIX_TILT_POS_CUR, Msg.pBuffer, ONE_BYTE); Msg.Length = 1; RouteMsg(&Msg); PrintH(Msg.pBuffer[0]); PrintR(); } AccelerometerRead(KIONIX_INT_REL, Data, ONE_BYTE); //clear int } }
int menu_button_handler(unsigned char MsgOptions) { char refresh = 0; if(menu_current() == app_menu) { tHostMsg* pOutgoingMsg; app_menu = NULL; BPL_AllocMessageBuffer(&pOutgoingMsg); pOutgoingMsg->Type = IdleUpdate; RouteMsg(&pOutgoingMsg); } else { if(MsgOptions < MENU_ITEMS) { refresh = menu_handle_button(&(menu_current()->items[MsgOptions])); } else if(MsgOptions == MENU_BUTTON_EXIT) { if(istop()) { tHostMsg* pOutgoingMsg; /* Only save stuff if it's been changed */ /* save all of the non-volatile items */ // FIXME SAVE STUFF!! //BPL_AllocMessageBuffer(&pOutgoingMsg); //pOutgoingMsg->Type = PariringControlMsg; //pOutgoingMsg->Options = PAIRING_CONTROL_OPTION_SAVE_SPP; //RouteMsg(&pOutgoingMsg); //SaveLinkAlarmEnable(); //SaveRstNmiConfiguration(); //SaveIdleBufferInvert(); //SaveDisplaySeconds(); //SaveTimeFormat(); /* go back to the normal idle screen */ BPL_AllocMessageBuffer(&pOutgoingMsg); pOutgoingMsg->Type = IdleUpdate; RouteMsg(&pOutgoingMsg); } else { menu_pop(); refresh = 1; } } } return refresh; }
void MenuAppStart(void)//unsigned char *paylxoad) { memset(&MenuApp,0,sizeof(MenuApp)); /* first item is length * Then next is huffman encoded text */ unsigned char length = payload[0]; //printf("length = %i\n", (int)length); decode((char*)(payload+1), length, buf); int menuindex = 0; char *ch = buf; while ((ch - buf) < length) { MenuApp.items[menuindex].type = menu_text_action; MenuApp.items[menuindex].flags = MENU_FLAG_UPDATE; MenuApp.items[menuindex].ButtonPressType = BUTTON_STATE_IMMEDIATE; MenuApp.items[menuindex].u.itext.text = ch; MenuApp.items[menuindex].u.itext.action = MenuAppAction; MenuApp.items[menuindex].u.itext.id = menuindex; menuindex++; ch = strchr(ch,' '); if(ch==NULL) break; *ch = 0; //printf("item = %s\n", ch); ch++; } menu_set_app(&MenuApp); tHostMsg* pOutgoingMsg; BPL_AllocMessageBuffer(&pOutgoingMsg); pOutgoingMsg->Type = MenuModeMsg; pOutgoingMsg->Options = MENU_MODE_OPTION_APP; RouteMsg(&pOutgoingMsg); }
/*! Initiate a light sensor cycle. Then send the instantaneous and average * light sense values to the host. * * \param tHostMsg* pMsg is unused * */ static void ReadLightSensorHandler(void) { /* start cycle and wait for it to finish */ LightSenseCycle(); /* send message to the host */ tMessage OutgoingMsg; SetupMessageAndAllocateBuffer(&OutgoingMsg, ReadLightSensorResponse, NO_MSG_OPTIONS); /* instantaneous value */ unsigned int lv = ReadLightSense(); OutgoingMsg.pBuffer[0] = lv & 0xFF; OutgoingMsg.pBuffer[1] = (lv >> 8 ) & 0xFF; /* average value */ lv = ReadLightSenseAverage(); OutgoingMsg.pBuffer[2] = lv & 0xFF; OutgoingMsg.pBuffer[3] = (lv >> 8 ) & 0xFF; OutgoingMsg.Length = 4; RouteMsg(&OutgoingMsg); }
static void ChangeModeHandler(unsigned char Option) { unsigned char Mode = Option & MODE_MASK; tMessage Msg; SetupMessageAndAllocateBuffer(&Msg, ModeChangeIndMsg, (CurrentIdleScreen() << 4) | Mode); Msg.pBuffer[0] = eScUpdateComplete; Msg.Length = 1; RouteMsg(&Msg); PrintStringAndHexByte("- ChgModInd:", Msg.Options); if (Option & MSG_OPT_CHGMOD_IND) return; // ask for current idle page only if (Mode == MUSIC_MODE) SendMessage(&Msg, UpdConnParamMsg, ShortInterval); if (Mode != IDLE_MODE) { PageType = PAGE_TYPE_IDLE; if (ModeTimerId == UNASSIGNED) ModeTimerId = AllocateOneSecondTimer(); SetupOneSecondTimer(ModeTimerId, ModeTimeout[Mode], NO_REPEAT, DISPLAY_QINDEX, ModeTimeoutMsg, Mode); StartOneSecondTimer(ModeTimerId); if (Option & MSG_OPT_UPD_INTERNAL) SendMessage(&Msg, UpdateDisplayMsg, Option); } else { StopOneSecondTimer(ModeTimerId); IdleUpdateHandler(); } CurrentMode = Mode; }
/* Send interrupt notification to the phone or * read data from the accelerometer and send it to the phone */ static void AccelerometerSendDataHandler(void) { tMessage Msg; SetupMessageWithBuffer(&Msg, AccelIndMsg, MSG_OPT_NONE); if (Msg.pBuffer != NULL) { if (Control & WUF_ENABLE) { AccelerometerRead(KIONIX_XOUT_HPF_L, Data, XYZ_DATA_LENGTH); AccelerometerRead(KIONIX_INT_REL, Data, ONE_BYTE); //clear int } else AccelerometerRead(KIONIX_XOUT_L, Data, XYZ_DATA_LENGTH); Msg.pBuffer[0] = CONVERT_TO_8_BIT(0); Msg.pBuffer[1] = CONVERT_TO_8_BIT(2); Msg.pBuffer[2] = CONVERT_TO_8_BIT(4); Msg.Length = 3; RouteMsg(&Msg); PrintH(Msg.pBuffer[0]); PrintC(SPACE); PrintH(Msg.pBuffer[1]); PrintC(SPACE); PrintH(Msg.pBuffer[2]); PrintR(); } }
// Shall be called only when clip is off void CheckBatteryLow(void) { static unsigned char Severity = WARN_LEVEL_NONE; unsigned int Average = Read(BATTERY); /* it was not possible to get a reading below 2.8V * the radio does not initialize when the battery voltage (from a supply) * is below 2.8 V * if the battery is not present then the readings are meaningless * if the battery is charging then ignore the measured voltage * and clear the flags */ if (Average < WarningLevel) { if (Average < RadioOffLevel && Severity == WARN_LEVEL_CRITICAL) Severity = WARN_LEVEL_RADIO_OFF; else if (Average >= RadioOffLevel && Severity == WARN_LEVEL_NONE) Severity = WARN_LEVEL_CRITICAL; else return; tMessage Msg; SetupMessageWithBuffer(&Msg, LowBattWarning[Severity].MsgType1, MSG_OPT_NONE); if (Msg.pBuffer != NULL) { Msg.pBuffer[0] = (unsigned char)Average; Msg.pBuffer[1] = (unsigned char)(Average >> 8); Msg.Length = 2; RouteMsg(&Msg); } /* send the same message to the display task */ SendMessage(&Msg, LowBattWarning[Severity].MsgType2, MSG_OPT_NONE); /* now send a vibration to the wearer */ SetupMessageWithBuffer(&Msg, SetVibrateMode, MSG_OPT_NONE); if (Msg.pBuffer != NULL) { signed char i = sizeof(tSetVibrateModePayload) - 1; for (; i >= 0; i--) Msg.pBuffer[i] = *((unsigned char *)&LowBattWarning[Severity].VibrateData + i); RouteMsg(&Msg); } }
static int IdleUpdateHandler(struct IdleInfo *Info) { /* select between 1 second and 1 minute */ int IdleUpdateTime; StopAllDisplayTimers(); if (GetDisplaySeconds()) { IdleUpdateTime = ONE_SECOND; } else { IdleUpdateTime = ONE_SECOND * 60; } /* setup a timer to determine when to draw the screen again */ SetupOneSecondTimer(Info->IdleModeTimerId, IdleUpdateTime, REPEAT_FOREVER, IdleUpdate, NO_MSG_OPTIONS); StartOneSecondTimer(Info->IdleModeTimerId); /* determine if the bottom of the screen should be drawn by the watch */ if (QueryFirstContact()) { tHostMsg* pOutgoingMsg; /* * immediately update the screen */ if (GetIdleBufferConfiguration() == WATCH_CONTROLS_TOP) { /* only draw watch part */ FillMyBuffer(STARTING_ROW, WATCH_DRAWN_IDLE_BUFFER_ROWS, 0x00); DrawIdleScreen(); // PrepareMyBufferForLcd(STARTING_ROW, WATCH_DRAWN_IDLE_BUFFER_ROWS); SendMyBufferToLcd(WATCH_DRAWN_IDLE_BUFFER_ROWS); } /* now update the remainder of the display */ /*! make a dirty flag for the idle page drawn by the phone * set it whenever watch uses whole screen */ BPL_AllocMessageBuffer(&pOutgoingMsg); pOutgoingMsg->Type = UpdateDisplay; pOutgoingMsg->Options = IDLE_MODE | DONT_ACTIVATE_DRAW_BUFFER; RouteMsg(&pOutgoingMsg); return IDLE_UPDATE_TOP_ONLY; } FillMyBuffer(STARTING_ROW, NUM_LCD_ROWS, 0x00); DrawSimpleIdleScreen(); DrawConnectionScreen(); return IDLE_UPDATE_FULL_SCREEN; }
static void MenuAppActionMsg(int item) { tHostMsg* pOutgoingMsg; BPL_AllocMessageBuffer(&pOutgoingMsg); pOutgoingMsg->pPayload[0] = item; UTL_BuildHstMsg(pOutgoingMsg,GeneralPurposePhoneMsg,MENU_MSG_TYPE, pOutgoingMsg->pPayload,sizeof(char)); RouteMsg(&pOutgoingMsg); }
static void ModeTimeoutHandler() { /* send a message to the host indicating that a timeout occurred */ PrintString2("- ModChgTout", CR); tMessage Msg; SetupMessageAndAllocateBuffer(&Msg, ModeChangeIndMsg, CurrentMode); Msg.pBuffer[0] = eScModeTimeout; Msg.Length = 1; RouteMsg(&Msg); ChangeModeHandler(IDLE_MODE); }
int IdlePageQrCodeExit(void) { StopOneSecondTimer(timerid); DeallocateOneSecondTimer(timerid); timerid = -1; tHostMsg* pOutgoingMsg; /* go back to the normal idle screen */ BPL_AllocMessageBuffer(&pOutgoingMsg); pOutgoingMsg->Type = IdleUpdate; RouteMsg(&pOutgoingMsg); return 0; }
void ChangeMode(unsigned char Option) { // PrintF("- ChgModInd:0x%02x", Option); // PrintF(" PgTp %d Pg: %d", PageType, CurrentPage[PageType]); unsigned char Mode = Option & MODE_MASK; tMessage Msg = {1, ModeChangeIndMsg, (CurrentIdleScreen() << 4) | Mode, NULL}; if (CreateMessage(&Msg)) { Msg.pBuffer[0] = (Option >> 4) ? Option >> 4 : eScUpdateComplete; RouteMsg(&Msg); }
/*! Handle the messages routed to the background task */ static void BackgroundMessageHandler(tHostMsg* pMsg) { tHostMsg* pOutgoingMsg; eMessageType Type = (eMessageType)pMsg->Type; switch(Type) { case GetDeviceType: BPL_AllocMessageBuffer(&pOutgoingMsg); pOutgoingMsg->pPayload[0] = 2; /* DIGITAL_BOARD_TYPE */ UTL_BuildHstMsg(pOutgoingMsg, GetDeviceTypeResponse, NO_MSG_OPTIONS, pOutgoingMsg->pPayload, sizeof(unsigned char)); RouteMsg(&pOutgoingMsg); break; case SetVibrateMode: SetVibrateModeHandler(pMsg); break; case SetRealTimeClock: halRtcSet((tRtcHostMsgPayload*)pMsg->pPayload); BPL_AllocMessageBuffer(&pOutgoingMsg); pOutgoingMsg->Type = IdleUpdate; pOutgoingMsg->Options = NO_MSG_OPTIONS; RouteMsg(&pOutgoingMsg); break; default: PrintStringAndHex("<<Unhandled Message>> in Background Task: Type 0x", Type); break; } }
static void ModeTimeoutHandler() { /* send a message to the host indicating that a timeout occurred */ PrintS("- ModChgTout"); tMessage Msg; SetupMessageWithBuffer(&Msg, ModeChangeIndMsg, CurrentMode); if (Msg.pBuffer != NULL) { Msg.pBuffer[0] = eScModeTimeout; Msg.Length = 1; RouteMsg(&Msg); } ChangeModeHandler(IDLE_MODE); }
/*! Read the voltage of the battery. This provides power good, battery charging, * battery voltage, and battery voltage average. * * \param tHostMsg* pMsg is unused * */ static void ReadBatteryVoltageHandler(void) { tMessage Msg; SetupMessageAndAllocateBuffer(&Msg, VBatRespMsg, MSG_OPT_NONE); Msg.Length = 6; Msg.pBuffer[0] = ClipOn(); Msg.pBuffer[1] = Charging(); Msg.pBuffer[2] = BatteryPercentage(); unsigned int bv = Read(BATTERY); Msg.pBuffer[4] = bv & 0xFF; Msg.pBuffer[5] = (bv >> 8) & 0xFF; RouteMsg(&Msg); }
int menu_handle_button(const struct menu_item *i) { tHostMsg* pOutgoingMsg; switch(i->type) { case menu_msg: BPL_AllocMessageBuffer(&pOutgoingMsg); pOutgoingMsg->Type = i->u.imsg.msg; pOutgoingMsg->Options = i->u.imsg.Options; RouteMsg(&pOutgoingMsg); break; case menu_menu: if((i->flags & MENU_ITEM_MENU_PUSH) == MENU_ITEM_MENU_PUSH) { menu_push(i->u.imenu.menuptr); } else if((i->flags & MENU_ITEM_MENU_NEXT) == MENU_ITEM_MENU_NEXT) { menu_next(i->u.imenu.menuptr); } break; case menu_action: if(i->u.iaction.action) { i->u.iaction.action(); } break; case menu_icon_action: if(i->u.iiconaction.action) { i->u.iiconaction.action(); } break; case menu_text_action: if(i->u.itext.action) { i->u.itext.action(i->u.itext.id); } default: break; } if((i->flags & MENU_FLAG_UPDATE) == MENU_FLAG_UPDATE) { return 1; } return 0; }
/*! A valid button event has occurred. Now send a message * * \param unsigned char ButtonIndex * \param unsigned char ButtonPressType */ static void HandleButtonEvent(unsigned char ButtonIndex, unsigned char ButtonPressType) { tHostMsg* pButtonEventMsg; tButtonConfiguration* pLocalCfg = &(ButtonCfg[QueryDisplayMode()][ButtonIndex]); unsigned char DisplayMode = QueryDisplayMode(); eMessageType Type = (eMessageType)pLocalCfg->CallbackMsgType[ButtonPressType]; unsigned char Options = pLocalCfg->CallbackMsgOptions[ButtonPressType]; if ( (pLocalCfg->MaskTable & (1 << ButtonPressType)) == 0 ) { /* if the message type is non-zero then generate a message */ if ( Type != 0 ) { BPL_AllocMessageBuffer(&pButtonEventMsg); /* if this button press is going to the bluetooth then * format it properly. */ if ( Type == ButtonEventMsg ) { // Send the index of the button that changed state UTL_BuildHstMsg(pButtonEventMsg, Type, Options, &ButtonIndex, sizeof(ButtonIndex)); } else { /* a button can be configured to send any type of simple message * simple == limited payload */ pButtonEventMsg->Type = Type; pButtonEventMsg->Options = Options; } RouteMsg(&pButtonEventMsg); } } }
static void HandleMusicPlayStateChange(unsigned char State) { // music icon fits into one message PrintStringAndDecimal("- HdlMusicPlyChg:", State); tMessage Msg; SetupMessageAndAllocateBuffer(&Msg, WriteBufferMsg, MUSIC_MODE | MSG_OPT_WRTBUF_MULTILINE | ICON_MUSIC_WIDTH << 3); Msg.pBuffer[0] = MUSIC_STATE_START_ROW; Msg.Length = ICON_MUSIC_WIDTH * ICON_MUSIC_HEIGHT + 1; PrintStringAndTwoDecimals("- start:", Msg.pBuffer[0], "L:", Msg.Length); unsigned char i = 1; for (; i < Msg.Length; ++i) Msg.pBuffer[i] = pIconMusicState[1 - State][i - 1]; RouteMsg(&Msg); SendMessage(&Msg, UpdateDisplayMsg, MUSIC_MODE); }
/* send a vibration to the wearer */ void GenerateLinkAlarm(void) { tMessage Msg; SetupMessageAndAllocateBuffer(&Msg,SetVibrateMode,NO_MSG_OPTIONS); tSetVibrateModePayload* pMsgData; pMsgData = (tSetVibrateModePayload*) Msg.pBuffer; pMsgData->Enable = 1; pMsgData->OnDurationLsb = 0x00; pMsgData->OnDurationMsb = 0x01; pMsgData->OffDurationLsb = 0x00; pMsgData->OffDurationMsb = 0x01; pMsgData->NumberOfCycles = 5; RouteMsg(&Msg); }
static void ChangeModeHandler(unsigned char Option) { PrintF("- ChgModInd:0x%02x", Option); PrintF(" PgTp %d Pg: %d", PageType, CurrentPage[PageType]); unsigned char Mode = Option & MODE_MASK; tMessage Msg; SetupMessageWithBuffer(&Msg, ModeChangeIndMsg, (CurrentIdleScreen() << 4) | Mode); if (Msg.pBuffer != NULL) { Msg.pBuffer[0] = eScUpdateComplete; Msg.Length = 1; RouteMsg(&Msg); } if (Option & MSG_OPT_CHGMOD_IND) return; // ask for current idle page only // StopTimer(ModeTimer); if (Mode == MUSIC_MODE) SendMessage(&Msg, UpdConnParamMsg, ShortInterval); else if (CurrentMode == MUSIC_MODE) SendMessage(&Msg, UpdConnParamMsg, LongInterval); CurrentMode = Mode; if (Mode == IDLE_MODE) { #if COUNTDOWN_TIMER if (CurrentPage[PageType] == CountdownPage) SendMessage(&Msg, CountDownMsg, MSG_OPT_NONE); else #endif { // PageType = PAGE_TYPE_IDLE; IdleUpdateHandler(); } } else { SetTimer(ModeTimer, ModeTimeOut[Mode], TOUT_ONCE); if (Option & MSG_OPT_UPD_INTERNAL) SendMessage(&Msg, UpdateDisplayMsg, Option); } }
static void HandleMusicPlayStateChange(unsigned char State) { // music icon fits into one message PrintF("- HdlMusicPlyChg:%d", State); tMessage Msg; SetupMessageWithBuffer(&Msg, WriteBufferMsg, MUSIC_MODE | MSG_OPT_WRTBUF_MULTILINE | ICON_MUSIC_WIDTH << 3); if (Msg.pBuffer != NULL) { Msg.pBuffer[0] = MUSIC_STATE_START_ROW; Msg.Length = ICON_MUSIC_WIDTH * ICON_MUSIC_HEIGHT + 1; PrintF("- start:%d Len: %d", Msg.pBuffer[0], Msg.Length); unsigned char i = 1; for (; i < Msg.Length; ++i) Msg.pBuffer[i] = pIconMusicState[1 - State][i - 1]; RouteMsg(&Msg); } SendMessage(&Msg, UpdateDisplayMsg, MUSIC_MODE); }
/*! Read configuration of a specified button. This is used to read the * configuration of a button that needs to be restored at a later time * by the application. * * \param tHostMsg* pMsg - A message with a tButtonActionPayload payload */ static void ReadButtonConfigHandler(tMessage* pMsg) { /* map incoming message payload to button information */ tButtonActionPayload* pButtonActionPayload = (tButtonActionPayload*)pMsg->pBuffer; tMessage OutgoingMsg; SetupMessageAndAllocateBuffer(&OutgoingMsg, ReadButtonConfigResponse, NO_MSG_OPTIONS); ReadButtonConfiguration(pButtonActionPayload->DisplayMode, pButtonActionPayload->ButtonIndex, pButtonActionPayload->ButtonPressType, OutgoingMsg.pBuffer); OutgoingMsg.Length = 5; RouteMsg(&OutgoingMsg); }
static void ShowCall(tString *pString, unsigned char Type) { static tString CallerId[15] = ""; static tTimerId NotifyTimerId = UNASSIGNED; tMessage Msg; if (Type == SHOW_NOTIF_CALLER_ID) strcpy(CallerId, pString); if (Type == SHOW_NOTIF_CALLER_NAME && *CallerId) { PrintString3("- Caller:", pString, CR); SetupMessageAndAllocateBuffer(&Msg, SetVibrateMode, MSG_OPT_NONE); *(tSetVibrateModePayload *)Msg.pBuffer = RingTone; RouteMsg(&Msg); PageType = PAGE_TYPE_INFO; CurrentPage[PageType] = CallPage; DrawCallScreen(CallerId, pString); // set a 5s timer for switching back to idle screen if (NotifyTimerId == UNASSIGNED) NotifyTimerId = AllocateOneSecondTimer(); SetupOneSecondTimer(NotifyTimerId, 10, NO_REPEAT, DISPLAY_QINDEX, CallerNameMsg, SHOW_NOTIF_END); StartOneSecondTimer(NotifyTimerId); } else if (Type == SHOW_NOTIF_END || Type == SHOW_NOTIF_REJECT_CALL) { PrintString2("- Call Notif End", CR); *CallerId = NULL; StopOneSecondTimer(NotifyTimerId); PageType = PAGE_TYPE_IDLE; SendMessage(&Msg, UpdateDisplayMsg, CurrentMode | MSG_OPT_UPD_INTERNAL | (CurrentMode == IDLE_MODE ? MSG_OPT_NEWUI : 0)); if (Type == SHOW_NOTIF_REJECT_CALL) SendMessage(&Msg, HfpMsg, MSG_OPT_HFP_HANGUP); } }
static void ShowCall(tString *pString, unsigned char Type) { static tString CallerId[15] = ""; tMessage Msg; if (Type == SHOW_NOTIF_CALLER_ID) strcpy(CallerId, pString); if (Type == SHOW_NOTIF_CALLER_NAME && *CallerId) { PrintF("- Caller:%s", pString); SetupMessageWithBuffer(&Msg, SetVibrateMode, MSG_OPT_NONE); if (Msg.pBuffer != NULL) { *(tSetVibrateModePayload *)Msg.pBuffer = RingTone; RouteMsg(&Msg); } PageType = PAGE_TYPE_INFO; CurrentPage[PageType] = CallPage; DrawCallScreen(CallerId, pString); // set a 5s timer for switching back to idle screen StartTimer(ShowCallTimer); } else if (Type == SHOW_NOTIF_END || Type == SHOW_NOTIF_REJECT_CALL) { PrintF("- Call Notif End"); *CallerId = NULL; StopTimer(ShowCallTimer); PageType = PAGE_TYPE_IDLE; SendMessage(&Msg, UpdateDisplayMsg, CurrentMode | MSG_OPT_UPD_INTERNAL | (CurrentMode == IDLE_MODE ? MSG_OPT_NEWUI : 0)); if (Type == SHOW_NOTIF_REJECT_CALL) SendMessage(&Msg, HfpMsg, MSG_OPT_HFP_HANGUP); } }
static void NvalOperationHandler(tMessage* pMsg) { if (pMsg->pBuffer == NULL) // Property { HandleProperty(pMsg->Options); } else { tNvalOperationPayload* pNvPayload = (tNvalOperationPayload*)pMsg->pBuffer; /* create the outgoing message */ tMessage Msg; SetupMessageAndAllocateBuffer(&Msg, PropRespMsg, MSG_OPT_NONE); /* add identifier to outgoing message */ tWordByteUnion Identifier; Identifier.word = pNvPayload->NvalIdentifier; Msg.pBuffer[0] = Identifier.Bytes.byte0; Msg.pBuffer[1] = Identifier.Bytes.byte1; Msg.Length = 2; PrintStringAndTwoHexBytes("- Nval Id:Val 0x", Identifier.word, pNvPayload->DataStartByte); unsigned char Property = PropertyBit(pNvPayload->NvalIdentifier); if (pMsg->Options == NVAL_READ_OPERATION) { if (Property) Msg.pBuffer[2] = GetProperty(Property); Msg.Length += pNvPayload->Size; } else if (Property) // write operation { SetProperty(Property, pNvPayload->DataStartByte ? Property : 0); UpdateClock(); } RouteMsg(&Msg); } }
/* send log to remote */ void SendStateLog(void) { if (!pStateLog) return; unsigned char *pData = pStateLog; unsigned char Len = STATE_INFO_SIZE + SavedLogNum * RESET_LOG_SIZE; tMessage Msg ={0, LogMsg, MSG_OPT_NONE, NULL}; while (Len) { Msg.Length = Len > MAX_LOG_PAYLOAD_LEN ? MAX_LOG_PAYLOAD_LEN : Len; if (CreateMessage(&Msg)) { memcpy(Msg.pBuffer, pData, Msg.Length); pData += Msg.Length; Len -= Msg.Length; RouteMsg(&Msg); } } vPortFree(pStateLog); pStateLog = NULL; }
/*! Read the voltage of the battery. This provides power good, battery charging, * battery voltage, and battery voltage average. * * \param tHostMsg* pMsg is unused * */ static void ReadBatteryVoltageHandler(void) { tMessage OutgoingMsg; SetupMessageAndAllocateBuffer(&OutgoingMsg, ReadBatteryVoltageResponse, NO_MSG_OPTIONS); /* if the battery is not present then these values are meaningless */ OutgoingMsg.pBuffer[0] = QueryPowerGood(); OutgoingMsg.pBuffer[1] = QueryBatteryCharging(); unsigned int bv = ReadBatterySense(); OutgoingMsg.pBuffer[2] = bv & 0xFF; OutgoingMsg.pBuffer[3] = (bv >> 8 ) & 0xFF; bv = ReadBatterySenseAverage(); OutgoingMsg.pBuffer[4] = bv & 0xFF; OutgoingMsg.pBuffer[5] = (bv >> 8 ) & 0xFF; OutgoingMsg.Length = 6; RouteMsg(&OutgoingMsg); }
void SendMessage(tMessage* pMsg, unsigned char Type, unsigned char Options) { SetupMessage(pMsg, Type, Options); RouteMsg(pMsg); }
/*! Handle the messages routed to the display queue */ static void DisplayQueueMessageHandler(tMessage *pMsg) { tMessage Msg; switch (pMsg->Type) { case ShowCallMsg: HandleCallNotification(pMsg->Options, pMsg->pBuffer, pMsg->Length); break; case WriteBufferMsg: WriteBufferHandler(pMsg); break; case SetWidgetListMsg: SetWidgetList(pMsg); break; case UpdateDisplayMsg: if ((!(pMsg->Options & MSG_OPT_UPD_INTERNAL) && (pMsg->Options & MODE_MASK) == NOTIF_MODE) && GetProperty(PROP_AUTO_BACKLIGHT)) SendMessage(AutoBacklightMsg, MSG_OPT_NONE); UpdateDisplayHandler(pMsg); break; case DrawMsg: DrawMsgHandler(pMsg); break; case UpdateClockMsg: UpdateClock(); break; case DrawClockWidgetMsg: DrawClockWidget(pMsg->Options); break; case BluetoothStateChangeMsg: BluetoothStateChangeHandler(pMsg); break; case IdleUpdateMsg: IdleUpdateHandler(); break; case ButtonStateMsg: ButtonStateHandler(); break; case StopTimerMsg: StopTimer((eTimerId)pMsg->Options); break; case MonitorBatteryMsg: MonitorBattery(); break; case MusicIconMsg: MusicIcon(pMsg->Options); break; case MusicStateMsg: HandleMusicStateChange(pMsg->Options); break; case ChangeModeMsg: ChangeMode(pMsg->Options); break; case ControlFullScreenMsg: SetProperty(PROP_PHONE_DRAW_TOP, pMsg->Options || *pMsg->pBuffer ? PROP_PHONE_DRAW_TOP : 0); break; case ModifyTimeMsg: ModifyTimeHandler(pMsg); break; case MenuModeMsg: MenuModeHandler(pMsg->Options); break; case MenuButtonMsg: MenuButtonHandler(pMsg->Options); break; case EnableButtonMsg: EnableButtonMsgHandler(pMsg); break; case DevTypeMsg: Msg.Length = 1; Msg.Type = DevTypeRespMsg; Msg.Options = BOARD_TYPE; //default G2 if (CreateMessage(&Msg)) { Msg.pBuffer[0] = BOARD_TYPE; // backward compatible if (GetMsp430HardwareRevision() < 'F') { Msg.Options = DIGITAL_WATCH_TYPE_G1; Msg.pBuffer[0] = DIGITAL_WATCH_TYPE_G1; // backward compatible } Msg.Options |= DEV_TYPE_EN_ACK; // support ACK RouteMsg(&Msg); } PrintF("- DevTypeResp:%u", Msg.Options); // set ACK and HFP/MAP bits // SendMessage(ConnTypeMsg, pMsg->Options); break; case VerInfoMsg: Msg.Length = BUILD_LENGTH + 4 + 3; Msg.Type = VerInfoRespMsg; Msg.Options = MSG_OPT_NONE; if (CreateMessage(&Msg)) { GetBuildNumber(Msg.pBuffer); *(Msg.pBuffer + BUILD_LENGTH) = VERSION[0] - ZERO; *(Msg.pBuffer + BUILD_LENGTH + 1) = VERSION[2] - ZERO; *(Msg.pBuffer + BUILD_LENGTH + 2) = VERSION[4] - ZERO; *(Msg.pBuffer + BUILD_LENGTH + 3) = GetMsp430HardwareRevision(); *(Msg.pBuffer + BUILD_LENGTH + 4) = BootVersion[0] - ZERO; *(Msg.pBuffer + BUILD_LENGTH + 5) = BootVersion[2] - ZERO; *(Msg.pBuffer + BUILD_LENGTH + 6) = BootVersion[4] - ZERO; RouteMsg(&Msg); } PrintE("-Ver(%u):", Msg.Length); PrintQ(Msg.pBuffer, Msg.Length); break; case LogMsg: SendStateLog(); break; case VibrateMsg: SetVibrateModeHandler(pMsg); break; case SetRtcMsg: if (SetRtc((Rtc_t *)pMsg->pBuffer)) UpdateClock(); break; case CountdownMsg: if (pMsg->Options == CDT_ENTER) { PageType = PAGE_TYPE_INFO; CurrentPage[PageType] = CountdownPage; } CountdownHandler(pMsg->Options); break; case ServiceMenuMsg: ServiceMenuHandler(); break; case FieldTestMsg: HandleFieldTestMode(pMsg->Options); break; case DisableButtonMsg: DisableButtonMsgHandler(pMsg); break; case ReadButtonConfigMsg: ReadButtonConfigHandler(pMsg); break; case SetBacklightMsg: SetBacklight(pMsg->Options); // testing // pMsg->Type = AccelMsg; // pMsg->Options = 1; //enable // HandleAccelerometer(pMsg); break; case AutoBacklightMsg: if (LightSenseCycle() < DARK_LEVEL) SetBacklight(LED_ON); break; case BatteryConfigMsg: SetBatteryLevels(pMsg->pBuffer); break; case ReadBatteryVoltageMsg: ReadBatteryVoltageHandler(); break; case ResetMsg: SoftwareReset(RESET_BUTTON_PRESS, pMsg->Options); break; case NvalOperationMsg: NvalOperationHandler(pMsg); break; case SecInvertMsg: HandleSecInvert(pMsg->Options); break; case LoadTemplateMsg: LoadTemplateHandler(pMsg); break; case LinkAlarmMsg: SendMessage(VibrateMsg, VIBRA_PATTERN_LNKALM); break; case ModeTimeoutMsg: ModeTimeoutHandler(); break; case WatchStatusMsg: PageType = PAGE_TYPE_INFO; CurrentPage[PageType] = StatusPage; DrawWatchStatusScreen(TRUE); break; case TermModeMsg: TermModeHandler(); break; case LowBatteryWarningMsg: break; case LowBatteryBtOffMsg: UpdateClock(); break; #if __IAR_SYSTEMS_ICC__ case EraseTemplateMsg: // EraseTemplateHandler(pMsg); break; case WriteToTemplateMsg: // WriteToTemplateHandler(pMsg); break; #endif case AccelMsg: HandleAccelerometer(pMsg); break; case ReadLightSensorMsg: ReadLightSensorHandler(); break; case WatchDrawnScreenTimeout: IdleUpdateHandler(); break; case RateTestMsg: /* don't care what data is */ Msg.Length = 10; Msg.Type = DiagnosticLoopback; Msg.Options = MSG_OPT_NONE; if (CreateMessage(&Msg)) RouteMsg(&Msg); break; default: PrintF("# Disp Msg:x%02X", pMsg->Type); break; } }
/*! Handle the messages routed to the display queue */ static void DisplayQueueMessageHandler(tMessage* pMsg) { tMessage Msg; unsigned char i = 0; switch (pMsg->Type) { case WriteBufferMsg: WriteBufferHandler(pMsg); break; case SetWidgetListMsg: SetWidgetList(pMsg); break; case UpdateDisplayMsg: UpdateDisplayHandler(pMsg); break; case UpdateClockMsg: UpdateClock(); break; case DrawClockWidgetMsg: DrawClockWidget(pMsg->Options); break; case MonitorBatteryMsg: MonitorBattery(); break; case BluetoothStateChangeMsg: BluetoothStateChangeHandler(pMsg); break; case IdleUpdateMsg: IdleUpdateHandler(); break; case ButtonStateMsg: ButtonStateHandler(); break; case CallerIdMsg: // PrintStringAndDecimal("LcdDisp:CallerId Len:", pMsg->Length); pMsg->pBuffer[pMsg->Length] = NULL; ShowCall((char *)pMsg->pBuffer, pMsg->Options); break; case CallerNameMsg: if (pMsg->Length) { pMsg->pBuffer[pMsg->Length] = NULL; ShowCall((char *)pMsg->pBuffer, SHOW_NOTIF_CALLER_NAME); } else ShowCall("", pMsg->Options); break; case MusicPlayStateMsg: HandleMusicPlayStateChange(pMsg->Options); break; case ChangeModeMsg: ChangeModeHandler(pMsg->Options); break; case ConfigureIdleBufferSize: SetProperty(PROP_PHONE_DRAW_TOP, *pMsg->pBuffer ? PROP_PHONE_DRAW_TOP : 0); break; case ModifyTimeMsg: ModifyTimeHandler(pMsg); break; case MenuModeMsg: MenuModeHandler(pMsg->Options); break; case MenuButtonMsg: MenuButtonHandler(pMsg->Options); break; case EnableButtonMsg: EnableButtonMsgHandler(pMsg); break; case DevTypeMsg: SetupMessageAndAllocateBuffer(&Msg, DevTypeRespMsg, MSG_OPT_NONE); Msg.Options = BOARD_TYPE; //default G2 Msg.pBuffer[0] = BOARD_TYPE; // backward compatible #ifdef WATCH if (GetMsp430HardwareRevision() < 'F') { Msg.Options = DIGITAL_WATCH_TYPE_G1; Msg.pBuffer[0] = DIGITAL_WATCH_TYPE_G1; // backward compatible } #endif Msg.Length = 1; RouteMsg(&Msg); PrintStringAndDecimal("- DevTypeResp:", Msg.pBuffer[0]); break; case VerInfoMsg: SetupMessageAndAllocateBuffer(&Msg, VerInfoRespMsg, MSG_OPT_NONE); /* exclude middle '.' */ strncpy((char *)Msg.pBuffer, BUILD, 3); strncpy((char *)Msg.pBuffer + 3, BUILD + 4, 3); Msg.Length += strlen(BUILD) - 1; *(Msg.pBuffer + Msg.Length++) = (unsigned char)atoi(VERSION); while (VERSION[i++] != '.'); *(Msg.pBuffer + Msg.Length++) = atoi(VERSION + i); *(Msg.pBuffer + Msg.Length++) = NULL; RouteMsg(&Msg); PrintString("-Ver:"); for (i = 6; i < Msg.Length; ++i) PrintHex(Msg.pBuffer[i]); break; case SetVibrateMode: SetVibrateModeHandler(pMsg); break; case SetRtcMsg: halRtcSet((tRtcHostMsgPayload*)pMsg->pBuffer); #ifdef DIGITAL UpdateClock(); #endif break; case GetRtcMsg: SetupMessageAndAllocateBuffer(&Msg, RtcRespMsg, MSG_OPT_NONE); halRtcGet((tRtcHostMsgPayload*)Msg.pBuffer); Msg.Length = sizeof(tRtcHostMsgPayload); RouteMsg(&Msg); break; case ServiceMenuMsg: ServiceMenuHandler(); break; case DisableButtonMsg: DisableButtonMsgHandler(pMsg); break; case ReadButtonConfigMsg: ReadButtonConfigHandler(pMsg); break; case LedChange: LedChangeHandler(pMsg); break; case BatteryConfigMsg: SetBatteryLevels(pMsg->pBuffer); break; case ReadBatteryVoltageMsg: ReadBatteryVoltageHandler(); break; case ResetMsg: SoftwareResetHandler(pMsg); break; case NvalOperationMsg: NvalOperationHandler(pMsg); break; case SecInvertMsg: HandleSecInvert(pMsg->Options); break; case LoadTemplateMsg: LoadTemplateHandler(pMsg); break; case LinkAlarmMsg: if (!GetProperty(PROP_DISABLE_LINK_ALARM)) { SetupMessageAndAllocateBuffer(&Msg, SetVibrateMode, MSG_OPT_NONE); tSetVibrateModePayload* pMsgData; pMsgData = (tSetVibrateModePayload *)Msg.pBuffer; pMsgData->Enable = 1; pMsgData->OnDurationLsb = 0xC8; pMsgData->OnDurationMsb = 0x00; pMsgData->OffDurationLsb = 0xF4; pMsgData->OffDurationMsb = 0x01; pMsgData->NumberOfCycles = 1; //3 RouteMsg(&Msg); } break; case ModeTimeoutMsg: ModeTimeoutHandler(); break; case WatchStatusMsg: PageType = PAGE_TYPE_INFO; CurrentPage[PageType] = StatusPage; DrawWatchStatusScreen(); break; // case ListPairedDevicesMsg: // ListPairedDevicesHandler(); // break; case WatchDrawnScreenTimeout: IdleUpdateHandler(); break; case TermModeMsg: TermModeHandler(); break; case LowBatteryWarningMsg: break; case LowBatteryBtOffMsg: UpdateClock(); break; #if __IAR_SYSTEMS_ICC__ case EraseTemplateMsg: EraseTemplateHandler(pMsg); break; case WriteToTemplateMsg: WriteToTemplateHandler(pMsg); break; #endif case EnableAccelerometerMsg: case DisableAccelerometerMsg: case AccelerometerSendDataMsg: case AccelerometerAccessMsg: case AccelerometerSetupMsg: HandleAccelerometer(pMsg); break; case ReadLightSensorMsg: ReadLightSensorHandler(); break; case RateTestMsg: SetupMessageAndAllocateBuffer(&Msg, DiagnosticLoopback, MSG_OPT_NONE); /* don't care what data is */ Msg.Length = 10; RouteMsg(&Msg); break; case RamTestMsg: RamTestHandler(pMsg); break; default: PrintStringAndHexByte("# Disp Msg: 0x", pMsg->Type); break; } }