For final
Dependents: Hexiwear HexiwearFinal HexiwearFinal1
Fork of Hexi_KW40Z by
Hexi_KW40Z.cpp@7:f363aea73f45, 2016-09-25 (annotated)
- Committer:
- khuang
- Date:
- Sun Sep 25 05:24:24 2016 +0000
- Revision:
- 7:f363aea73f45
- Parent:
- 4:8586f50385d2
Changed SendAccel, SendGyro,SendMag functions to accept int16_t for x,y,z instead of uint8_t. Payload length for these should be 6 bytes not 3.
Who changed what in which revision?
User | Revision | Line number | New 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 | |
khuang | 7:f363aea73f45 | 36 | |
cotigac | 0:c2d52562f36b | 37 | #include "Hexi_KW40Z.h" |
cotigac | 0:c2d52562f36b | 38 | |
cotigac | 0:c2d52562f36b | 39 | #if defined (LIB_DEBUG) |
cotigac | 0:c2d52562f36b | 40 | RawSerial pc(USBTX, USBRX); // tx, rx |
cotigac | 0:c2d52562f36b | 41 | #endif |
cotigac | 0:c2d52562f36b | 42 | |
cotigac | 0:c2d52562f36b | 43 | KW40Z::KW40Z(PinName txPin,PinName rxPin) : device(txPin, rxPin), mainThread(&KW40Z::mainStarter, this, osPriorityNormal,1024), rxThread(&KW40Z::rxStarter, this, osPriorityNormal,1024) |
cotigac | 0:c2d52562f36b | 44 | { |
cotigac | 0:c2d52562f36b | 45 | #if defined (LIB_DEBUG) |
cotigac | 0:c2d52562f36b | 46 | pc.baud(115200); |
cotigac | 0:c2d52562f36b | 47 | pc.printf("Initializing\r\n"); |
cotigac | 0:c2d52562f36b | 48 | #endif |
cotigac | 0:c2d52562f36b | 49 | |
cotigac | 0:c2d52562f36b | 50 | device.baud(230400); |
cotigac | 0:c2d52562f36b | 51 | device.format(8, Serial::None, 2); |
cotigac | 0:c2d52562f36b | 52 | |
cotigac | 0:c2d52562f36b | 53 | rxBuff = (uint8_t*)&hostInterface_rxPacket; |
cotigac | 1:f6f9b24aea57 | 54 | |
cotigac | 1:f6f9b24aea57 | 55 | /* initialize callbacks */ |
cotigac | 1:f6f9b24aea57 | 56 | buttonUpCb = NULL; |
cotigac | 1:f6f9b24aea57 | 57 | buttonDownCb = NULL; |
cotigac | 1:f6f9b24aea57 | 58 | buttonLeftCb = NULL; |
cotigac | 1:f6f9b24aea57 | 59 | buttonRightCb = NULL; |
cotigac | 1:f6f9b24aea57 | 60 | buttonSlideCb = NULL; |
cotigac | 1:f6f9b24aea57 | 61 | alertCb = NULL; |
cotigac | 1:f6f9b24aea57 | 62 | passkeyCb = NULL; |
cotigac | 1:f6f9b24aea57 | 63 | notificationsCb = NULL; |
cotigac | 2:bb66c19c3c04 | 64 | |
cotigac | 2:bb66c19c3c04 | 65 | kw40_version.ver_patchNumber = 0; |
cotigac | 2:bb66c19c3c04 | 66 | kw40_version.ver_minorNumber = 0; |
cotigac | 2:bb66c19c3c04 | 67 | kw40_version.ver_majorNumber = 0; |
cotigac | 2:bb66c19c3c04 | 68 | |
cotigac | 2:bb66c19c3c04 | 69 | activeTsiGroup = 0; |
cotigac | 2:bb66c19c3c04 | 70 | advertisementMode = 0; |
cotigac | 2:bb66c19c3c04 | 71 | linkState = 0; |
khuang | 3:9e92f113c671 | 72 | bondPassKey = 0; |
cotigac | 0:c2d52562f36b | 73 | |
cotigac | 0:c2d52562f36b | 74 | /* intialization finalized, signal to start the threads */ |
cotigac | 0:c2d52562f36b | 75 | mainThread.signal_set(START_THREAD); |
cotigac | 0:c2d52562f36b | 76 | rxThread.signal_set(START_THREAD); |
cotigac | 0:c2d52562f36b | 77 | } |
cotigac | 0:c2d52562f36b | 78 | |
cotigac | 0:c2d52562f36b | 79 | KW40Z::~KW40Z(void) |
cotigac | 0:c2d52562f36b | 80 | { |
cotigac | 0:c2d52562f36b | 81 | } |
cotigac | 0:c2d52562f36b | 82 | |
cotigac | 2:bb66c19c3c04 | 83 | void KW40Z::attach_buttonUp(button_t btnFct) { buttonUpCb = btnFct; } |
cotigac | 2:bb66c19c3c04 | 84 | void KW40Z::attach_buttonDown(button_t btnFct) { buttonDownCb = btnFct; } |
cotigac | 2:bb66c19c3c04 | 85 | void KW40Z::attach_buttonLeft(button_t btnFct) { buttonLeftCb = btnFct; } |
cotigac | 2:bb66c19c3c04 | 86 | void KW40Z::attach_buttonRight(button_t btnFct) { buttonRightCb = btnFct; } |
cotigac | 2:bb66c19c3c04 | 87 | void KW40Z::attach_buttonSlide(button_t btnFct) { buttonSlideCb = btnFct; } |
cotigac | 2:bb66c19c3c04 | 88 | void KW40Z::attach_alert(alert_t alertFct) { alertCb = alertFct; } |
cotigac | 2:bb66c19c3c04 | 89 | void KW40Z::attach_passkey(passkey_t passkeyFct){ passkeyCb = passkeyFct; } |
cotigac | 2:bb66c19c3c04 | 90 | void KW40Z::attach_notifications(notifications_t notFct) { notificationsCb = notFct; } |
cotigac | 0:c2d52562f36b | 91 | |
cotigac | 0:c2d52562f36b | 92 | void KW40Z::rxStarter(void const *p) { |
cotigac | 0:c2d52562f36b | 93 | KW40Z *instance = (KW40Z*)p; |
cotigac | 0:c2d52562f36b | 94 | instance->rxTask(); |
cotigac | 0:c2d52562f36b | 95 | } |
cotigac | 0:c2d52562f36b | 96 | |
cotigac | 0:c2d52562f36b | 97 | void KW40Z::mainStarter(void const *p) { |
cotigac | 0:c2d52562f36b | 98 | KW40Z *instance = (KW40Z*)p; |
cotigac | 0:c2d52562f36b | 99 | instance->mainTask(); |
cotigac | 0:c2d52562f36b | 100 | } |
cotigac | 0:c2d52562f36b | 101 | |
cotigac | 0:c2d52562f36b | 102 | void KW40Z::mainTask(void) |
cotigac | 0:c2d52562f36b | 103 | { |
cotigac | 0:c2d52562f36b | 104 | mainThread.signal_wait(START_THREAD); |
cotigac | 0:c2d52562f36b | 105 | |
cotigac | 0:c2d52562f36b | 106 | #if defined (LIB_DEBUG) |
cotigac | 0:c2d52562f36b | 107 | pc.printf("MainTask Stared\r\n"); |
cotigac | 0:c2d52562f36b | 108 | #endif |
cotigac | 0:c2d52562f36b | 109 | |
khuang | 3:9e92f113c671 | 110 | |
cotigac | 2:bb66c19c3c04 | 111 | SendGetActiveTsiGroup(); |
cotigac | 2:bb66c19c3c04 | 112 | SendGetAdvertisementMode(); |
cotigac | 2:bb66c19c3c04 | 113 | SendGetLinkState(); |
cotigac | 2:bb66c19c3c04 | 114 | SendGetVersion(); |
khuang | 3:9e92f113c671 | 115 | |
cotigac | 2:bb66c19c3c04 | 116 | |
cotigac | 0:c2d52562f36b | 117 | while(1) |
cotigac | 0:c2d52562f36b | 118 | { |
cotigac | 0:c2d52562f36b | 119 | osEvent evt = queue.get(); |
cotigac | 0:c2d52562f36b | 120 | if (evt.status == osEventMessage) |
cotigac | 0:c2d52562f36b | 121 | { |
cotigac | 0:c2d52562f36b | 122 | hostInterface_packet_t *rxPacket = (hostInterface_packet_t*)evt.value.p; |
cotigac | 0:c2d52562f36b | 123 | ProcessReceivedPacket(rxPacket); |
cotigac | 0:c2d52562f36b | 124 | mpool.free(rxPacket); |
cotigac | 0:c2d52562f36b | 125 | } |
cotigac | 0:c2d52562f36b | 126 | } |
cotigac | 0:c2d52562f36b | 127 | } |
cotigac | 0:c2d52562f36b | 128 | |
cotigac | 0:c2d52562f36b | 129 | void KW40Z::rxTask(void) |
cotigac | 0:c2d52562f36b | 130 | { |
cotigac | 0:c2d52562f36b | 131 | rxThread.signal_wait(START_THREAD); |
cotigac | 0:c2d52562f36b | 132 | |
cotigac | 0:c2d52562f36b | 133 | #if defined (LIB_DEBUG) |
cotigac | 0:c2d52562f36b | 134 | pc.printf("RxTask Stared\r\n"); |
cotigac | 0:c2d52562f36b | 135 | #endif |
cotigac | 0:c2d52562f36b | 136 | |
cotigac | 0:c2d52562f36b | 137 | while(1) |
cotigac | 0:c2d52562f36b | 138 | { |
cotigac | 0:c2d52562f36b | 139 | if(device.readable()) |
cotigac | 0:c2d52562f36b | 140 | { |
cotigac | 0:c2d52562f36b | 141 | *rxBuff++ = device.getc(); |
cotigac | 0:c2d52562f36b | 142 | ProcessBuffer(); |
cotigac | 0:c2d52562f36b | 143 | |
cotigac | 0:c2d52562f36b | 144 | /* check for buffer overflow */ |
cotigac | 0:c2d52562f36b | 145 | if(rxBuff >= ((uint8_t*)&hostInterface_rxPacket + sizeof(hostInterface_rxPacket))) |
cotigac | 0:c2d52562f36b | 146 | { |
cotigac | 0:c2d52562f36b | 147 | rxBuff = (uint8_t*)&hostInterface_rxPacket; |
cotigac | 0:c2d52562f36b | 148 | } |
cotigac | 0:c2d52562f36b | 149 | } |
cotigac | 0:c2d52562f36b | 150 | } |
cotigac | 0:c2d52562f36b | 151 | } |
cotigac | 0:c2d52562f36b | 152 | |
cotigac | 0:c2d52562f36b | 153 | #if defined (LIB_DEBUG) |
khuang | 7:f363aea73f45 | 154 | |
cotigac | 0:c2d52562f36b | 155 | void KW40Z::DebugPrintTxPacket(hostInterface_packet_t * txPacket) |
cotigac | 0:c2d52562f36b | 156 | { |
cotigac | 0:c2d52562f36b | 157 | char * txBuff = (char *)txPacket; |
cotigac | 0:c2d52562f36b | 158 | uint8_t length = txPacket->length + gHostInterface_headerSize + 1; |
cotigac | 0:c2d52562f36b | 159 | |
cotigac | 0:c2d52562f36b | 160 | pc.printf("Tx: "); |
cotigac | 0:c2d52562f36b | 161 | for(uint8_t i = 0; i < length; i++) |
cotigac | 0:c2d52562f36b | 162 | { |
cotigac | 0:c2d52562f36b | 163 | pc.printf("%02X ",*txBuff); |
cotigac | 0:c2d52562f36b | 164 | txBuff++; |
cotigac | 0:c2d52562f36b | 165 | } |
cotigac | 0:c2d52562f36b | 166 | pc.printf("\r\n"); |
cotigac | 0:c2d52562f36b | 167 | } |
cotigac | 0:c2d52562f36b | 168 | |
cotigac | 0:c2d52562f36b | 169 | void KW40Z::DebugPrintRxPacket() |
cotigac | 0:c2d52562f36b | 170 | { |
cotigac | 0:c2d52562f36b | 171 | pc.printf("RX: "); |
cotigac | 0:c2d52562f36b | 172 | for(uint8_t * i = (uint8_t*)&hostInterface_rxPacket; i<rxBuff; i++) |
cotigac | 0:c2d52562f36b | 173 | { |
cotigac | 0:c2d52562f36b | 174 | pc.printf("%02X ",*i); |
cotigac | 0:c2d52562f36b | 175 | } |
cotigac | 0:c2d52562f36b | 176 | pc.printf("\r\n"); |
cotigac | 0:c2d52562f36b | 177 | } |
cotigac | 0:c2d52562f36b | 178 | #endif |
cotigac | 0:c2d52562f36b | 179 | |
cotigac | 2:bb66c19c3c04 | 180 | |
cotigac | 2:bb66c19c3c04 | 181 | void KW40Z::SendPacket(hostInterface_packet_t * txPacket, bool confirmRequested) |
cotigac | 2:bb66c19c3c04 | 182 | { |
cotigac | 2:bb66c19c3c04 | 183 | uint8_t retries = 0; |
cotigac | 2:bb66c19c3c04 | 184 | confirmReceived = false; |
cotigac | 2:bb66c19c3c04 | 185 | |
cotigac | 2:bb66c19c3c04 | 186 | do |
cotigac | 2:bb66c19c3c04 | 187 | { |
cotigac | 2:bb66c19c3c04 | 188 | char * txBuff = (char *)txPacket; |
cotigac | 2:bb66c19c3c04 | 189 | uint8_t length = txPacket->length + gHostInterface_headerSize + 1; |
cotigac | 2:bb66c19c3c04 | 190 | |
cotigac | 2:bb66c19c3c04 | 191 | if(confirmRequested == true) |
cotigac | 2:bb66c19c3c04 | 192 | { |
cotigac | 2:bb66c19c3c04 | 193 | txPacket->start2 |= 0x01; |
cotigac | 2:bb66c19c3c04 | 194 | } |
cotigac | 2:bb66c19c3c04 | 195 | |
cotigac | 2:bb66c19c3c04 | 196 | for(uint8_t i = 0; i < length; i++) |
cotigac | 2:bb66c19c3c04 | 197 | { |
cotigac | 2:bb66c19c3c04 | 198 | device.putc(*txBuff); |
cotigac | 2:bb66c19c3c04 | 199 | txBuff++; |
cotigac | 2:bb66c19c3c04 | 200 | } |
cotigac | 2:bb66c19c3c04 | 201 | |
cotigac | 2:bb66c19c3c04 | 202 | #if defined (LIB_DEBUG) |
cotigac | 2:bb66c19c3c04 | 203 | DebugPrintTxPacket(txPacket); |
cotigac | 2:bb66c19c3c04 | 204 | #endif |
cotigac | 2:bb66c19c3c04 | 205 | |
cotigac | 2:bb66c19c3c04 | 206 | retries++; |
cotigac | 2:bb66c19c3c04 | 207 | |
cotigac | 2:bb66c19c3c04 | 208 | #if defined (gHostInterface_RxConfirmationEnable) |
cotigac | 2:bb66c19c3c04 | 209 | if((confirmRequested == true) && (confirmReceived == false)) |
cotigac | 2:bb66c19c3c04 | 210 | { |
cotigac | 2:bb66c19c3c04 | 211 | Thread::wait(gHostInterface_retransmitTimeout); |
cotigac | 2:bb66c19c3c04 | 212 | } |
cotigac | 2:bb66c19c3c04 | 213 | #endif |
cotigac | 2:bb66c19c3c04 | 214 | } |
cotigac | 2:bb66c19c3c04 | 215 | while((confirmRequested == true) && |
cotigac | 2:bb66c19c3c04 | 216 | (confirmReceived == false) && |
cotigac | 2:bb66c19c3c04 | 217 | (retries < gHostInterface_retransmitCount)); |
cotigac | 2:bb66c19c3c04 | 218 | } |
cotigac | 2:bb66c19c3c04 | 219 | |
cotigac | 0:c2d52562f36b | 220 | void KW40Z::ProcessBuffer() |
cotigac | 0:c2d52562f36b | 221 | { |
cotigac | 0:c2d52562f36b | 222 | /* check if header has been received */ |
cotigac | 0:c2d52562f36b | 223 | if(rxBuff > ((uint8_t*)&hostInterface_rxPacket + gHostInterface_headerSize)) |
cotigac | 0:c2d52562f36b | 224 | { |
cotigac | 0:c2d52562f36b | 225 | /* check packet header */ |
cotigac | 0:c2d52562f36b | 226 | if((gHostInterface_startByte1 != hostInterface_rxPacket.start1)|| |
cotigac | 0:c2d52562f36b | 227 | (gHostInterface_startByte2 != (hostInterface_rxPacket.start2 & 0xFE))|| |
cotigac | 0:c2d52562f36b | 228 | (hostInterface_rxPacket.length > gHostInterface_dataSize)) |
cotigac | 0:c2d52562f36b | 229 | { |
cotigac | 0:c2d52562f36b | 230 | #if defined (LIB_DEBUG) |
cotigac | 0:c2d52562f36b | 231 | DebugPrintRxPacket(); |
cotigac | 0:c2d52562f36b | 232 | pc.printf("check header 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 | /* check data length */ |
cotigac | 0:c2d52562f36b | 240 | if(rxBuff > ((uint8_t*)&hostInterface_rxPacket + gHostInterface_headerSize + hostInterface_rxPacket.length)) |
cotigac | 0:c2d52562f36b | 241 | { |
cotigac | 0:c2d52562f36b | 242 | /* check trailer byte */ |
cotigac | 0:c2d52562f36b | 243 | if(gHostInterface_trailerByte != hostInterface_rxPacket.data[hostInterface_rxPacket.length]) |
cotigac | 0:c2d52562f36b | 244 | { |
cotigac | 0:c2d52562f36b | 245 | #if defined (LIB_DEBUG) |
cotigac | 0:c2d52562f36b | 246 | DebugPrintRxPacket(); |
cotigac | 0:c2d52562f36b | 247 | pc.printf("trailer byte failed\r\n"); |
cotigac | 0:c2d52562f36b | 248 | #endif |
cotigac | 0:c2d52562f36b | 249 | |
cotigac | 0:c2d52562f36b | 250 | SearchStartByte(); |
cotigac | 0:c2d52562f36b | 251 | } |
cotigac | 0:c2d52562f36b | 252 | else |
cotigac | 0:c2d52562f36b | 253 | { |
cotigac | 0:c2d52562f36b | 254 | |
cotigac | 0:c2d52562f36b | 255 | #if defined (gHostInterface_RxConfirmationEnable) |
cotigac | 0:c2d52562f36b | 256 | if(hostInterface_rxPacket.type == packetType_OK) |
cotigac | 0:c2d52562f36b | 257 | { |
cotigac | 0:c2d52562f36b | 258 | confirmReceived = true; |
cotigac | 0:c2d52562f36b | 259 | } |
cotigac | 0:c2d52562f36b | 260 | #endif |
cotigac | 0:c2d52562f36b | 261 | |
cotigac | 0:c2d52562f36b | 262 | /* send message to main task */ |
cotigac | 0:c2d52562f36b | 263 | hostInterface_packet_t *rxPacket = mpool.alloc(); |
cotigac | 0:c2d52562f36b | 264 | memcpy(rxPacket, &hostInterface_rxPacket, sizeof(hostInterface_packet_t)); |
cotigac | 0:c2d52562f36b | 265 | queue.put(rxPacket); |
cotigac | 0:c2d52562f36b | 266 | |
cotigac | 0:c2d52562f36b | 267 | #if defined (LIB_DEBUG) |
cotigac | 0:c2d52562f36b | 268 | DebugPrintRxPacket(); |
cotigac | 0:c2d52562f36b | 269 | #endif |
cotigac | 0:c2d52562f36b | 270 | /* reset buffer position */ |
cotigac | 0:c2d52562f36b | 271 | rxBuff = (uint8_t*)&hostInterface_rxPacket; |
cotigac | 0:c2d52562f36b | 272 | } |
cotigac | 0:c2d52562f36b | 273 | } |
cotigac | 0:c2d52562f36b | 274 | } |
cotigac | 0:c2d52562f36b | 275 | } |
cotigac | 0:c2d52562f36b | 276 | } |
cotigac | 0:c2d52562f36b | 277 | |
cotigac | 0:c2d52562f36b | 278 | void KW40Z::SearchStartByte() |
cotigac | 0:c2d52562f36b | 279 | { |
cotigac | 0:c2d52562f36b | 280 | bool found = false; |
cotigac | 0:c2d52562f36b | 281 | uint8_t * rdIdx = (uint8_t*)&hostInterface_rxPacket + 1; |
cotigac | 0:c2d52562f36b | 282 | |
cotigac | 0:c2d52562f36b | 283 | while(rdIdx < rxBuff) |
cotigac | 0:c2d52562f36b | 284 | { |
cotigac | 0:c2d52562f36b | 285 | if(*rdIdx == gHostInterface_startByte1) |
cotigac | 0:c2d52562f36b | 286 | { |
cotigac | 0:c2d52562f36b | 287 | uint32_t len = rxBuff - rdIdx; |
cotigac | 0:c2d52562f36b | 288 | |
cotigac | 0:c2d52562f36b | 289 | memcpy(&hostInterface_rxPacket,rdIdx,len); |
cotigac | 0:c2d52562f36b | 290 | rxBuff -= len; |
cotigac | 0:c2d52562f36b | 291 | found = true; |
cotigac | 0:c2d52562f36b | 292 | |
cotigac | 0:c2d52562f36b | 293 | #if defined (LIB_DEBUG) |
cotigac | 0:c2d52562f36b | 294 | pc.printf("moving "); |
cotigac | 0:c2d52562f36b | 295 | #endif |
cotigac | 0:c2d52562f36b | 296 | break; |
cotigac | 0:c2d52562f36b | 297 | } |
cotigac | 0:c2d52562f36b | 298 | rdIdx++; |
cotigac | 0:c2d52562f36b | 299 | } |
cotigac | 0:c2d52562f36b | 300 | |
cotigac | 0:c2d52562f36b | 301 | if(!found) |
cotigac | 0:c2d52562f36b | 302 | { |
cotigac | 0:c2d52562f36b | 303 | /* reset buffer position */ |
cotigac | 0:c2d52562f36b | 304 | rxBuff = (uint8_t*)&hostInterface_rxPacket; |
cotigac | 0:c2d52562f36b | 305 | } |
cotigac | 0:c2d52562f36b | 306 | |
cotigac | 0:c2d52562f36b | 307 | #if defined (LIB_DEBUG) |
cotigac | 0:c2d52562f36b | 308 | pc.printf("search done\r\n"); |
cotigac | 0:c2d52562f36b | 309 | DebugPrintRxPacket(); |
cotigac | 0:c2d52562f36b | 310 | #endif |
cotigac | 0:c2d52562f36b | 311 | } |
cotigac | 0:c2d52562f36b | 312 | |
cotigac | 0:c2d52562f36b | 313 | void KW40Z::ProcessReceivedPacket(hostInterface_packet_t * rxPacket) |
cotigac | 0:c2d52562f36b | 314 | { |
cotigac | 0:c2d52562f36b | 315 | #if defined (LIB_DEBUG) |
cotigac | 0:c2d52562f36b | 316 | pc.printf("packet found %d\r\n", rxPacket->type); |
cotigac | 0:c2d52562f36b | 317 | #endif |
cotigac | 0:c2d52562f36b | 318 | |
cotigac | 0:c2d52562f36b | 319 | #ifdef gHostInterface_TxConfirmationEnable |
cotigac | 0:c2d52562f36b | 320 | // acknowledge the packet reception |
cotigac | 0:c2d52562f36b | 321 | if ( 1 == ( rxPacket->start2 & 0x01 ) ) |
cotigac | 0:c2d52562f36b | 322 | { |
cotigac | 0:c2d52562f36b | 323 | SendPacketOK(); |
cotigac | 0:c2d52562f36b | 324 | } |
cotigac | 0:c2d52562f36b | 325 | #endif |
cotigac | 0:c2d52562f36b | 326 | |
cotigac | 0:c2d52562f36b | 327 | switch(rxPacket->type) |
cotigac | 0:c2d52562f36b | 328 | { |
cotigac | 0:c2d52562f36b | 329 | /* button presses */ |
cotigac | 0:c2d52562f36b | 330 | case packetType_pressUp: |
cotigac | 1:f6f9b24aea57 | 331 | if(buttonUpCb != NULL) buttonUpCb(); |
cotigac | 1:f6f9b24aea57 | 332 | break; |
cotigac | 1:f6f9b24aea57 | 333 | |
cotigac | 0:c2d52562f36b | 334 | case packetType_pressDown: |
cotigac | 1:f6f9b24aea57 | 335 | if(buttonDownCb != NULL) buttonDownCb(); |
cotigac | 1:f6f9b24aea57 | 336 | break; |
cotigac | 1:f6f9b24aea57 | 337 | |
cotigac | 0:c2d52562f36b | 338 | case packetType_pressLeft: |
cotigac | 1:f6f9b24aea57 | 339 | if(buttonLeftCb != NULL) buttonLeftCb(); |
cotigac | 1:f6f9b24aea57 | 340 | break; |
cotigac | 1:f6f9b24aea57 | 341 | |
cotigac | 0:c2d52562f36b | 342 | case packetType_pressRight: |
cotigac | 1:f6f9b24aea57 | 343 | if(buttonRightCb != NULL) buttonRightCb(); |
cotigac | 1:f6f9b24aea57 | 344 | break; |
cotigac | 1:f6f9b24aea57 | 345 | |
cotigac | 0:c2d52562f36b | 346 | case packetType_slide: |
cotigac | 1:f6f9b24aea57 | 347 | if(buttonSlideCb != NULL) buttonSlideCb(); |
cotigac | 0:c2d52562f36b | 348 | break; |
cotigac | 0:c2d52562f36b | 349 | |
cotigac | 0:c2d52562f36b | 350 | /* Alert Service */ |
cotigac | 0:c2d52562f36b | 351 | case packetType_alertIn: |
cotigac | 1:f6f9b24aea57 | 352 | if(alertCb != NULL) alertCb(&rxPacket->data[0], rxPacket->length); |
cotigac | 0:c2d52562f36b | 353 | break; |
cotigac | 0:c2d52562f36b | 354 | |
cotigac | 0:c2d52562f36b | 355 | /* Passkey for pairing received */ |
cotigac | 0:c2d52562f36b | 356 | case packetType_passDisplay: |
khuang | 3:9e92f113c671 | 357 | if(passkeyCb != NULL) |
khuang | 3:9e92f113c671 | 358 | { |
khuang | 3:9e92f113c671 | 359 | memcpy((uint8_t *)&bondPassKey,&rxPacket->data[0], 3); |
khuang | 3:9e92f113c671 | 360 | passkeyCb(); |
khuang | 3:9e92f113c671 | 361 | } |
cotigac | 0:c2d52562f36b | 362 | break; |
cotigac | 0:c2d52562f36b | 363 | |
cotigac | 0:c2d52562f36b | 364 | /* OTAP messages */ |
cotigac | 0:c2d52562f36b | 365 | case packetType_otapCompleted: |
cotigac | 0:c2d52562f36b | 366 | case packetType_otapFailed: |
cotigac | 0:c2d52562f36b | 367 | break; |
cotigac | 0:c2d52562f36b | 368 | |
cotigac | 0:c2d52562f36b | 369 | /* TSI Status */ |
cotigac | 0:c2d52562f36b | 370 | case packetType_buttonsGroupSendActive: |
cotigac | 2:bb66c19c3c04 | 371 | activeTsiGroup = rxPacket->data[0]; |
cotigac | 0:c2d52562f36b | 372 | break; |
cotigac | 0:c2d52562f36b | 373 | |
cotigac | 0:c2d52562f36b | 374 | /* Advertisement Mode Info */ |
cotigac | 0:c2d52562f36b | 375 | case packetType_advModeSend: |
cotigac | 2:bb66c19c3c04 | 376 | advertisementMode = rxPacket->data[0]; |
cotigac | 0:c2d52562f36b | 377 | break; |
cotigac | 0:c2d52562f36b | 378 | |
cotigac | 0:c2d52562f36b | 379 | /* Link State */ |
cotigac | 0:c2d52562f36b | 380 | case packetType_linkStateSend: |
cotigac | 2:bb66c19c3c04 | 381 | linkState = rxPacket->data[0]; |
cotigac | 0:c2d52562f36b | 382 | break; |
cotigac | 0:c2d52562f36b | 383 | |
cotigac | 0:c2d52562f36b | 384 | /* ANCS Service Notification Received */ |
cotigac | 0:c2d52562f36b | 385 | case packetType_notification: |
cotigac | 1:f6f9b24aea57 | 386 | if(notificationsCb != NULL) notificationsCb(rxPacket->data[0], rxPacket->data[1]); |
cotigac | 0:c2d52562f36b | 387 | break; |
cotigac | 0:c2d52562f36b | 388 | |
cotigac | 0:c2d52562f36b | 389 | /* Build version */ |
cotigac | 0:c2d52562f36b | 390 | case packetType_buildVersion: |
cotigac | 2:bb66c19c3c04 | 391 | kw40_version.ver_patchNumber = rxPacket->data[2]; |
cotigac | 2:bb66c19c3c04 | 392 | kw40_version.ver_minorNumber = rxPacket->data[1]; |
cotigac | 2:bb66c19c3c04 | 393 | kw40_version.ver_majorNumber = rxPacket->data[0]; |
cotigac | 0:c2d52562f36b | 394 | break; |
cotigac | 0:c2d52562f36b | 395 | |
cotigac | 0:c2d52562f36b | 396 | case packetType_OK: |
cotigac | 0:c2d52562f36b | 397 | /* do nothing, the flag is set in the RxTask */ |
cotigac | 0:c2d52562f36b | 398 | break; |
cotigac | 0:c2d52562f36b | 399 | |
cotigac | 0:c2d52562f36b | 400 | default: |
cotigac | 0:c2d52562f36b | 401 | break; |
cotigac | 0:c2d52562f36b | 402 | } |
cotigac | 0:c2d52562f36b | 403 | } |
cotigac | 2:bb66c19c3c04 | 404 | |
cotigac | 2:bb66c19c3c04 | 405 | void KW40Z::SendBatteryLevel(uint8_t percentage) |
cotigac | 2:bb66c19c3c04 | 406 | { |
cotigac | 2:bb66c19c3c04 | 407 | hostInterface_packet_t txPacket = {0}; |
cotigac | 2:bb66c19c3c04 | 408 | |
cotigac | 2:bb66c19c3c04 | 409 | txPacket.start1 = gHostInterface_startByte1; |
cotigac | 2:bb66c19c3c04 | 410 | txPacket.start2 = gHostInterface_startByte2; |
cotigac | 2:bb66c19c3c04 | 411 | txPacket.type = packetType_batteryLevel; |
cotigac | 2:bb66c19c3c04 | 412 | txPacket.length = 1; |
cotigac | 2:bb66c19c3c04 | 413 | txPacket.data[0] = percentage; |
cotigac | 2:bb66c19c3c04 | 414 | txPacket.data[1] = gHostInterface_trailerByte; |
cotigac | 2:bb66c19c3c04 | 415 | |
cotigac | 2:bb66c19c3c04 | 416 | SendPacket(&txPacket, true); |
cotigac | 2:bb66c19c3c04 | 417 | } |
cotigac | 2:bb66c19c3c04 | 418 | |
khuang | 7:f363aea73f45 | 419 | void KW40Z::SendAccel(int16_t x, int16_t y, int16_t z) |
cotigac | 2:bb66c19c3c04 | 420 | { |
cotigac | 2:bb66c19c3c04 | 421 | hostInterface_packet_t txPacket = {0}; |
cotigac | 2:bb66c19c3c04 | 422 | |
cotigac | 2:bb66c19c3c04 | 423 | txPacket.start1 = gHostInterface_startByte1; |
cotigac | 2:bb66c19c3c04 | 424 | txPacket.start2 = gHostInterface_startByte2; |
cotigac | 2:bb66c19c3c04 | 425 | txPacket.type = packetType_accel; |
khuang | 7:f363aea73f45 | 426 | txPacket.length = 6; |
khuang | 7:f363aea73f45 | 427 | |
khuang | 7:f363aea73f45 | 428 | txPacket.data[0] = (uint8_t) ((x >> 8)&0xFF); |
khuang | 7:f363aea73f45 | 429 | txPacket.data[1] = (uint8_t) x; |
khuang | 7:f363aea73f45 | 430 | txPacket.data[2] = (uint8_t) ((y >> 8)&0xFF); |
khuang | 7:f363aea73f45 | 431 | txPacket.data[3] = (uint8_t) y; |
khuang | 7:f363aea73f45 | 432 | txPacket.data[4] = (uint8_t) ((z >> 8)&0xFF); |
khuang | 7:f363aea73f45 | 433 | txPacket.data[5] = (uint8_t) z; |
khuang | 7:f363aea73f45 | 434 | txPacket.data[6] = gHostInterface_trailerByte; |
cotigac | 2:bb66c19c3c04 | 435 | |
cotigac | 2:bb66c19c3c04 | 436 | SendPacket(&txPacket, true); |
cotigac | 2:bb66c19c3c04 | 437 | } |
cotigac | 2:bb66c19c3c04 | 438 | |
khuang | 7:f363aea73f45 | 439 | void KW40Z::SendGyro(int16_t x, int16_t y, int16_t z) |
cotigac | 2:bb66c19c3c04 | 440 | { |
cotigac | 2:bb66c19c3c04 | 441 | hostInterface_packet_t txPacket = {0}; |
cotigac | 2:bb66c19c3c04 | 442 | |
cotigac | 2:bb66c19c3c04 | 443 | txPacket.start1 = gHostInterface_startByte1; |
cotigac | 2:bb66c19c3c04 | 444 | txPacket.start2 = gHostInterface_startByte2; |
cotigac | 2:bb66c19c3c04 | 445 | txPacket.type = packetType_gyro; |
khuang | 7:f363aea73f45 | 446 | txPacket.length = 6; |
khuang | 7:f363aea73f45 | 447 | txPacket.data[0] = (uint8_t) ((x >> 8)&0xFF); |
khuang | 7:f363aea73f45 | 448 | txPacket.data[1] = (uint8_t) x; |
khuang | 7:f363aea73f45 | 449 | txPacket.data[2] = (uint8_t) ((y >> 8)&0xFF); |
khuang | 7:f363aea73f45 | 450 | txPacket.data[3] = (uint8_t) y; |
khuang | 7:f363aea73f45 | 451 | txPacket.data[4] = (uint8_t) ((z >> 8)&0xFF); |
khuang | 7:f363aea73f45 | 452 | txPacket.data[5] = (uint8_t) z; |
khuang | 7:f363aea73f45 | 453 | txPacket.data[6] = gHostInterface_trailerByte; |
cotigac | 2:bb66c19c3c04 | 454 | |
cotigac | 2:bb66c19c3c04 | 455 | SendPacket(&txPacket, true); |
cotigac | 2:bb66c19c3c04 | 456 | } |
cotigac | 2:bb66c19c3c04 | 457 | |
khuang | 7:f363aea73f45 | 458 | void KW40Z::SendMag(int16_t x, int16_t y, int16_t z) |
cotigac | 2:bb66c19c3c04 | 459 | { |
cotigac | 2:bb66c19c3c04 | 460 | hostInterface_packet_t txPacket = {0}; |
cotigac | 2:bb66c19c3c04 | 461 | |
cotigac | 2:bb66c19c3c04 | 462 | txPacket.start1 = gHostInterface_startByte1; |
cotigac | 2:bb66c19c3c04 | 463 | txPacket.start2 = gHostInterface_startByte2; |
cotigac | 2:bb66c19c3c04 | 464 | txPacket.type = packetType_magnet; |
khuang | 7:f363aea73f45 | 465 | txPacket.length = 6; |
khuang | 7:f363aea73f45 | 466 | txPacket.data[0] = (uint8_t) ((x >> 8)&0xFF); |
khuang | 7:f363aea73f45 | 467 | txPacket.data[1] = (uint8_t) x; |
khuang | 7:f363aea73f45 | 468 | txPacket.data[2] = (uint8_t) ((y >> 8)&0xFF); |
khuang | 7:f363aea73f45 | 469 | txPacket.data[3] = (uint8_t) y; |
khuang | 7:f363aea73f45 | 470 | txPacket.data[4] = (uint8_t) ((z >> 8)&0xFF); |
khuang | 7:f363aea73f45 | 471 | txPacket.data[5] = (uint8_t) z; |
khuang | 7:f363aea73f45 | 472 | txPacket.data[6] = gHostInterface_trailerByte; |
cotigac | 2:bb66c19c3c04 | 473 | |
cotigac | 2:bb66c19c3c04 | 474 | SendPacket(&txPacket, true); |
cotigac | 2:bb66c19c3c04 | 475 | } |
cotigac | 2:bb66c19c3c04 | 476 | |
cotigac | 2:bb66c19c3c04 | 477 | void KW40Z::SendAmbientLight(uint8_t percentage) |
cotigac | 2:bb66c19c3c04 | 478 | { |
cotigac | 2:bb66c19c3c04 | 479 | hostInterface_packet_t txPacket = {0}; |
cotigac | 2:bb66c19c3c04 | 480 | |
cotigac | 2:bb66c19c3c04 | 481 | txPacket.start1 = gHostInterface_startByte1; |
cotigac | 2:bb66c19c3c04 | 482 | txPacket.start2 = gHostInterface_startByte2; |
cotigac | 2:bb66c19c3c04 | 483 | txPacket.type = packetType_ambiLight; |
cotigac | 2:bb66c19c3c04 | 484 | txPacket.length = 1; |
cotigac | 2:bb66c19c3c04 | 485 | txPacket.data[0] = percentage; |
cotigac | 2:bb66c19c3c04 | 486 | txPacket.data[1] = gHostInterface_trailerByte; |
cotigac | 2:bb66c19c3c04 | 487 | |
cotigac | 2:bb66c19c3c04 | 488 | SendPacket(&txPacket, true); |
cotigac | 2:bb66c19c3c04 | 489 | } |
cotigac | 2:bb66c19c3c04 | 490 | |
cotigac | 2:bb66c19c3c04 | 491 | void KW40Z::SendTemperature(uint16_t celsius) |
cotigac | 2:bb66c19c3c04 | 492 | { |
cotigac | 2:bb66c19c3c04 | 493 | hostInterface_packet_t txPacket = {0}; |
cotigac | 2:bb66c19c3c04 | 494 | |
cotigac | 2:bb66c19c3c04 | 495 | txPacket.start1 = gHostInterface_startByte1; |
cotigac | 2:bb66c19c3c04 | 496 | txPacket.start2 = gHostInterface_startByte2; |
cotigac | 2:bb66c19c3c04 | 497 | txPacket.type = packetType_temperature; |
cotigac | 2:bb66c19c3c04 | 498 | txPacket.length = 2; |
cotigac | 2:bb66c19c3c04 | 499 | memcpy(&txPacket.data[0],(uint8_t*)&celsius,txPacket.length); |
cotigac | 2:bb66c19c3c04 | 500 | txPacket.data[2] = gHostInterface_trailerByte; |
cotigac | 2:bb66c19c3c04 | 501 | |
cotigac | 2:bb66c19c3c04 | 502 | SendPacket(&txPacket, true); |
cotigac | 2:bb66c19c3c04 | 503 | } |
cotigac | 2:bb66c19c3c04 | 504 | |
cotigac | 2:bb66c19c3c04 | 505 | void KW40Z::SendHumidity(uint16_t percentage) |
cotigac | 2:bb66c19c3c04 | 506 | { |
cotigac | 2:bb66c19c3c04 | 507 | hostInterface_packet_t txPacket = {0}; |
cotigac | 2:bb66c19c3c04 | 508 | |
cotigac | 2:bb66c19c3c04 | 509 | txPacket.start1 = gHostInterface_startByte1; |
cotigac | 2:bb66c19c3c04 | 510 | txPacket.start2 = gHostInterface_startByte2; |
cotigac | 2:bb66c19c3c04 | 511 | txPacket.type = packetType_humidity; |
cotigac | 2:bb66c19c3c04 | 512 | txPacket.length = 2; |
cotigac | 2:bb66c19c3c04 | 513 | memcpy(&txPacket.data[0],(uint8_t*)&percentage,txPacket.length); |
cotigac | 2:bb66c19c3c04 | 514 | txPacket.data[2] = gHostInterface_trailerByte; |
cotigac | 2:bb66c19c3c04 | 515 | |
cotigac | 2:bb66c19c3c04 | 516 | SendPacket(&txPacket, true); |
cotigac | 2:bb66c19c3c04 | 517 | } |
cotigac | 2:bb66c19c3c04 | 518 | |
cotigac | 2:bb66c19c3c04 | 519 | void KW40Z::SendPressure(uint16_t pascal) |
cotigac | 2:bb66c19c3c04 | 520 | { |
cotigac | 2:bb66c19c3c04 | 521 | hostInterface_packet_t txPacket = {0}; |
cotigac | 2:bb66c19c3c04 | 522 | |
cotigac | 2:bb66c19c3c04 | 523 | txPacket.start1 = gHostInterface_startByte1; |
cotigac | 2:bb66c19c3c04 | 524 | txPacket.start2 = gHostInterface_startByte2; |
cotigac | 2:bb66c19c3c04 | 525 | txPacket.type = packetType_pressure; |
cotigac | 2:bb66c19c3c04 | 526 | txPacket.length = 2; |
cotigac | 2:bb66c19c3c04 | 527 | memcpy(&txPacket.data[0],(uint8_t*)&pascal,txPacket.length); |
cotigac | 2:bb66c19c3c04 | 528 | txPacket.data[2] = gHostInterface_trailerByte; |
cotigac | 2:bb66c19c3c04 | 529 | |
cotigac | 2:bb66c19c3c04 | 530 | SendPacket(&txPacket, true); |
cotigac | 2:bb66c19c3c04 | 531 | } |
cotigac | 2:bb66c19c3c04 | 532 | |
khuang | 3:9e92f113c671 | 533 | void KW40Z::SendHeartRate(uint8_t rate) |
cotigac | 2:bb66c19c3c04 | 534 | { |
cotigac | 2:bb66c19c3c04 | 535 | hostInterface_packet_t txPacket = {0}; |
cotigac | 2:bb66c19c3c04 | 536 | |
cotigac | 2:bb66c19c3c04 | 537 | txPacket.start1 = gHostInterface_startByte1; |
cotigac | 2:bb66c19c3c04 | 538 | txPacket.start2 = gHostInterface_startByte2; |
cotigac | 2:bb66c19c3c04 | 539 | txPacket.type = packetType_steps; |
cotigac | 2:bb66c19c3c04 | 540 | txPacket.length = 1; |
cotigac | 2:bb66c19c3c04 | 541 | txPacket.data[0] = rate; |
cotigac | 2:bb66c19c3c04 | 542 | txPacket.data[1] = gHostInterface_trailerByte; |
cotigac | 2:bb66c19c3c04 | 543 | |
cotigac | 2:bb66c19c3c04 | 544 | SendPacket(&txPacket, true); |
cotigac | 2:bb66c19c3c04 | 545 | } |
cotigac | 2:bb66c19c3c04 | 546 | |
cotigac | 2:bb66c19c3c04 | 547 | void KW40Z::SendSteps(uint16_t steps) |
cotigac | 2:bb66c19c3c04 | 548 | { |
cotigac | 2:bb66c19c3c04 | 549 | hostInterface_packet_t txPacket = {0}; |
cotigac | 2:bb66c19c3c04 | 550 | |
cotigac | 2:bb66c19c3c04 | 551 | txPacket.start1 = gHostInterface_startByte1; |
cotigac | 2:bb66c19c3c04 | 552 | txPacket.start2 = gHostInterface_startByte2; |
cotigac | 2:bb66c19c3c04 | 553 | txPacket.type = packetType_steps; |
cotigac | 2:bb66c19c3c04 | 554 | txPacket.length = 2; |
cotigac | 2:bb66c19c3c04 | 555 | memcpy(&txPacket.data[0],(uint8_t*)&steps,txPacket.length); |
cotigac | 2:bb66c19c3c04 | 556 | txPacket.data[2] = gHostInterface_trailerByte; |
cotigac | 2:bb66c19c3c04 | 557 | |
cotigac | 2:bb66c19c3c04 | 558 | SendPacket(&txPacket, true); |
cotigac | 2:bb66c19c3c04 | 559 | } |
cotigac | 2:bb66c19c3c04 | 560 | |
cotigac | 2:bb66c19c3c04 | 561 | void KW40Z::SendCalories(uint16_t calories) |
cotigac | 2:bb66c19c3c04 | 562 | { |
cotigac | 2:bb66c19c3c04 | 563 | hostInterface_packet_t txPacket = {0}; |
cotigac | 2:bb66c19c3c04 | 564 | |
cotigac | 2:bb66c19c3c04 | 565 | txPacket.start1 = gHostInterface_startByte1; |
cotigac | 2:bb66c19c3c04 | 566 | txPacket.start2 = gHostInterface_startByte2; |
cotigac | 2:bb66c19c3c04 | 567 | txPacket.type = packetType_calories; |
cotigac | 2:bb66c19c3c04 | 568 | txPacket.length = 2; |
cotigac | 2:bb66c19c3c04 | 569 | memcpy(&txPacket.data[0],(uint8_t*)&calories,txPacket.length); |
cotigac | 2:bb66c19c3c04 | 570 | txPacket.data[2] = gHostInterface_trailerByte; |
cotigac | 2:bb66c19c3c04 | 571 | |
cotigac | 2:bb66c19c3c04 | 572 | SendPacket(&txPacket, true); |
cotigac | 2:bb66c19c3c04 | 573 | } |
cotigac | 2:bb66c19c3c04 | 574 | |
cotigac | 2:bb66c19c3c04 | 575 | void KW40Z::SendAlert(uint8_t *pData, uint8_t length) |
cotigac | 2:bb66c19c3c04 | 576 | { |
cotigac | 2:bb66c19c3c04 | 577 | hostInterface_packet_t txPacket = {0}; |
cotigac | 2:bb66c19c3c04 | 578 | |
cotigac | 2:bb66c19c3c04 | 579 | txPacket.start1 = gHostInterface_startByte1; |
cotigac | 2:bb66c19c3c04 | 580 | txPacket.start2 = gHostInterface_startByte2; |
cotigac | 2:bb66c19c3c04 | 581 | txPacket.type = packetType_alertOut; |
cotigac | 2:bb66c19c3c04 | 582 | txPacket.length = length; |
cotigac | 2:bb66c19c3c04 | 583 | memcpy(&txPacket.data[0],pData,length); |
cotigac | 2:bb66c19c3c04 | 584 | txPacket.data[length] = gHostInterface_trailerByte; |
cotigac | 2:bb66c19c3c04 | 585 | |
cotigac | 2:bb66c19c3c04 | 586 | SendPacket(&txPacket, true); |
cotigac | 2:bb66c19c3c04 | 587 | } |
cotigac | 2:bb66c19c3c04 | 588 | |
cotigac | 2:bb66c19c3c04 | 589 | void KW40Z::ToggleTsiGroup(void) |
cotigac | 2:bb66c19c3c04 | 590 | { |
cotigac | 2:bb66c19c3c04 | 591 | hostInterface_packet_t txPacket = {0}; |
cotigac | 2:bb66c19c3c04 | 592 | |
cotigac | 2:bb66c19c3c04 | 593 | txPacket.start1 = gHostInterface_startByte1; |
cotigac | 2:bb66c19c3c04 | 594 | txPacket.start2 = gHostInterface_startByte2; |
cotigac | 2:bb66c19c3c04 | 595 | txPacket.type = packetType_buttonsGroupToggleActive; |
cotigac | 2:bb66c19c3c04 | 596 | txPacket.length = 0; |
cotigac | 2:bb66c19c3c04 | 597 | txPacket.data[0] = gHostInterface_trailerByte; |
cotigac | 2:bb66c19c3c04 | 598 | |
cotigac | 2:bb66c19c3c04 | 599 | SendPacket(&txPacket, true); |
cotigac | 2:bb66c19c3c04 | 600 | } |
cotigac | 2:bb66c19c3c04 | 601 | |
cotigac | 2:bb66c19c3c04 | 602 | void KW40Z::ToggleAdvertisementMode(void) |
cotigac | 2:bb66c19c3c04 | 603 | { |
cotigac | 2:bb66c19c3c04 | 604 | hostInterface_packet_t txPacket = {0}; |
cotigac | 2:bb66c19c3c04 | 605 | |
cotigac | 2:bb66c19c3c04 | 606 | txPacket.start1 = gHostInterface_startByte1; |
cotigac | 2:bb66c19c3c04 | 607 | txPacket.start2 = gHostInterface_startByte2; |
cotigac | 2:bb66c19c3c04 | 608 | txPacket.type = packetType_advModeToggle; |
cotigac | 2:bb66c19c3c04 | 609 | txPacket.length = 0; |
cotigac | 2:bb66c19c3c04 | 610 | txPacket.data[0] = gHostInterface_trailerByte; |
cotigac | 2:bb66c19c3c04 | 611 | |
cotigac | 2:bb66c19c3c04 | 612 | SendPacket(&txPacket, true); |
cotigac | 2:bb66c19c3c04 | 613 | } |
cotigac | 2:bb66c19c3c04 | 614 | |
cotigac | 2:bb66c19c3c04 | 615 | void KW40Z::SendSetApplicationMode(gui_current_app_t mode) |
cotigac | 2:bb66c19c3c04 | 616 | { |
cotigac | 2:bb66c19c3c04 | 617 | hostInterface_packet_t txPacket = {0}; |
cotigac | 2:bb66c19c3c04 | 618 | |
cotigac | 2:bb66c19c3c04 | 619 | txPacket.start1 = gHostInterface_startByte1; |
cotigac | 2:bb66c19c3c04 | 620 | txPacket.start2 = gHostInterface_startByte2; |
cotigac | 2:bb66c19c3c04 | 621 | txPacket.type = packetType_appMode; |
cotigac | 2:bb66c19c3c04 | 622 | txPacket.length = 1; |
cotigac | 2:bb66c19c3c04 | 623 | txPacket.data[0] = (uint8_t)mode; |
cotigac | 2:bb66c19c3c04 | 624 | txPacket.data[1] = gHostInterface_trailerByte; |
cotigac | 2:bb66c19c3c04 | 625 | |
cotigac | 2:bb66c19c3c04 | 626 | SendPacket(&txPacket, true); |
cotigac | 2:bb66c19c3c04 | 627 | } |
cotigac | 2:bb66c19c3c04 | 628 | |
cotigac | 2:bb66c19c3c04 | 629 | void KW40Z::SendGetActiveTsiGroup(void) |
cotigac | 2:bb66c19c3c04 | 630 | { |
cotigac | 2:bb66c19c3c04 | 631 | hostInterface_packet_t txPacket = {0}; |
cotigac | 2:bb66c19c3c04 | 632 | |
cotigac | 2:bb66c19c3c04 | 633 | txPacket.start1 = gHostInterface_startByte1; |
cotigac | 2:bb66c19c3c04 | 634 | txPacket.start2 = gHostInterface_startByte2; |
cotigac | 2:bb66c19c3c04 | 635 | txPacket.type = packetType_buttonsGroupGetActive; |
cotigac | 2:bb66c19c3c04 | 636 | txPacket.length = 0; |
cotigac | 2:bb66c19c3c04 | 637 | txPacket.data[0] = gHostInterface_trailerByte; |
cotigac | 2:bb66c19c3c04 | 638 | |
cotigac | 2:bb66c19c3c04 | 639 | SendPacket(&txPacket, false); |
cotigac | 2:bb66c19c3c04 | 640 | } |
cotigac | 2:bb66c19c3c04 | 641 | |
cotigac | 2:bb66c19c3c04 | 642 | void KW40Z::SendGetAdvertisementMode(void) |
cotigac | 2:bb66c19c3c04 | 643 | { |
cotigac | 2:bb66c19c3c04 | 644 | hostInterface_packet_t txPacket = {0}; |
cotigac | 2:bb66c19c3c04 | 645 | |
cotigac | 2:bb66c19c3c04 | 646 | txPacket.start1 = gHostInterface_startByte1; |
cotigac | 2:bb66c19c3c04 | 647 | txPacket.start2 = gHostInterface_startByte2; |
cotigac | 2:bb66c19c3c04 | 648 | txPacket.type = packetType_advModeGet; |
cotigac | 2:bb66c19c3c04 | 649 | txPacket.length = 0; |
cotigac | 2:bb66c19c3c04 | 650 | txPacket.data[0] = gHostInterface_trailerByte; |
cotigac | 2:bb66c19c3c04 | 651 | |
cotigac | 2:bb66c19c3c04 | 652 | SendPacket(&txPacket, false); |
cotigac | 2:bb66c19c3c04 | 653 | } |
cotigac | 2:bb66c19c3c04 | 654 | |
cotigac | 2:bb66c19c3c04 | 655 | void KW40Z::SendGetLinkState(void) |
cotigac | 2:bb66c19c3c04 | 656 | { |
cotigac | 2:bb66c19c3c04 | 657 | hostInterface_packet_t txPacket = {0}; |
cotigac | 2:bb66c19c3c04 | 658 | |
cotigac | 2:bb66c19c3c04 | 659 | txPacket.start1 = gHostInterface_startByte1; |
cotigac | 2:bb66c19c3c04 | 660 | txPacket.start2 = gHostInterface_startByte2; |
cotigac | 2:bb66c19c3c04 | 661 | txPacket.type = packetType_linkStateGet; |
cotigac | 2:bb66c19c3c04 | 662 | txPacket.length = 0; |
cotigac | 2:bb66c19c3c04 | 663 | txPacket.data[0] = gHostInterface_trailerByte; |
cotigac | 2:bb66c19c3c04 | 664 | |
cotigac | 2:bb66c19c3c04 | 665 | SendPacket(&txPacket, false); |
cotigac | 2:bb66c19c3c04 | 666 | } |
cotigac | 2:bb66c19c3c04 | 667 | |
cotigac | 2:bb66c19c3c04 | 668 | void KW40Z::SendGetVersion(void) |
cotigac | 2:bb66c19c3c04 | 669 | { |
cotigac | 2:bb66c19c3c04 | 670 | hostInterface_packet_t txPacket = {0}; |
cotigac | 2:bb66c19c3c04 | 671 | |
cotigac | 2:bb66c19c3c04 | 672 | txPacket.start1 = gHostInterface_startByte1; |
cotigac | 2:bb66c19c3c04 | 673 | txPacket.start2 = gHostInterface_startByte2; |
cotigac | 2:bb66c19c3c04 | 674 | txPacket.type = packetType_buildVersion; |
cotigac | 2:bb66c19c3c04 | 675 | txPacket.length = 3; |
cotigac | 2:bb66c19c3c04 | 676 | txPacket.data[0] = HEXIWEAR_VERSION_MAJOR; |
cotigac | 2:bb66c19c3c04 | 677 | txPacket.data[1] = HEXIWEAR_VERSION_MINOR; |
cotigac | 2:bb66c19c3c04 | 678 | txPacket.data[2] = HEXIWEAR_VERSION_PATCH; |
cotigac | 2:bb66c19c3c04 | 679 | txPacket.data[3] = gHostInterface_trailerByte; |
cotigac | 2:bb66c19c3c04 | 680 | |
cotigac | 2:bb66c19c3c04 | 681 | SendPacket(&txPacket, false); |
cotigac | 2:bb66c19c3c04 | 682 | } |
cotigac | 2:bb66c19c3c04 | 683 | |
cotigac | 2:bb66c19c3c04 | 684 | void KW40Z::SendPacketOK(void) |
cotigac | 2:bb66c19c3c04 | 685 | { |
cotigac | 2:bb66c19c3c04 | 686 | hostInterface_packet_t txPacket = {0}; |
cotigac | 2:bb66c19c3c04 | 687 | |
cotigac | 2:bb66c19c3c04 | 688 | txPacket.start1 = gHostInterface_startByte1; |
cotigac | 2:bb66c19c3c04 | 689 | txPacket.start2 = gHostInterface_startByte2; |
cotigac | 2:bb66c19c3c04 | 690 | txPacket.type = packetType_OK; |
cotigac | 2:bb66c19c3c04 | 691 | txPacket.length = 0; |
cotigac | 2:bb66c19c3c04 | 692 | txPacket.data[0] = gHostInterface_trailerByte; |
cotigac | 2:bb66c19c3c04 | 693 | |
cotigac | 2:bb66c19c3c04 | 694 | SendPacket(&txPacket, false); |
cotigac | 2:bb66c19c3c04 | 695 | } |
khuang | 3:9e92f113c671 | 696 | |
khuang | 3:9e92f113c671 | 697 | uint8_t KW40Z::GetAdvertisementMode(void) |
khuang | 3:9e92f113c671 | 698 | { |
khuang | 3:9e92f113c671 | 699 | return advertisementMode; |
khuang | 3:9e92f113c671 | 700 | } |
khuang | 3:9e92f113c671 | 701 | |
khuang | 3:9e92f113c671 | 702 | uint32_t KW40Z::GetPassKey(void) |
khuang | 3:9e92f113c671 | 703 | { |
khuang | 3:9e92f113c671 | 704 | return bondPassKey; |
khuang | 3:9e92f113c671 | 705 | } |
khuang | 4:8586f50385d2 | 706 | |
khuang | 4:8586f50385d2 | 707 | uint8_t KW40Z::GetLinkState(void) |
khuang | 4:8586f50385d2 | 708 | { |
khuang | 4:8586f50385d2 | 709 | return linkState; |
khuang | 4:8586f50385d2 | 710 | } |
khuang | 4:8586f50385d2 | 711 | |
khuang | 4:8586f50385d2 | 712 | hexiwear_version_t KW40Z::GetVersion(void) |
khuang | 4:8586f50385d2 | 713 | { |
khuang | 4:8586f50385d2 | 714 | return kw40_version; |
khuang | 4:8586f50385d2 | 715 | } |
khuang | 4:8586f50385d2 | 716 | |
khuang | 4:8586f50385d2 | 717 | uint8_t KW40Z::GetTsiGroup(void) |
khuang | 4:8586f50385d2 | 718 | { |
khuang | 4:8586f50385d2 | 719 | return activeTsiGroup; |
khuang | 4:8586f50385d2 | 720 | } |
khuang | 4:8586f50385d2 | 721 | |
khuang | 3:9e92f113c671 | 722 |