Hexiwear library for communicating with the on-board KW40Z BLE device. KW40Z handles also the touch buttons.
Dependents: Hexi_Buttons_Example Hexi_Click_Relay-v2_Example Hexi_Click_Relay-v3_Example Hexi_Catch-the-dot_Game ... more
Hexi_KW40Z.cpp
00001 /** BLE KW40Z Driver for Hexiwear 00002 * This file contains BLE and Touch Buttons driver functionality for Hexiwear 00003 * 00004 * Redistribution and use in source and binary forms, with or without modification, 00005 * are permitted provided that the following conditions are met: 00006 * 00007 * Redistributions of source code must retain the above copyright notice, this list 00008 * of conditions and the following disclaimer. 00009 * 00010 * Redistributions in binary form must reproduce the above copyright notice, this 00011 * list of conditions and the following disclaimer in the documentation and/or 00012 * other materials provided with the distribution. 00013 * 00014 * Neither the name of NXP, nor the names of its 00015 * contributors may be used to endorse or promote products derived from this 00016 * software without specific prior written permission. 00017 * 00018 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 00019 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 00020 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00021 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 00022 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 00023 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00024 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 00025 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00026 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00027 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00028 * 00029 * visit: http://www.mikroe.com and http://www.nxp.com 00030 * 00031 * get support at: http://www.mikroe.com/forum and https://community.nxp.com 00032 * 00033 * Project HEXIWEAR, 2015 00034 */ 00035 00036 #include "Hexi_KW40Z.h" 00037 00038 KW40Z::KW40Z(PinName txPin,PinName rxPin) : 00039 #if defined (LIB_DEBUG) || defined (RAW_DEBUG) 00040 pc(USBTX, USBRX), 00041 #endif 00042 device(txPin, rxPin), rxThread(osPriorityNormal,1024), mainThread(osPriorityNormal,1024) 00043 { 00044 #if defined (LIB_DEBUG) 00045 pc.baud(115200); 00046 pc.printf("Initializing\r\n"); 00047 #endif 00048 00049 device.baud(230400); 00050 device.format(8, Serial::None, 2); 00051 00052 rxBuff = (uint8_t*)&hostInterface_rxPacket; 00053 00054 /* initialize callbacks */ 00055 buttonUpCb = NULL; 00056 buttonDownCb = NULL; 00057 buttonLeftCb = NULL; 00058 buttonRightCb = NULL; 00059 buttonSlideCb = NULL; 00060 alertCb = NULL; 00061 passkeyCb = NULL; 00062 notificationsCb = NULL; 00063 00064 kw40_version.ver_patchNumber = 0; 00065 kw40_version.ver_minorNumber = 0; 00066 kw40_version.ver_majorNumber = 0; 00067 00068 activeTsiGroup = 0; 00069 advertisementMode = 0; 00070 linkState = 0; 00071 bondPassKey = 0; 00072 00073 /* intialization finalized, signal to start the threads */ 00074 rxThread.start(this, &KW40Z::rxTask); 00075 mainThread.start(this,&KW40Z::mainTask); 00076 } 00077 00078 KW40Z::~KW40Z(void) 00079 { 00080 } 00081 00082 void KW40Z::attach_buttonUp(button_t btnFct) { buttonUpCb = btnFct; } 00083 void KW40Z::attach_buttonDown(button_t btnFct) { buttonDownCb = btnFct; } 00084 void KW40Z::attach_buttonLeft(button_t btnFct) { buttonLeftCb = btnFct; } 00085 void KW40Z::attach_buttonRight(button_t btnFct) { buttonRightCb = btnFct; } 00086 void KW40Z::attach_buttonSlide(button_t btnFct) { buttonSlideCb = btnFct; } 00087 void KW40Z::attach_alert(alert_t alertFct) { alertCb = alertFct; } 00088 void KW40Z::attach_passkey(passkey_t passkeyFct){ passkeyCb = passkeyFct; } 00089 void KW40Z::attach_notifications(notifications_t notFct) { notificationsCb = notFct; } 00090 00091 void KW40Z::mainTask(void) 00092 { 00093 #if defined (LIB_DEBUG) 00094 pc.printf("MainTask Stared\r\n"); 00095 #endif 00096 00097 SendGetActiveTsiGroup(); 00098 SendGetAdvertisementMode(); 00099 SendGetLinkState(); 00100 SendGetVersion(); 00101 00102 while(1) 00103 { 00104 osEvent evt = queue.get(); 00105 if (evt.status == osEventMessage) 00106 { 00107 hostInterface_packet_t *packet = (hostInterface_packet_t*)evt.value.p; 00108 ProcessPacket(packet); 00109 mpool.free(packet); 00110 } 00111 } 00112 } 00113 00114 void KW40Z::rxTask(void) 00115 { 00116 #if defined (LIB_DEBUG) 00117 pc.printf("RxTask Stared\r\n"); 00118 #endif 00119 00120 while(1) 00121 { 00122 if(device.readable()) 00123 { 00124 *rxBuff++ = device.getc(); 00125 ProcessBuffer(); 00126 00127 /* check for buffer overflow */ 00128 if(rxBuff >= ((uint8_t*)&hostInterface_rxPacket + sizeof(hostInterface_rxPacket))) 00129 { 00130 rxBuff = (uint8_t*)&hostInterface_rxPacket; 00131 } 00132 } 00133 } 00134 } 00135 00136 void KW40Z::SendPacket(hostInterface_packet_t * txPacket, bool confirmRequested) 00137 { 00138 /* copy txPacket to the mem pool */ 00139 hostInterface_packet_t *packet = mpool.alloc(); 00140 memcpy(packet, txPacket, sizeof(hostInterface_packet_t)); 00141 00142 /* Set the TX bit in the Start 2 byte */ 00143 packet->start2 |= gHostInterface_txPacketMask; 00144 00145 if (true == confirmRequested) 00146 { 00147 /* Set the confirm requested bit in the Start 2 byte */ 00148 packet->start2 |= gHostInterface_rxConfirmMask; 00149 } 00150 00151 #if defined (LIB_DEBUG) 00152 pc.printf("SendPacket: "); 00153 DebugPrintPacket(packet); 00154 #endif 00155 00156 /* send message to main task */ 00157 queue.put(packet); 00158 } 00159 00160 void KW40Z::SendInternal(hostInterface_packet_t * txPacket) 00161 { 00162 uint8_t retries = 0; 00163 bool confirmRequested = false; 00164 confirmReceived = false; 00165 00166 #if defined (LIB_DEBUG) 00167 pc.printf("SendInternal: "); 00168 DebugPrintPacket(txPacket); 00169 #endif 00170 00171 if(gHostInterface_rxConfirmMask == (txPacket->start2 & gHostInterface_rxConfirmMask)) 00172 { 00173 confirmRequested = true; 00174 #if defined (LIB_DEBUG) 00175 pc.printf("Found confirmRequested\r\n"); 00176 #endif 00177 } 00178 00179 do 00180 { 00181 char * txBuff = (char *)txPacket; 00182 uint8_t length = txPacket->length + gHostInterface_headerSize + 1; 00183 00184 for(uint8_t i = 0; i < length; i++) 00185 { 00186 device.putc(*txBuff); 00187 txBuff++; 00188 } 00189 00190 #if defined (LIB_DEBUG) 00191 pc.printf("TX: "); 00192 DebugPrintPacket(txPacket); 00193 #endif 00194 00195 retries++; 00196 00197 #if defined (gHostInterface_RxConfirmationEnable) 00198 if((confirmRequested == true) && (confirmReceived == false)) 00199 { 00200 Thread::wait(gHostInterface_retransmitTimeout); 00201 } 00202 #endif 00203 } 00204 while((confirmRequested == true) && 00205 (confirmReceived == false) && 00206 (retries < gHostInterface_retransmitCount)); 00207 } 00208 00209 void KW40Z::ProcessBuffer() 00210 { 00211 #if defined (RAW_DEBUG) 00212 pc.printf("%02X ", rxBuff-1); 00213 #endif 00214 /* check if header has been received */ 00215 if(rxBuff > ((uint8_t*)&hostInterface_rxPacket + gHostInterface_headerSize)) 00216 { 00217 /* check packet header */ 00218 if((gHostInterface_startByte1 != hostInterface_rxPacket.start1)|| 00219 (gHostInterface_startByte2 != (hostInterface_rxPacket.start2 & 0xFE))|| 00220 (hostInterface_rxPacket.length > gHostInterface_dataSize)) 00221 { 00222 #if defined (LIB_DEBUG) 00223 pc.printf("Check header failed: "); 00224 DebugPrintPacket(&hostInterface_rxPacket); 00225 #endif 00226 00227 SearchStartByte(); 00228 } 00229 else 00230 { 00231 /* check data length */ 00232 if(rxBuff > ((uint8_t*)&hostInterface_rxPacket + gHostInterface_headerSize + hostInterface_rxPacket.length)) 00233 { 00234 /* check trailer byte */ 00235 if(gHostInterface_trailerByte != hostInterface_rxPacket.data[hostInterface_rxPacket.length]) 00236 { 00237 #if defined (LIB_DEBUG) 00238 pc.printf("Trailer byte failed: "); 00239 DebugPrintPacket(&hostInterface_rxPacket); 00240 #endif 00241 00242 SearchStartByte(); 00243 } 00244 else 00245 { 00246 00247 #if defined (gHostInterface_RxConfirmationEnable) 00248 if(hostInterface_rxPacket.type == packetType_OK) 00249 { 00250 confirmReceived = true; 00251 } 00252 #endif 00253 00254 /* send message to main task */ 00255 hostInterface_packet_t *rxPacket = mpool.alloc(); 00256 memcpy(rxPacket, &hostInterface_rxPacket, sizeof(hostInterface_packet_t)); 00257 queue.put(rxPacket); 00258 00259 #if defined (LIB_DEBUG) 00260 pc.printf("RX: "); 00261 DebugPrintPacket(&hostInterface_rxPacket); 00262 #endif 00263 #if defined (RAW_DEBUG) 00264 pc.printf("\r\n"); 00265 #endif 00266 /* reset buffer position */ 00267 rxBuff = (uint8_t*)&hostInterface_rxPacket; 00268 } 00269 } 00270 } 00271 } 00272 } 00273 00274 void KW40Z::SearchStartByte() 00275 { 00276 bool found = false; 00277 uint8_t * rdIdx = (uint8_t*)&hostInterface_rxPacket; 00278 rdIdx++; 00279 00280 while(rdIdx < rxBuff) 00281 { 00282 if(*rdIdx == gHostInterface_startByte1) 00283 { 00284 uint32_t len = rxBuff - rdIdx + 1; 00285 00286 memcpy(&hostInterface_rxPacket,rdIdx,len); 00287 rxBuff = (uint8_t*)&hostInterface_rxPacket + len; 00288 found = true; 00289 00290 #if defined (LIB_DEBUG) 00291 pc.printf("moving %d", len); 00292 #endif 00293 break; 00294 } 00295 rdIdx++; 00296 } 00297 00298 if(!found) 00299 { 00300 /* reset buffer position */ 00301 rxBuff = (uint8_t*)&hostInterface_rxPacket; 00302 memset(rxBuff, 0, sizeof(hostInterface_packet_t)); 00303 } 00304 00305 #if defined (LIB_DEBUG) 00306 pc.printf("Search done: \r\n"); 00307 pc.printf("rxBuff: "); 00308 DebugPrintPacket((hostInterface_packet_t*)rxBuff); 00309 pc.printf("rxPack: "); 00310 DebugPrintPacket(&hostInterface_rxPacket); 00311 #endif 00312 } 00313 00314 void KW40Z::ProcessPacket(hostInterface_packet_t * packet) 00315 { 00316 #if defined (LIB_DEBUG) 00317 pc.printf("ProcessPacket: "); 00318 DebugPrintPacket(packet); 00319 #endif 00320 00321 /* check if this is a TX packet */ 00322 if(gHostInterface_txPacketMask == (packet->start2 & gHostInterface_txPacketMask)) 00323 { 00324 /* revert back the TX bit in Start2 byte */ 00325 packet->start2 &= ~gHostInterface_txPacketMask; 00326 00327 /* This is not a received packet, so call SendInternal */ 00328 SendInternal(packet); 00329 } 00330 else 00331 { 00332 #ifdef gHostInterface_TxConfirmationEnable 00333 /* acknowledge the packet reception if requested by sender */ 00334 if(gHostInterface_rxConfirmMask == (packet->start2 & gHostInterface_rxConfirmMask)) 00335 { 00336 SendPacketOK(); 00337 } 00338 #endif 00339 00340 switch(packet->type) 00341 { 00342 /* button presses */ 00343 case packetType_pressUp: 00344 if(buttonUpCb != NULL) buttonUpCb(); 00345 break; 00346 00347 case packetType_pressDown: 00348 if(buttonDownCb != NULL) buttonDownCb(); 00349 break; 00350 00351 case packetType_pressLeft: 00352 if(buttonLeftCb != NULL) buttonLeftCb(); 00353 break; 00354 00355 case packetType_pressRight: 00356 if(buttonRightCb != NULL) buttonRightCb(); 00357 break; 00358 00359 case packetType_slide: 00360 if(buttonSlideCb != NULL) buttonSlideCb(); 00361 break; 00362 00363 /* Alert Service */ 00364 case packetType_alertIn: 00365 if(alertCb != NULL) alertCb(&packet->data[0], packet->length); 00366 break; 00367 00368 /* Passkey for pairing received */ 00369 case packetType_passDisplay: 00370 if(passkeyCb != NULL) 00371 { 00372 memcpy((uint8_t *)&bondPassKey,&packet->data[0], 3); 00373 passkeyCb(); 00374 } 00375 break; 00376 00377 /* OTAP messages */ 00378 case packetType_otapCompleted: 00379 case packetType_otapFailed: 00380 break; 00381 00382 /* TSI Status */ 00383 case packetType_buttonsGroupSendActive: 00384 activeTsiGroup = packet->data[0]; 00385 break; 00386 00387 /* Advertisement Mode Info */ 00388 case packetType_advModeSend: 00389 advertisementMode = packet->data[0]; 00390 break; 00391 00392 /* Link State */ 00393 case packetType_linkStateSend: 00394 linkState = packet->data[0]; 00395 break; 00396 00397 /* ANCS Service Notification Received */ 00398 case packetType_notification: 00399 if(notificationsCb != NULL) notificationsCb(packet->data[0], packet->data[1]); 00400 break; 00401 00402 /* Build version */ 00403 case packetType_buildVersion: 00404 kw40_version.ver_patchNumber = packet->data[2]; 00405 kw40_version.ver_minorNumber = packet->data[1]; 00406 kw40_version.ver_majorNumber = packet->data[0]; 00407 break; 00408 00409 case packetType_OK: 00410 /* do nothing, passthrough, the flag is set in the RxTask */ 00411 break; 00412 00413 default: 00414 break; 00415 } 00416 } 00417 } 00418 00419 void KW40Z::SendBatteryLevel(uint8_t percentage) 00420 { 00421 hostInterface_packet_t txPacket = {0}; 00422 00423 txPacket.start1 = gHostInterface_startByte1; 00424 txPacket.start2 = gHostInterface_startByte2; 00425 txPacket.type = packetType_batteryLevel; 00426 txPacket.length = 1; 00427 txPacket.data[0] = percentage; 00428 txPacket.data[1] = gHostInterface_trailerByte; 00429 00430 SendPacket(&txPacket, true); 00431 } 00432 00433 void KW40Z::SendAccel(int16_t x, int16_t y, int16_t z) 00434 { 00435 hostInterface_packet_t txPacket = {0}; 00436 00437 txPacket.start1 = gHostInterface_startByte1; 00438 txPacket.start2 = gHostInterface_startByte2; 00439 txPacket.type = packetType_accel; 00440 txPacket.length = 6; 00441 00442 txPacket.data[0] = (uint8_t) ((x >> 8)&0xFF); 00443 txPacket.data[1] = (uint8_t) x; 00444 txPacket.data[2] = (uint8_t) ((y >> 8)&0xFF); 00445 txPacket.data[3] = (uint8_t) y; 00446 txPacket.data[4] = (uint8_t) ((z >> 8)&0xFF); 00447 txPacket.data[5] = (uint8_t) z; 00448 txPacket.data[6] = gHostInterface_trailerByte; 00449 00450 SendPacket(&txPacket, true); 00451 } 00452 00453 void KW40Z::SendGyro(int16_t x, int16_t y, int16_t z) 00454 { 00455 hostInterface_packet_t txPacket = {0}; 00456 00457 txPacket.start1 = gHostInterface_startByte1; 00458 txPacket.start2 = gHostInterface_startByte2; 00459 txPacket.type = packetType_gyro; 00460 txPacket.length = 6; 00461 txPacket.data[0] = (uint8_t) ((x >> 8)&0xFF); 00462 txPacket.data[1] = (uint8_t) x; 00463 txPacket.data[2] = (uint8_t) ((y >> 8)&0xFF); 00464 txPacket.data[3] = (uint8_t) y; 00465 txPacket.data[4] = (uint8_t) ((z >> 8)&0xFF); 00466 txPacket.data[5] = (uint8_t) z; 00467 txPacket.data[6] = gHostInterface_trailerByte; 00468 00469 SendPacket(&txPacket, true); 00470 } 00471 00472 void KW40Z::SendMag(int16_t x, int16_t y, int16_t z) 00473 { 00474 hostInterface_packet_t txPacket = {0}; 00475 00476 txPacket.start1 = gHostInterface_startByte1; 00477 txPacket.start2 = gHostInterface_startByte2; 00478 txPacket.type = packetType_magnet; 00479 txPacket.length = 6; 00480 txPacket.data[0] = (uint8_t) ((x >> 8)&0xFF); 00481 txPacket.data[1] = (uint8_t) x; 00482 txPacket.data[2] = (uint8_t) ((y >> 8)&0xFF); 00483 txPacket.data[3] = (uint8_t) y; 00484 txPacket.data[4] = (uint8_t) ((z >> 8)&0xFF); 00485 txPacket.data[5] = (uint8_t) z; 00486 txPacket.data[6] = gHostInterface_trailerByte; 00487 00488 SendPacket(&txPacket, true); 00489 } 00490 00491 void KW40Z::SendAmbientLight(uint8_t percentage) 00492 { 00493 hostInterface_packet_t txPacket = {0}; 00494 00495 txPacket.start1 = gHostInterface_startByte1; 00496 txPacket.start2 = gHostInterface_startByte2; 00497 txPacket.type = packetType_ambiLight; 00498 txPacket.length = 1; 00499 txPacket.data[0] = percentage; 00500 txPacket.data[1] = gHostInterface_trailerByte; 00501 00502 SendPacket(&txPacket, true); 00503 } 00504 00505 void KW40Z::SendTemperature(uint16_t celsius) 00506 { 00507 hostInterface_packet_t txPacket = {0}; 00508 00509 txPacket.start1 = gHostInterface_startByte1; 00510 txPacket.start2 = gHostInterface_startByte2; 00511 txPacket.type = packetType_temperature; 00512 txPacket.length = 2; 00513 memcpy(&txPacket.data[0],(uint8_t*)&celsius,txPacket.length); 00514 txPacket.data[2] = gHostInterface_trailerByte; 00515 00516 SendPacket(&txPacket, true); 00517 } 00518 00519 void KW40Z::SendHumidity(uint16_t percentage) 00520 { 00521 hostInterface_packet_t txPacket = {0}; 00522 00523 txPacket.start1 = gHostInterface_startByte1; 00524 txPacket.start2 = gHostInterface_startByte2; 00525 txPacket.type = packetType_humidity; 00526 txPacket.length = 2; 00527 memcpy(&txPacket.data[0],(uint8_t*)&percentage,txPacket.length); 00528 txPacket.data[2] = gHostInterface_trailerByte; 00529 00530 SendPacket(&txPacket, true); 00531 } 00532 00533 void KW40Z::SendPressure(uint16_t pascal) 00534 { 00535 hostInterface_packet_t txPacket = {0}; 00536 00537 txPacket.start1 = gHostInterface_startByte1; 00538 txPacket.start2 = gHostInterface_startByte2; 00539 txPacket.type = packetType_pressure; 00540 txPacket.length = 2; 00541 memcpy(&txPacket.data[0],(uint8_t*)&pascal,txPacket.length); 00542 txPacket.data[2] = gHostInterface_trailerByte; 00543 00544 SendPacket(&txPacket, true); 00545 } 00546 00547 void KW40Z::SendHeartRate(uint8_t rate) 00548 { 00549 hostInterface_packet_t txPacket = {0}; 00550 00551 txPacket.start1 = gHostInterface_startByte1; 00552 txPacket.start2 = gHostInterface_startByte2; 00553 txPacket.type = packetType_steps; 00554 txPacket.length = 1; 00555 txPacket.data[0] = rate; 00556 txPacket.data[1] = gHostInterface_trailerByte; 00557 00558 SendPacket(&txPacket, true); 00559 } 00560 00561 void KW40Z::SendSteps(uint16_t steps) 00562 { 00563 hostInterface_packet_t txPacket = {0}; 00564 00565 txPacket.start1 = gHostInterface_startByte1; 00566 txPacket.start2 = gHostInterface_startByte2; 00567 txPacket.type = packetType_steps; 00568 txPacket.length = 2; 00569 memcpy(&txPacket.data[0],(uint8_t*)&steps,txPacket.length); 00570 txPacket.data[2] = gHostInterface_trailerByte; 00571 00572 SendPacket(&txPacket, true); 00573 } 00574 00575 void KW40Z::SendCalories(uint16_t calories) 00576 { 00577 hostInterface_packet_t txPacket = {0}; 00578 00579 txPacket.start1 = gHostInterface_startByte1; 00580 txPacket.start2 = gHostInterface_startByte2; 00581 txPacket.type = packetType_calories; 00582 txPacket.length = 2; 00583 memcpy(&txPacket.data[0],(uint8_t*)&calories,txPacket.length); 00584 txPacket.data[2] = gHostInterface_trailerByte; 00585 00586 SendPacket(&txPacket, true); 00587 } 00588 00589 void KW40Z::SendAlert(uint8_t *pData, uint8_t length) 00590 { 00591 hostInterface_packet_t txPacket = {0}; 00592 00593 txPacket.start1 = gHostInterface_startByte1; 00594 txPacket.start2 = gHostInterface_startByte2; 00595 txPacket.type = packetType_alertOut; 00596 txPacket.length = length; 00597 memcpy(&txPacket.data[0],pData,length); 00598 txPacket.data[length] = gHostInterface_trailerByte; 00599 00600 SendPacket(&txPacket, true); 00601 } 00602 00603 void KW40Z::ToggleTsiGroup(void) 00604 { 00605 hostInterface_packet_t txPacket = {0}; 00606 00607 txPacket.start1 = gHostInterface_startByte1; 00608 txPacket.start2 = gHostInterface_startByte2; 00609 txPacket.type = packetType_buttonsGroupToggleActive; 00610 txPacket.length = 0; 00611 txPacket.data[0] = gHostInterface_trailerByte; 00612 00613 SendPacket(&txPacket, true); 00614 } 00615 00616 void KW40Z::ToggleAdvertisementMode(void) 00617 { 00618 hostInterface_packet_t txPacket = {0}; 00619 00620 txPacket.start1 = gHostInterface_startByte1; 00621 txPacket.start2 = gHostInterface_startByte2; 00622 txPacket.type = packetType_advModeToggle; 00623 txPacket.length = 0; 00624 txPacket.data[0] = gHostInterface_trailerByte; 00625 00626 SendPacket(&txPacket, true); 00627 } 00628 00629 void KW40Z::SendSetApplicationMode(gui_current_app_t mode) 00630 { 00631 hostInterface_packet_t txPacket = {0}; 00632 00633 txPacket.start1 = gHostInterface_startByte1; 00634 txPacket.start2 = gHostInterface_startByte2; 00635 txPacket.type = packetType_appMode; 00636 txPacket.length = 1; 00637 txPacket.data[0] = (uint8_t)mode; 00638 txPacket.data[1] = gHostInterface_trailerByte; 00639 00640 SendPacket(&txPacket, true); 00641 } 00642 00643 void KW40Z::SendGetActiveTsiGroup(void) 00644 { 00645 hostInterface_packet_t txPacket = {0}; 00646 00647 txPacket.start1 = gHostInterface_startByte1; 00648 txPacket.start2 = gHostInterface_startByte2; 00649 txPacket.type = packetType_buttonsGroupGetActive; 00650 txPacket.length = 0; 00651 txPacket.data[0] = gHostInterface_trailerByte; 00652 00653 SendPacket(&txPacket, false); 00654 } 00655 00656 void KW40Z::SendGetAdvertisementMode(void) 00657 { 00658 hostInterface_packet_t txPacket = {0}; 00659 00660 txPacket.start1 = gHostInterface_startByte1; 00661 txPacket.start2 = gHostInterface_startByte2; 00662 txPacket.type = packetType_advModeGet; 00663 txPacket.length = 0; 00664 txPacket.data[0] = gHostInterface_trailerByte; 00665 00666 SendPacket(&txPacket, false); 00667 } 00668 00669 void KW40Z::SendGetLinkState(void) 00670 { 00671 hostInterface_packet_t txPacket = {0}; 00672 00673 txPacket.start1 = gHostInterface_startByte1; 00674 txPacket.start2 = gHostInterface_startByte2; 00675 txPacket.type = packetType_linkStateGet; 00676 txPacket.length = 0; 00677 txPacket.data[0] = gHostInterface_trailerByte; 00678 00679 SendPacket(&txPacket, false); 00680 } 00681 00682 void KW40Z::SendGetVersion(void) 00683 { 00684 hostInterface_packet_t txPacket = {0}; 00685 00686 txPacket.start1 = gHostInterface_startByte1; 00687 txPacket.start2 = gHostInterface_startByte2; 00688 txPacket.type = packetType_buildVersion; 00689 txPacket.length = 3; 00690 txPacket.data[0] = HEXIWEAR_VERSION_MAJOR; 00691 txPacket.data[1] = HEXIWEAR_VERSION_MINOR; 00692 txPacket.data[2] = HEXIWEAR_VERSION_PATCH; 00693 txPacket.data[3] = gHostInterface_trailerByte; 00694 00695 SendPacket(&txPacket, true); 00696 } 00697 00698 void KW40Z::SendPacketOK(void) 00699 { 00700 hostInterface_packet_t txPacket = {0}; 00701 00702 txPacket.start1 = gHostInterface_startByte1; 00703 txPacket.start2 = gHostInterface_startByte2; 00704 txPacket.type = packetType_OK; 00705 txPacket.length = 0; 00706 txPacket.data[0] = gHostInterface_trailerByte; 00707 00708 SendPacket(&txPacket, false); 00709 } 00710 00711 uint8_t KW40Z::GetAdvertisementMode(void) 00712 { 00713 return advertisementMode; 00714 } 00715 00716 uint32_t KW40Z::GetPassKey(void) 00717 { 00718 return bondPassKey; 00719 } 00720 00721 uint8_t KW40Z::GetLinkState(void) 00722 { 00723 return linkState; 00724 } 00725 00726 hexiwear_version_t KW40Z::GetVersion(void) 00727 { 00728 return kw40_version; 00729 } 00730 00731 uint8_t KW40Z::GetTsiGroup(void) 00732 { 00733 return activeTsiGroup; 00734 } 00735 00736 #if defined (LIB_DEBUG) 00737 void KW40Z::DebugPrintPacket(hostInterface_packet_t * packet) 00738 { 00739 char * idx = (char *)packet; 00740 uint8_t length = packet->length + gHostInterface_headerSize + 1; 00741 00742 if(length > sizeof(hostInterface_packet_t)) 00743 { 00744 length = sizeof(hostInterface_packet_t); 00745 } 00746 00747 for(uint8_t i = 0; i < length; i++) 00748 { 00749 pc.printf("%02X ",*idx); 00750 idx++; 00751 } 00752 pc.printf("\r\n"); 00753 } 00754 #endif
Generated on Wed Jul 13 2022 11:50:03 by
1.7.2