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

Committer:
cotigac
Date:
Mon Sep 19 02:46:28 2016 +0000
Revision:
0:c2d52562f36b
Child:
1:f6f9b24aea57
Initial version of KW40Z library for Hexiwear

Who changed what in which revision?

UserRevisionLine numberNew contents of line
cotigac 0:c2d52562f36b 1 /** BLE KW40Z Driver for Hexiwear
cotigac 0:c2d52562f36b 2 * This file contains BLE and Touch Buttons driver functionality for Hexiwear
cotigac 0:c2d52562f36b 3 *
cotigac 0:c2d52562f36b 4 * Redistribution and use in source and binary forms, with or without modification,
cotigac 0:c2d52562f36b 5 * are permitted provided that the following conditions are met:
cotigac 0:c2d52562f36b 6 *
cotigac 0:c2d52562f36b 7 * Redistributions of source code must retain the above copyright notice, this list
cotigac 0:c2d52562f36b 8 * of conditions and the following disclaimer.
cotigac 0:c2d52562f36b 9 *
cotigac 0:c2d52562f36b 10 * Redistributions in binary form must reproduce the above copyright notice, this
cotigac 0:c2d52562f36b 11 * list of conditions and the following disclaimer in the documentation and/or
cotigac 0:c2d52562f36b 12 * other materials provided with the distribution.
cotigac 0:c2d52562f36b 13 *
cotigac 0:c2d52562f36b 14 * Neither the name of NXP, nor the names of its
cotigac 0:c2d52562f36b 15 * contributors may be used to endorse or promote products derived from this
cotigac 0:c2d52562f36b 16 * software without specific prior written permission.
cotigac 0:c2d52562f36b 17 *
cotigac 0:c2d52562f36b 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
cotigac 0:c2d52562f36b 19 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
cotigac 0:c2d52562f36b 20 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
cotigac 0:c2d52562f36b 21 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
cotigac 0:c2d52562f36b 22 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
cotigac 0:c2d52562f36b 23 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
cotigac 0:c2d52562f36b 24 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
cotigac 0:c2d52562f36b 25 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
cotigac 0:c2d52562f36b 26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
cotigac 0:c2d52562f36b 27 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
cotigac 0:c2d52562f36b 28 *
cotigac 0:c2d52562f36b 29 * visit: http://www.mikroe.com and http://www.nxp.com
cotigac 0:c2d52562f36b 30 *
cotigac 0:c2d52562f36b 31 * get support at: http://www.mikroe.com/forum and https://community.nxp.com
cotigac 0:c2d52562f36b 32 *
cotigac 0:c2d52562f36b 33 * Project HEXIWEAR, 2015
cotigac 0:c2d52562f36b 34 */
cotigac 0:c2d52562f36b 35
cotigac 0:c2d52562f36b 36 #include "Hexi_KW40Z.h"
cotigac 0:c2d52562f36b 37
cotigac 0:c2d52562f36b 38 #if defined (LIB_DEBUG)
cotigac 0:c2d52562f36b 39 RawSerial pc(USBTX, USBRX); // tx, rx
cotigac 0:c2d52562f36b 40 #endif
cotigac 0:c2d52562f36b 41
cotigac 0:c2d52562f36b 42 KW40Z::KW40Z(PinName txPin,PinName rxPin) : device(txPin, rxPin), mainThread(&KW40Z::mainStarter, this, osPriorityNormal,1024), rxThread(&KW40Z::rxStarter, this, osPriorityNormal,1024)
cotigac 0:c2d52562f36b 43 {
cotigac 0:c2d52562f36b 44 #if defined (LIB_DEBUG)
cotigac 0:c2d52562f36b 45 pc.baud(115200);
cotigac 0:c2d52562f36b 46 pc.printf("Initializing\r\n");
cotigac 0:c2d52562f36b 47 #endif
cotigac 0:c2d52562f36b 48
cotigac 0:c2d52562f36b 49 device.baud(230400);
cotigac 0:c2d52562f36b 50 device.format(8, Serial::None, 2);
cotigac 0:c2d52562f36b 51
cotigac 0:c2d52562f36b 52 rxBuff = (uint8_t*)&hostInterface_rxPacket;
cotigac 0:c2d52562f36b 53 kw40z_Cbs = NULL;
cotigac 0:c2d52562f36b 54 //memset(&hexiwear_kw40version,0,sizeof(hexiwear_version_t));
cotigac 0:c2d52562f36b 55
cotigac 0:c2d52562f36b 56 /* intialization finalized, signal to start the threads */
cotigac 0:c2d52562f36b 57 mainThread.signal_set(START_THREAD);
cotigac 0:c2d52562f36b 58 rxThread.signal_set(START_THREAD);
cotigac 0:c2d52562f36b 59 }
cotigac 0:c2d52562f36b 60
cotigac 0:c2d52562f36b 61 KW40Z::~KW40Z(void)
cotigac 0:c2d52562f36b 62 {
cotigac 0:c2d52562f36b 63 }
cotigac 0:c2d52562f36b 64
cotigac 0:c2d52562f36b 65 void KW40Z::attach(kw40z_callbacks_t * callbacks)
cotigac 0:c2d52562f36b 66 {
cotigac 0:c2d52562f36b 67 kw40z_Cbs = callbacks;
cotigac 0:c2d52562f36b 68 }
cotigac 0:c2d52562f36b 69
cotigac 0:c2d52562f36b 70 void KW40Z::rxStarter(void const *p) {
cotigac 0:c2d52562f36b 71 KW40Z *instance = (KW40Z*)p;
cotigac 0:c2d52562f36b 72 instance->rxTask();
cotigac 0:c2d52562f36b 73 }
cotigac 0:c2d52562f36b 74
cotigac 0:c2d52562f36b 75 void KW40Z::mainStarter(void const *p) {
cotigac 0:c2d52562f36b 76 KW40Z *instance = (KW40Z*)p;
cotigac 0:c2d52562f36b 77 instance->mainTask();
cotigac 0:c2d52562f36b 78 }
cotigac 0:c2d52562f36b 79
cotigac 0:c2d52562f36b 80 void KW40Z::GetVersion()
cotigac 0:c2d52562f36b 81 {
cotigac 0:c2d52562f36b 82 hostInterface_packet_t txPacket = {0};
cotigac 0:c2d52562f36b 83
cotigac 0:c2d52562f36b 84 txPacket.start1 = gHostInterface_startByte1,
cotigac 0:c2d52562f36b 85 txPacket.start2 = gHostInterface_startByte2,
cotigac 0:c2d52562f36b 86 txPacket.type = packetType_buildVersion,
cotigac 0:c2d52562f36b 87 txPacket.length = 3,
cotigac 0:c2d52562f36b 88 txPacket.data[0] = HEXIWEAR_VERSION_MAJOR;
cotigac 0:c2d52562f36b 89 txPacket.data[1] = HEXIWEAR_VERSION_MINOR;
cotigac 0:c2d52562f36b 90 txPacket.data[2] = HEXIWEAR_VERSION_PATCH;
cotigac 0:c2d52562f36b 91 txPacket.data[3] = gHostInterface_trailerByte;
cotigac 0:c2d52562f36b 92
cotigac 0:c2d52562f36b 93 SendPacket(&txPacket, false);
cotigac 0:c2d52562f36b 94 }
cotigac 0:c2d52562f36b 95
cotigac 0:c2d52562f36b 96 void KW40Z::SendPacket(hostInterface_packet_t * txPacket, bool confirmRequested)
cotigac 0:c2d52562f36b 97 {
cotigac 0:c2d52562f36b 98 uint8_t retries = 0;
cotigac 0:c2d52562f36b 99 confirmReceived = false;
cotigac 0:c2d52562f36b 100
cotigac 0:c2d52562f36b 101 do
cotigac 0:c2d52562f36b 102 {
cotigac 0:c2d52562f36b 103 char * txBuff = (char *)txPacket;
cotigac 0:c2d52562f36b 104 uint8_t length = txPacket->length + gHostInterface_headerSize + 1;
cotigac 0:c2d52562f36b 105
cotigac 0:c2d52562f36b 106 if(confirmRequested == true)
cotigac 0:c2d52562f36b 107 {
cotigac 0:c2d52562f36b 108 txPacket->start2 |= 0x01;
cotigac 0:c2d52562f36b 109 }
cotigac 0:c2d52562f36b 110
cotigac 0:c2d52562f36b 111 for(uint8_t i = 0; i < length; i++)
cotigac 0:c2d52562f36b 112 {
cotigac 0:c2d52562f36b 113 device.putc(*txBuff);
cotigac 0:c2d52562f36b 114 txBuff++;
cotigac 0:c2d52562f36b 115 }
cotigac 0:c2d52562f36b 116
cotigac 0:c2d52562f36b 117 #if defined (LIB_DEBUG)
cotigac 0:c2d52562f36b 118 DebugPrintTxPacket(txPacket);
cotigac 0:c2d52562f36b 119 #endif
cotigac 0:c2d52562f36b 120
cotigac 0:c2d52562f36b 121 retries++;
cotigac 0:c2d52562f36b 122
cotigac 0:c2d52562f36b 123 #if defined (gHostInterface_RxConfirmationEnable)
cotigac 0:c2d52562f36b 124 if((confirmRequested == true) && (confirmReceived == false))
cotigac 0:c2d52562f36b 125 {
cotigac 0:c2d52562f36b 126 Thread::wait(gHostInterface_retransmitTimeout);
cotigac 0:c2d52562f36b 127 }
cotigac 0:c2d52562f36b 128 #endif
cotigac 0:c2d52562f36b 129 }
cotigac 0:c2d52562f36b 130 while((confirmRequested == true) &&
cotigac 0:c2d52562f36b 131 (confirmReceived == false) &&
cotigac 0:c2d52562f36b 132 (retries < gHostInterface_retransmitCount));
cotigac 0:c2d52562f36b 133 }
cotigac 0:c2d52562f36b 134
cotigac 0:c2d52562f36b 135 void KW40Z::mainTask(void)
cotigac 0:c2d52562f36b 136 {
cotigac 0:c2d52562f36b 137 mainThread.signal_wait(START_THREAD);
cotigac 0:c2d52562f36b 138
cotigac 0:c2d52562f36b 139 #if defined (LIB_DEBUG)
cotigac 0:c2d52562f36b 140 pc.printf("MainTask Stared\r\n");
cotigac 0:c2d52562f36b 141 #endif
cotigac 0:c2d52562f36b 142
cotigac 0:c2d52562f36b 143 while(1)
cotigac 0:c2d52562f36b 144 {
cotigac 0:c2d52562f36b 145 osEvent evt = queue.get();
cotigac 0:c2d52562f36b 146 if (evt.status == osEventMessage)
cotigac 0:c2d52562f36b 147 {
cotigac 0:c2d52562f36b 148 hostInterface_packet_t *rxPacket = (hostInterface_packet_t*)evt.value.p;
cotigac 0:c2d52562f36b 149 ProcessReceivedPacket(rxPacket);
cotigac 0:c2d52562f36b 150 mpool.free(rxPacket);
cotigac 0:c2d52562f36b 151 }
cotigac 0:c2d52562f36b 152 }
cotigac 0:c2d52562f36b 153 }
cotigac 0:c2d52562f36b 154
cotigac 0:c2d52562f36b 155 void KW40Z::rxTask(void)
cotigac 0:c2d52562f36b 156 {
cotigac 0:c2d52562f36b 157 rxThread.signal_wait(START_THREAD);
cotigac 0:c2d52562f36b 158
cotigac 0:c2d52562f36b 159 #if defined (LIB_DEBUG)
cotigac 0:c2d52562f36b 160 pc.printf("RxTask Stared\r\n");
cotigac 0:c2d52562f36b 161 #endif
cotigac 0:c2d52562f36b 162
cotigac 0:c2d52562f36b 163 while(1)
cotigac 0:c2d52562f36b 164 {
cotigac 0:c2d52562f36b 165 if(device.readable())
cotigac 0:c2d52562f36b 166 {
cotigac 0:c2d52562f36b 167 *rxBuff++ = device.getc();
cotigac 0:c2d52562f36b 168 ProcessBuffer();
cotigac 0:c2d52562f36b 169
cotigac 0:c2d52562f36b 170 /* check for buffer overflow */
cotigac 0:c2d52562f36b 171 if(rxBuff >= ((uint8_t*)&hostInterface_rxPacket + sizeof(hostInterface_rxPacket)))
cotigac 0:c2d52562f36b 172 {
cotigac 0:c2d52562f36b 173 rxBuff = (uint8_t*)&hostInterface_rxPacket;
cotigac 0:c2d52562f36b 174 }
cotigac 0:c2d52562f36b 175 }
cotigac 0:c2d52562f36b 176 }
cotigac 0:c2d52562f36b 177 }
cotigac 0:c2d52562f36b 178
cotigac 0:c2d52562f36b 179 #if defined (LIB_DEBUG)
cotigac 0:c2d52562f36b 180 void KW40Z::DebugPrintTxPacket(hostInterface_packet_t * txPacket)
cotigac 0:c2d52562f36b 181 {
cotigac 0:c2d52562f36b 182 char * txBuff = (char *)txPacket;
cotigac 0:c2d52562f36b 183 uint8_t length = txPacket->length + gHostInterface_headerSize + 1;
cotigac 0:c2d52562f36b 184
cotigac 0:c2d52562f36b 185 pc.printf("Tx: ");
cotigac 0:c2d52562f36b 186 for(uint8_t i = 0; i < length; i++)
cotigac 0:c2d52562f36b 187 {
cotigac 0:c2d52562f36b 188 pc.printf("%02X ",*txBuff);
cotigac 0:c2d52562f36b 189 txBuff++;
cotigac 0:c2d52562f36b 190 }
cotigac 0:c2d52562f36b 191 pc.printf("\r\n");
cotigac 0:c2d52562f36b 192 }
cotigac 0:c2d52562f36b 193
cotigac 0:c2d52562f36b 194 void KW40Z::DebugPrintRxPacket()
cotigac 0:c2d52562f36b 195 {
cotigac 0:c2d52562f36b 196 pc.printf("RX: ");
cotigac 0:c2d52562f36b 197 for(uint8_t * i = (uint8_t*)&hostInterface_rxPacket; i<rxBuff; i++)
cotigac 0:c2d52562f36b 198 {
cotigac 0:c2d52562f36b 199 pc.printf("%02X ",*i);
cotigac 0:c2d52562f36b 200 }
cotigac 0:c2d52562f36b 201 pc.printf("\r\n");
cotigac 0:c2d52562f36b 202 }
cotigac 0:c2d52562f36b 203 #endif
cotigac 0:c2d52562f36b 204
cotigac 0:c2d52562f36b 205 void KW40Z::ProcessBuffer()
cotigac 0:c2d52562f36b 206 {
cotigac 0:c2d52562f36b 207 /* check if header has been received */
cotigac 0:c2d52562f36b 208 if(rxBuff > ((uint8_t*)&hostInterface_rxPacket + gHostInterface_headerSize))
cotigac 0:c2d52562f36b 209 {
cotigac 0:c2d52562f36b 210 /* check packet header */
cotigac 0:c2d52562f36b 211 if((gHostInterface_startByte1 != hostInterface_rxPacket.start1)||
cotigac 0:c2d52562f36b 212 (gHostInterface_startByte2 != (hostInterface_rxPacket.start2 & 0xFE))||
cotigac 0:c2d52562f36b 213 (hostInterface_rxPacket.length > gHostInterface_dataSize))
cotigac 0:c2d52562f36b 214 {
cotigac 0:c2d52562f36b 215 #if defined (LIB_DEBUG)
cotigac 0:c2d52562f36b 216 DebugPrintRxPacket();
cotigac 0:c2d52562f36b 217 pc.printf("check header failed\r\n");
cotigac 0:c2d52562f36b 218 #endif
cotigac 0:c2d52562f36b 219
cotigac 0:c2d52562f36b 220 SearchStartByte();
cotigac 0:c2d52562f36b 221 }
cotigac 0:c2d52562f36b 222 else
cotigac 0:c2d52562f36b 223 {
cotigac 0:c2d52562f36b 224 /* check data length */
cotigac 0:c2d52562f36b 225 if(rxBuff > ((uint8_t*)&hostInterface_rxPacket + gHostInterface_headerSize + hostInterface_rxPacket.length))
cotigac 0:c2d52562f36b 226 {
cotigac 0:c2d52562f36b 227 /* check trailer byte */
cotigac 0:c2d52562f36b 228 if(gHostInterface_trailerByte != hostInterface_rxPacket.data[hostInterface_rxPacket.length])
cotigac 0:c2d52562f36b 229 {
cotigac 0:c2d52562f36b 230 #if defined (LIB_DEBUG)
cotigac 0:c2d52562f36b 231 DebugPrintRxPacket();
cotigac 0:c2d52562f36b 232 pc.printf("trailer byte failed\r\n");
cotigac 0:c2d52562f36b 233 #endif
cotigac 0:c2d52562f36b 234
cotigac 0:c2d52562f36b 235 SearchStartByte();
cotigac 0:c2d52562f36b 236 }
cotigac 0:c2d52562f36b 237 else
cotigac 0:c2d52562f36b 238 {
cotigac 0:c2d52562f36b 239
cotigac 0:c2d52562f36b 240 #if defined (gHostInterface_RxConfirmationEnable)
cotigac 0:c2d52562f36b 241 if(hostInterface_rxPacket.type == packetType_OK)
cotigac 0:c2d52562f36b 242 {
cotigac 0:c2d52562f36b 243 confirmReceived = true;
cotigac 0:c2d52562f36b 244 }
cotigac 0:c2d52562f36b 245 #endif
cotigac 0:c2d52562f36b 246
cotigac 0:c2d52562f36b 247 /* send message to main task */
cotigac 0:c2d52562f36b 248 hostInterface_packet_t *rxPacket = mpool.alloc();
cotigac 0:c2d52562f36b 249 memcpy(rxPacket, &hostInterface_rxPacket, sizeof(hostInterface_packet_t));
cotigac 0:c2d52562f36b 250 queue.put(rxPacket);
cotigac 0:c2d52562f36b 251
cotigac 0:c2d52562f36b 252 #if defined (LIB_DEBUG)
cotigac 0:c2d52562f36b 253 DebugPrintRxPacket();
cotigac 0:c2d52562f36b 254 #endif
cotigac 0:c2d52562f36b 255 /* reset buffer position */
cotigac 0:c2d52562f36b 256 rxBuff = (uint8_t*)&hostInterface_rxPacket;
cotigac 0:c2d52562f36b 257 }
cotigac 0:c2d52562f36b 258 }
cotigac 0:c2d52562f36b 259 }
cotigac 0:c2d52562f36b 260 }
cotigac 0:c2d52562f36b 261 }
cotigac 0:c2d52562f36b 262
cotigac 0:c2d52562f36b 263 void KW40Z::SearchStartByte()
cotigac 0:c2d52562f36b 264 {
cotigac 0:c2d52562f36b 265 bool found = false;
cotigac 0:c2d52562f36b 266 uint8_t * rdIdx = (uint8_t*)&hostInterface_rxPacket + 1;
cotigac 0:c2d52562f36b 267
cotigac 0:c2d52562f36b 268 while(rdIdx < rxBuff)
cotigac 0:c2d52562f36b 269 {
cotigac 0:c2d52562f36b 270 if(*rdIdx == gHostInterface_startByte1)
cotigac 0:c2d52562f36b 271 {
cotigac 0:c2d52562f36b 272 uint32_t len = rxBuff - rdIdx;
cotigac 0:c2d52562f36b 273
cotigac 0:c2d52562f36b 274 memcpy(&hostInterface_rxPacket,rdIdx,len);
cotigac 0:c2d52562f36b 275 rxBuff -= len;
cotigac 0:c2d52562f36b 276 found = true;
cotigac 0:c2d52562f36b 277
cotigac 0:c2d52562f36b 278 #if defined (LIB_DEBUG)
cotigac 0:c2d52562f36b 279 pc.printf("moving ");
cotigac 0:c2d52562f36b 280 #endif
cotigac 0:c2d52562f36b 281 break;
cotigac 0:c2d52562f36b 282 }
cotigac 0:c2d52562f36b 283 rdIdx++;
cotigac 0:c2d52562f36b 284 }
cotigac 0:c2d52562f36b 285
cotigac 0:c2d52562f36b 286 if(!found)
cotigac 0:c2d52562f36b 287 {
cotigac 0:c2d52562f36b 288 /* reset buffer position */
cotigac 0:c2d52562f36b 289 rxBuff = (uint8_t*)&hostInterface_rxPacket;
cotigac 0:c2d52562f36b 290 }
cotigac 0:c2d52562f36b 291
cotigac 0:c2d52562f36b 292 #if defined (LIB_DEBUG)
cotigac 0:c2d52562f36b 293 pc.printf("search done\r\n");
cotigac 0:c2d52562f36b 294 DebugPrintRxPacket();
cotigac 0:c2d52562f36b 295 #endif
cotigac 0:c2d52562f36b 296 }
cotigac 0:c2d52562f36b 297
cotigac 0:c2d52562f36b 298 void KW40Z::SendPacketOK()
cotigac 0:c2d52562f36b 299 {
cotigac 0:c2d52562f36b 300 hostInterface_packet_t txPacket = {0};
cotigac 0:c2d52562f36b 301
cotigac 0:c2d52562f36b 302 txPacket.start1 = gHostInterface_startByte1,
cotigac 0:c2d52562f36b 303 txPacket.start2 = gHostInterface_startByte2,
cotigac 0:c2d52562f36b 304 txPacket.type = packetType_OK,
cotigac 0:c2d52562f36b 305 txPacket.length = 0,
cotigac 0:c2d52562f36b 306 txPacket.data[0] = gHostInterface_trailerByte;
cotigac 0:c2d52562f36b 307
cotigac 0:c2d52562f36b 308 SendPacket(&txPacket, false);
cotigac 0:c2d52562f36b 309 }
cotigac 0:c2d52562f36b 310
cotigac 0:c2d52562f36b 311 void KW40Z::ConfirmPacketOK()
cotigac 0:c2d52562f36b 312 {
cotigac 0:c2d52562f36b 313 }
cotigac 0:c2d52562f36b 314
cotigac 0:c2d52562f36b 315 void KW40Z::ProcessReceivedPacket(hostInterface_packet_t * rxPacket)
cotigac 0:c2d52562f36b 316 {
cotigac 0:c2d52562f36b 317 #if defined (LIB_DEBUG)
cotigac 0:c2d52562f36b 318 pc.printf("packet found %d\r\n", rxPacket->type);
cotigac 0:c2d52562f36b 319 #endif
cotigac 0:c2d52562f36b 320
cotigac 0:c2d52562f36b 321 #ifdef gHostInterface_TxConfirmationEnable
cotigac 0:c2d52562f36b 322 // acknowledge the packet reception
cotigac 0:c2d52562f36b 323 if ( 1 == ( rxPacket->start2 & 0x01 ) )
cotigac 0:c2d52562f36b 324 {
cotigac 0:c2d52562f36b 325 SendPacketOK();
cotigac 0:c2d52562f36b 326 }
cotigac 0:c2d52562f36b 327 #endif
cotigac 0:c2d52562f36b 328
cotigac 0:c2d52562f36b 329 switch(rxPacket->type)
cotigac 0:c2d52562f36b 330 {
cotigac 0:c2d52562f36b 331 /* button presses */
cotigac 0:c2d52562f36b 332 case packetType_pressUp:
cotigac 0:c2d52562f36b 333 case packetType_pressDown:
cotigac 0:c2d52562f36b 334 case packetType_pressLeft:
cotigac 0:c2d52562f36b 335 case packetType_pressRight:
cotigac 0:c2d52562f36b 336 case packetType_slide:
cotigac 0:c2d52562f36b 337 if((kw40z_Cbs != NULL) && (kw40z_Cbs->buttons != NULL))
cotigac 0:c2d52562f36b 338 {
cotigac 0:c2d52562f36b 339 kw40z_Cbs->buttons((hexi_buttons_t)(rxPacket->type));
cotigac 0:c2d52562f36b 340 }
cotigac 0:c2d52562f36b 341 break;
cotigac 0:c2d52562f36b 342
cotigac 0:c2d52562f36b 343 /* Alert Service */
cotigac 0:c2d52562f36b 344 case packetType_alertIn:
cotigac 0:c2d52562f36b 345 if((kw40z_Cbs != NULL) && (kw40z_Cbs->alert != NULL))
cotigac 0:c2d52562f36b 346 {
cotigac 0:c2d52562f36b 347 kw40z_Cbs->alert(&rxPacket->data[0], rxPacket->length);
cotigac 0:c2d52562f36b 348 }
cotigac 0:c2d52562f36b 349 break;
cotigac 0:c2d52562f36b 350
cotigac 0:c2d52562f36b 351 /* Passkey for pairing received */
cotigac 0:c2d52562f36b 352 case packetType_passDisplay:
cotigac 0:c2d52562f36b 353 if((kw40z_Cbs != NULL) && (kw40z_Cbs->passkey != NULL))
cotigac 0:c2d52562f36b 354 {
cotigac 0:c2d52562f36b 355 kw40z_Cbs->passkey(&rxPacket->data[0]);
cotigac 0:c2d52562f36b 356 }
cotigac 0:c2d52562f36b 357 break;
cotigac 0:c2d52562f36b 358
cotigac 0:c2d52562f36b 359 /* OTAP messages */
cotigac 0:c2d52562f36b 360 case packetType_otapCompleted:
cotigac 0:c2d52562f36b 361 case packetType_otapFailed:
cotigac 0:c2d52562f36b 362 break;
cotigac 0:c2d52562f36b 363
cotigac 0:c2d52562f36b 364 /* TSI Status */
cotigac 0:c2d52562f36b 365 case packetType_buttonsGroupSendActive:
cotigac 0:c2d52562f36b 366 break;
cotigac 0:c2d52562f36b 367
cotigac 0:c2d52562f36b 368 /* Advertisement Mode Info */
cotigac 0:c2d52562f36b 369 case packetType_advModeSend:
cotigac 0:c2d52562f36b 370 break;
cotigac 0:c2d52562f36b 371
cotigac 0:c2d52562f36b 372 /* Link State */
cotigac 0:c2d52562f36b 373 case packetType_linkStateSend:
cotigac 0:c2d52562f36b 374 break;
cotigac 0:c2d52562f36b 375
cotigac 0:c2d52562f36b 376 /* ANCS Service Notification Received */
cotigac 0:c2d52562f36b 377 case packetType_notification:
cotigac 0:c2d52562f36b 378 if((kw40z_Cbs != NULL) && (kw40z_Cbs->notifications != NULL))
cotigac 0:c2d52562f36b 379 {
cotigac 0:c2d52562f36b 380 kw40z_Cbs->notifications(rxPacket->data[0],rxPacket->data[1]);
cotigac 0:c2d52562f36b 381 }
cotigac 0:c2d52562f36b 382 break;
cotigac 0:c2d52562f36b 383
cotigac 0:c2d52562f36b 384 /* Build version */
cotigac 0:c2d52562f36b 385 case packetType_buildVersion:
cotigac 0:c2d52562f36b 386 break;
cotigac 0:c2d52562f36b 387
cotigac 0:c2d52562f36b 388 case packetType_OK:
cotigac 0:c2d52562f36b 389 /* do nothing, the flag is set in the RxTask */
cotigac 0:c2d52562f36b 390 break;
cotigac 0:c2d52562f36b 391
cotigac 0:c2d52562f36b 392 default:
cotigac 0:c2d52562f36b 393 break;
cotigac 0:c2d52562f36b 394 }
cotigac 0:c2d52562f36b 395 }