Hexiwear library for communicating with the on-board KW40Z BLE device. KW40Z handles also the touch buttons.
Dependents: Hexi_BLE_Example_Modified Hexi_BLE_Example_ModifiedPOTATO
Fork of Hexi_KW40Z by
Hexi_KW40Z.cpp@6:23323e8aeda4, 2016-09-25 (annotated)
- Committer:
- cotigac
- Date:
- Sun Sep 25 04:28:52 2016 +0000
- Revision:
- 6:23323e8aeda4
- Parent:
- 5:8c7c1cc024ed
- Child:
- 8:2b9b24f3154d
Updated thread initialization in the class constructor as ARM team suggested
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 | |
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 | 6:23323e8aeda4 | 42 | KW40Z::KW40Z(PinName txPin,PinName rxPin) : device(txPin, rxPin), mainThread(osPriorityNormal,1024), rxThread(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 | 1:f6f9b24aea57 | 53 | |
cotigac | 1:f6f9b24aea57 | 54 | /* initialize callbacks */ |
cotigac | 1:f6f9b24aea57 | 55 | buttonUpCb = NULL; |
cotigac | 1:f6f9b24aea57 | 56 | buttonDownCb = NULL; |
cotigac | 1:f6f9b24aea57 | 57 | buttonLeftCb = NULL; |
cotigac | 1:f6f9b24aea57 | 58 | buttonRightCb = NULL; |
cotigac | 1:f6f9b24aea57 | 59 | buttonSlideCb = NULL; |
cotigac | 1:f6f9b24aea57 | 60 | alertCb = NULL; |
cotigac | 1:f6f9b24aea57 | 61 | passkeyCb = NULL; |
cotigac | 1:f6f9b24aea57 | 62 | notificationsCb = NULL; |
cotigac | 2:bb66c19c3c04 | 63 | |
cotigac | 2:bb66c19c3c04 | 64 | kw40_version.ver_patchNumber = 0; |
cotigac | 2:bb66c19c3c04 | 65 | kw40_version.ver_minorNumber = 0; |
cotigac | 2:bb66c19c3c04 | 66 | kw40_version.ver_majorNumber = 0; |
cotigac | 2:bb66c19c3c04 | 67 | |
cotigac | 2:bb66c19c3c04 | 68 | activeTsiGroup = 0; |
cotigac | 2:bb66c19c3c04 | 69 | advertisementMode = 0; |
cotigac | 2:bb66c19c3c04 | 70 | linkState = 0; |
khuang | 3:9e92f113c671 | 71 | bondPassKey = 0; |
cotigac | 0:c2d52562f36b | 72 | |
cotigac | 0:c2d52562f36b | 73 | /* intialization finalized, signal to start the threads */ |
cotigac | 6:23323e8aeda4 | 74 | mainThread.start(this,&KW40Z::mainTask); |
cotigac | 6:23323e8aeda4 | 75 | rxThread.start(this, &KW40Z::rxTask); |
cotigac | 0:c2d52562f36b | 76 | } |
cotigac | 0:c2d52562f36b | 77 | |
cotigac | 0:c2d52562f36b | 78 | KW40Z::~KW40Z(void) |
cotigac | 0:c2d52562f36b | 79 | { |
cotigac | 0:c2d52562f36b | 80 | } |
cotigac | 0:c2d52562f36b | 81 | |
cotigac | 2:bb66c19c3c04 | 82 | void KW40Z::attach_buttonUp(button_t btnFct) { buttonUpCb = btnFct; } |
cotigac | 2:bb66c19c3c04 | 83 | void KW40Z::attach_buttonDown(button_t btnFct) { buttonDownCb = btnFct; } |
cotigac | 2:bb66c19c3c04 | 84 | void KW40Z::attach_buttonLeft(button_t btnFct) { buttonLeftCb = btnFct; } |
cotigac | 2:bb66c19c3c04 | 85 | void KW40Z::attach_buttonRight(button_t btnFct) { buttonRightCb = btnFct; } |
cotigac | 2:bb66c19c3c04 | 86 | void KW40Z::attach_buttonSlide(button_t btnFct) { buttonSlideCb = btnFct; } |
cotigac | 2:bb66c19c3c04 | 87 | void KW40Z::attach_alert(alert_t alertFct) { alertCb = alertFct; } |
cotigac | 2:bb66c19c3c04 | 88 | void KW40Z::attach_passkey(passkey_t passkeyFct){ passkeyCb = passkeyFct; } |
cotigac | 2:bb66c19c3c04 | 89 | void KW40Z::attach_notifications(notifications_t notFct) { notificationsCb = notFct; } |
cotigac | 0:c2d52562f36b | 90 | |
cotigac | 0:c2d52562f36b | 91 | void KW40Z::mainTask(void) |
cotigac | 0:c2d52562f36b | 92 | { |
cotigac | 0:c2d52562f36b | 93 | #if defined (LIB_DEBUG) |
cotigac | 0:c2d52562f36b | 94 | pc.printf("MainTask Stared\r\n"); |
cotigac | 0:c2d52562f36b | 95 | #endif |
cotigac | 0:c2d52562f36b | 96 | |
cotigac | 2:bb66c19c3c04 | 97 | SendGetActiveTsiGroup(); |
cotigac | 2:bb66c19c3c04 | 98 | SendGetAdvertisementMode(); |
cotigac | 2:bb66c19c3c04 | 99 | SendGetLinkState(); |
cotigac | 2:bb66c19c3c04 | 100 | SendGetVersion(); |
khuang | 3:9e92f113c671 | 101 | |
cotigac | 0:c2d52562f36b | 102 | while(1) |
cotigac | 0:c2d52562f36b | 103 | { |
cotigac | 0:c2d52562f36b | 104 | osEvent evt = queue.get(); |
cotigac | 0:c2d52562f36b | 105 | if (evt.status == osEventMessage) |
cotigac | 0:c2d52562f36b | 106 | { |
cotigac | 0:c2d52562f36b | 107 | hostInterface_packet_t *rxPacket = (hostInterface_packet_t*)evt.value.p; |
cotigac | 0:c2d52562f36b | 108 | ProcessReceivedPacket(rxPacket); |
cotigac | 0:c2d52562f36b | 109 | mpool.free(rxPacket); |
cotigac | 0:c2d52562f36b | 110 | } |
cotigac | 0:c2d52562f36b | 111 | } |
cotigac | 0:c2d52562f36b | 112 | } |
cotigac | 0:c2d52562f36b | 113 | |
cotigac | 0:c2d52562f36b | 114 | void KW40Z::rxTask(void) |
cotigac | 0:c2d52562f36b | 115 | { |
cotigac | 0:c2d52562f36b | 116 | #if defined (LIB_DEBUG) |
cotigac | 0:c2d52562f36b | 117 | pc.printf("RxTask Stared\r\n"); |
cotigac | 0:c2d52562f36b | 118 | #endif |
cotigac | 0:c2d52562f36b | 119 | |
cotigac | 0:c2d52562f36b | 120 | while(1) |
cotigac | 0:c2d52562f36b | 121 | { |
cotigac | 0:c2d52562f36b | 122 | if(device.readable()) |
cotigac | 0:c2d52562f36b | 123 | { |
cotigac | 0:c2d52562f36b | 124 | *rxBuff++ = device.getc(); |
cotigac | 0:c2d52562f36b | 125 | ProcessBuffer(); |
cotigac | 0:c2d52562f36b | 126 | |
cotigac | 0:c2d52562f36b | 127 | /* check for buffer overflow */ |
cotigac | 0:c2d52562f36b | 128 | if(rxBuff >= ((uint8_t*)&hostInterface_rxPacket + sizeof(hostInterface_rxPacket))) |
cotigac | 0:c2d52562f36b | 129 | { |
cotigac | 0:c2d52562f36b | 130 | rxBuff = (uint8_t*)&hostInterface_rxPacket; |
cotigac | 0:c2d52562f36b | 131 | } |
cotigac | 0:c2d52562f36b | 132 | } |
cotigac | 0:c2d52562f36b | 133 | } |
cotigac | 0:c2d52562f36b | 134 | } |
cotigac | 0:c2d52562f36b | 135 | |
cotigac | 0:c2d52562f36b | 136 | #if defined (LIB_DEBUG) |
cotigac | 0:c2d52562f36b | 137 | void KW40Z::DebugPrintTxPacket(hostInterface_packet_t * txPacket) |
cotigac | 0:c2d52562f36b | 138 | { |
cotigac | 0:c2d52562f36b | 139 | char * txBuff = (char *)txPacket; |
cotigac | 0:c2d52562f36b | 140 | uint8_t length = txPacket->length + gHostInterface_headerSize + 1; |
cotigac | 0:c2d52562f36b | 141 | |
cotigac | 0:c2d52562f36b | 142 | pc.printf("Tx: "); |
cotigac | 0:c2d52562f36b | 143 | for(uint8_t i = 0; i < length; i++) |
cotigac | 0:c2d52562f36b | 144 | { |
cotigac | 0:c2d52562f36b | 145 | pc.printf("%02X ",*txBuff); |
cotigac | 0:c2d52562f36b | 146 | txBuff++; |
cotigac | 0:c2d52562f36b | 147 | } |
cotigac | 0:c2d52562f36b | 148 | pc.printf("\r\n"); |
cotigac | 0:c2d52562f36b | 149 | } |
cotigac | 0:c2d52562f36b | 150 | |
cotigac | 0:c2d52562f36b | 151 | void KW40Z::DebugPrintRxPacket() |
cotigac | 0:c2d52562f36b | 152 | { |
cotigac | 0:c2d52562f36b | 153 | pc.printf("RX: "); |
cotigac | 0:c2d52562f36b | 154 | for(uint8_t * i = (uint8_t*)&hostInterface_rxPacket; i<rxBuff; i++) |
cotigac | 0:c2d52562f36b | 155 | { |
cotigac | 0:c2d52562f36b | 156 | pc.printf("%02X ",*i); |
cotigac | 0:c2d52562f36b | 157 | } |
cotigac | 0:c2d52562f36b | 158 | pc.printf("\r\n"); |
cotigac | 0:c2d52562f36b | 159 | } |
cotigac | 0:c2d52562f36b | 160 | #endif |
cotigac | 0:c2d52562f36b | 161 | |
cotigac | 2:bb66c19c3c04 | 162 | |
cotigac | 2:bb66c19c3c04 | 163 | void KW40Z::SendPacket(hostInterface_packet_t * txPacket, bool confirmRequested) |
cotigac | 2:bb66c19c3c04 | 164 | { |
cotigac | 2:bb66c19c3c04 | 165 | uint8_t retries = 0; |
cotigac | 2:bb66c19c3c04 | 166 | confirmReceived = false; |
cotigac | 2:bb66c19c3c04 | 167 | |
cotigac | 2:bb66c19c3c04 | 168 | do |
cotigac | 2:bb66c19c3c04 | 169 | { |
cotigac | 2:bb66c19c3c04 | 170 | char * txBuff = (char *)txPacket; |
cotigac | 2:bb66c19c3c04 | 171 | uint8_t length = txPacket->length + gHostInterface_headerSize + 1; |
cotigac | 2:bb66c19c3c04 | 172 | |
cotigac | 2:bb66c19c3c04 | 173 | if(confirmRequested == true) |
cotigac | 2:bb66c19c3c04 | 174 | { |
cotigac | 2:bb66c19c3c04 | 175 | txPacket->start2 |= 0x01; |
cotigac | 2:bb66c19c3c04 | 176 | } |
cotigac | 2:bb66c19c3c04 | 177 | |
cotigac | 2:bb66c19c3c04 | 178 | for(uint8_t i = 0; i < length; i++) |
cotigac | 2:bb66c19c3c04 | 179 | { |
cotigac | 2:bb66c19c3c04 | 180 | device.putc(*txBuff); |
cotigac | 2:bb66c19c3c04 | 181 | txBuff++; |
cotigac | 2:bb66c19c3c04 | 182 | } |
cotigac | 2:bb66c19c3c04 | 183 | |
cotigac | 2:bb66c19c3c04 | 184 | #if defined (LIB_DEBUG) |
cotigac | 2:bb66c19c3c04 | 185 | DebugPrintTxPacket(txPacket); |
cotigac | 2:bb66c19c3c04 | 186 | #endif |
cotigac | 2:bb66c19c3c04 | 187 | |
cotigac | 2:bb66c19c3c04 | 188 | retries++; |
cotigac | 2:bb66c19c3c04 | 189 | |
cotigac | 2:bb66c19c3c04 | 190 | #if defined (gHostInterface_RxConfirmationEnable) |
cotigac | 2:bb66c19c3c04 | 191 | if((confirmRequested == true) && (confirmReceived == false)) |
cotigac | 2:bb66c19c3c04 | 192 | { |
cotigac | 2:bb66c19c3c04 | 193 | Thread::wait(gHostInterface_retransmitTimeout); |
cotigac | 2:bb66c19c3c04 | 194 | } |
cotigac | 2:bb66c19c3c04 | 195 | #endif |
cotigac | 2:bb66c19c3c04 | 196 | } |
cotigac | 2:bb66c19c3c04 | 197 | while((confirmRequested == true) && |
cotigac | 2:bb66c19c3c04 | 198 | (confirmReceived == false) && |
cotigac | 2:bb66c19c3c04 | 199 | (retries < gHostInterface_retransmitCount)); |
cotigac | 2:bb66c19c3c04 | 200 | } |
cotigac | 2:bb66c19c3c04 | 201 | |
cotigac | 0:c2d52562f36b | 202 | void KW40Z::ProcessBuffer() |
cotigac | 0:c2d52562f36b | 203 | { |
cotigac | 0:c2d52562f36b | 204 | /* check if header has been received */ |
cotigac | 0:c2d52562f36b | 205 | if(rxBuff > ((uint8_t*)&hostInterface_rxPacket + gHostInterface_headerSize)) |
cotigac | 0:c2d52562f36b | 206 | { |
cotigac | 0:c2d52562f36b | 207 | /* check packet header */ |
cotigac | 0:c2d52562f36b | 208 | if((gHostInterface_startByte1 != hostInterface_rxPacket.start1)|| |
cotigac | 0:c2d52562f36b | 209 | (gHostInterface_startByte2 != (hostInterface_rxPacket.start2 & 0xFE))|| |
cotigac | 0:c2d52562f36b | 210 | (hostInterface_rxPacket.length > gHostInterface_dataSize)) |
cotigac | 0:c2d52562f36b | 211 | { |
cotigac | 0:c2d52562f36b | 212 | #if defined (LIB_DEBUG) |
cotigac | 0:c2d52562f36b | 213 | DebugPrintRxPacket(); |
cotigac | 0:c2d52562f36b | 214 | pc.printf("check header failed\r\n"); |
cotigac | 0:c2d52562f36b | 215 | #endif |
cotigac | 0:c2d52562f36b | 216 | |
cotigac | 0:c2d52562f36b | 217 | SearchStartByte(); |
cotigac | 0:c2d52562f36b | 218 | } |
cotigac | 0:c2d52562f36b | 219 | else |
cotigac | 0:c2d52562f36b | 220 | { |
cotigac | 0:c2d52562f36b | 221 | /* check data length */ |
cotigac | 0:c2d52562f36b | 222 | if(rxBuff > ((uint8_t*)&hostInterface_rxPacket + gHostInterface_headerSize + hostInterface_rxPacket.length)) |
cotigac | 0:c2d52562f36b | 223 | { |
cotigac | 0:c2d52562f36b | 224 | /* check trailer byte */ |
cotigac | 0:c2d52562f36b | 225 | if(gHostInterface_trailerByte != hostInterface_rxPacket.data[hostInterface_rxPacket.length]) |
cotigac | 0:c2d52562f36b | 226 | { |
cotigac | 0:c2d52562f36b | 227 | #if defined (LIB_DEBUG) |
cotigac | 0:c2d52562f36b | 228 | DebugPrintRxPacket(); |
cotigac | 0:c2d52562f36b | 229 | pc.printf("trailer byte failed\r\n"); |
cotigac | 0:c2d52562f36b | 230 | #endif |
cotigac | 0:c2d52562f36b | 231 | |
cotigac | 0:c2d52562f36b | 232 | SearchStartByte(); |
cotigac | 0:c2d52562f36b | 233 | } |
cotigac | 0:c2d52562f36b | 234 | else |
cotigac | 0:c2d52562f36b | 235 | { |
cotigac | 0:c2d52562f36b | 236 | |
cotigac | 0:c2d52562f36b | 237 | #if defined (gHostInterface_RxConfirmationEnable) |
cotigac | 0:c2d52562f36b | 238 | if(hostInterface_rxPacket.type == packetType_OK) |
cotigac | 0:c2d52562f36b | 239 | { |
cotigac | 0:c2d52562f36b | 240 | confirmReceived = true; |
cotigac | 0:c2d52562f36b | 241 | } |
cotigac | 0:c2d52562f36b | 242 | #endif |
cotigac | 0:c2d52562f36b | 243 | |
cotigac | 0:c2d52562f36b | 244 | /* send message to main task */ |
cotigac | 0:c2d52562f36b | 245 | hostInterface_packet_t *rxPacket = mpool.alloc(); |
cotigac | 0:c2d52562f36b | 246 | memcpy(rxPacket, &hostInterface_rxPacket, sizeof(hostInterface_packet_t)); |
cotigac | 0:c2d52562f36b | 247 | queue.put(rxPacket); |
cotigac | 0:c2d52562f36b | 248 | |
cotigac | 0:c2d52562f36b | 249 | #if defined (LIB_DEBUG) |
cotigac | 0:c2d52562f36b | 250 | DebugPrintRxPacket(); |
cotigac | 0:c2d52562f36b | 251 | #endif |
cotigac | 0:c2d52562f36b | 252 | /* reset buffer position */ |
cotigac | 0:c2d52562f36b | 253 | rxBuff = (uint8_t*)&hostInterface_rxPacket; |
cotigac | 0:c2d52562f36b | 254 | } |
cotigac | 0:c2d52562f36b | 255 | } |
cotigac | 0:c2d52562f36b | 256 | } |
cotigac | 0:c2d52562f36b | 257 | } |
cotigac | 0:c2d52562f36b | 258 | } |
cotigac | 0:c2d52562f36b | 259 | |
cotigac | 0:c2d52562f36b | 260 | void KW40Z::SearchStartByte() |
cotigac | 0:c2d52562f36b | 261 | { |
cotigac | 0:c2d52562f36b | 262 | bool found = false; |
cotigac | 0:c2d52562f36b | 263 | uint8_t * rdIdx = (uint8_t*)&hostInterface_rxPacket + 1; |
cotigac | 0:c2d52562f36b | 264 | |
cotigac | 0:c2d52562f36b | 265 | while(rdIdx < rxBuff) |
cotigac | 0:c2d52562f36b | 266 | { |
cotigac | 0:c2d52562f36b | 267 | if(*rdIdx == gHostInterface_startByte1) |
cotigac | 0:c2d52562f36b | 268 | { |
cotigac | 0:c2d52562f36b | 269 | uint32_t len = rxBuff - rdIdx; |
cotigac | 0:c2d52562f36b | 270 | |
cotigac | 0:c2d52562f36b | 271 | memcpy(&hostInterface_rxPacket,rdIdx,len); |
cotigac | 0:c2d52562f36b | 272 | rxBuff -= len; |
cotigac | 0:c2d52562f36b | 273 | found = true; |
cotigac | 0:c2d52562f36b | 274 | |
cotigac | 0:c2d52562f36b | 275 | #if defined (LIB_DEBUG) |
cotigac | 0:c2d52562f36b | 276 | pc.printf("moving "); |
cotigac | 0:c2d52562f36b | 277 | #endif |
cotigac | 0:c2d52562f36b | 278 | break; |
cotigac | 0:c2d52562f36b | 279 | } |
cotigac | 0:c2d52562f36b | 280 | rdIdx++; |
cotigac | 0:c2d52562f36b | 281 | } |
cotigac | 0:c2d52562f36b | 282 | |
cotigac | 0:c2d52562f36b | 283 | if(!found) |
cotigac | 0:c2d52562f36b | 284 | { |
cotigac | 0:c2d52562f36b | 285 | /* reset buffer position */ |
cotigac | 0:c2d52562f36b | 286 | rxBuff = (uint8_t*)&hostInterface_rxPacket; |
cotigac | 0:c2d52562f36b | 287 | } |
cotigac | 0:c2d52562f36b | 288 | |
cotigac | 0:c2d52562f36b | 289 | #if defined (LIB_DEBUG) |
cotigac | 0:c2d52562f36b | 290 | pc.printf("search done\r\n"); |
cotigac | 0:c2d52562f36b | 291 | DebugPrintRxPacket(); |
cotigac | 0:c2d52562f36b | 292 | #endif |
cotigac | 0:c2d52562f36b | 293 | } |
cotigac | 0:c2d52562f36b | 294 | |
cotigac | 0:c2d52562f36b | 295 | void KW40Z::ProcessReceivedPacket(hostInterface_packet_t * rxPacket) |
cotigac | 0:c2d52562f36b | 296 | { |
cotigac | 0:c2d52562f36b | 297 | #if defined (LIB_DEBUG) |
cotigac | 0:c2d52562f36b | 298 | pc.printf("packet found %d\r\n", rxPacket->type); |
cotigac | 0:c2d52562f36b | 299 | #endif |
cotigac | 0:c2d52562f36b | 300 | |
cotigac | 0:c2d52562f36b | 301 | #ifdef gHostInterface_TxConfirmationEnable |
cotigac | 0:c2d52562f36b | 302 | // acknowledge the packet reception |
cotigac | 0:c2d52562f36b | 303 | if ( 1 == ( rxPacket->start2 & 0x01 ) ) |
cotigac | 0:c2d52562f36b | 304 | { |
cotigac | 0:c2d52562f36b | 305 | SendPacketOK(); |
cotigac | 0:c2d52562f36b | 306 | } |
cotigac | 0:c2d52562f36b | 307 | #endif |
cotigac | 0:c2d52562f36b | 308 | |
cotigac | 0:c2d52562f36b | 309 | switch(rxPacket->type) |
cotigac | 0:c2d52562f36b | 310 | { |
cotigac | 0:c2d52562f36b | 311 | /* button presses */ |
cotigac | 0:c2d52562f36b | 312 | case packetType_pressUp: |
cotigac | 1:f6f9b24aea57 | 313 | if(buttonUpCb != NULL) buttonUpCb(); |
cotigac | 1:f6f9b24aea57 | 314 | break; |
cotigac | 1:f6f9b24aea57 | 315 | |
cotigac | 0:c2d52562f36b | 316 | case packetType_pressDown: |
cotigac | 1:f6f9b24aea57 | 317 | if(buttonDownCb != NULL) buttonDownCb(); |
cotigac | 1:f6f9b24aea57 | 318 | break; |
cotigac | 1:f6f9b24aea57 | 319 | |
cotigac | 0:c2d52562f36b | 320 | case packetType_pressLeft: |
cotigac | 1:f6f9b24aea57 | 321 | if(buttonLeftCb != NULL) buttonLeftCb(); |
cotigac | 1:f6f9b24aea57 | 322 | break; |
cotigac | 1:f6f9b24aea57 | 323 | |
cotigac | 0:c2d52562f36b | 324 | case packetType_pressRight: |
cotigac | 1:f6f9b24aea57 | 325 | if(buttonRightCb != NULL) buttonRightCb(); |
cotigac | 1:f6f9b24aea57 | 326 | break; |
cotigac | 1:f6f9b24aea57 | 327 | |
cotigac | 0:c2d52562f36b | 328 | case packetType_slide: |
cotigac | 1:f6f9b24aea57 | 329 | if(buttonSlideCb != NULL) buttonSlideCb(); |
cotigac | 0:c2d52562f36b | 330 | break; |
cotigac | 0:c2d52562f36b | 331 | |
cotigac | 0:c2d52562f36b | 332 | /* Alert Service */ |
cotigac | 0:c2d52562f36b | 333 | case packetType_alertIn: |
cotigac | 1:f6f9b24aea57 | 334 | if(alertCb != NULL) alertCb(&rxPacket->data[0], rxPacket->length); |
cotigac | 0:c2d52562f36b | 335 | break; |
cotigac | 0:c2d52562f36b | 336 | |
cotigac | 0:c2d52562f36b | 337 | /* Passkey for pairing received */ |
cotigac | 0:c2d52562f36b | 338 | case packetType_passDisplay: |
khuang | 3:9e92f113c671 | 339 | if(passkeyCb != NULL) |
khuang | 3:9e92f113c671 | 340 | { |
khuang | 3:9e92f113c671 | 341 | memcpy((uint8_t *)&bondPassKey,&rxPacket->data[0], 3); |
khuang | 3:9e92f113c671 | 342 | passkeyCb(); |
khuang | 3:9e92f113c671 | 343 | } |
cotigac | 0:c2d52562f36b | 344 | break; |
cotigac | 0:c2d52562f36b | 345 | |
cotigac | 0:c2d52562f36b | 346 | /* OTAP messages */ |
cotigac | 0:c2d52562f36b | 347 | case packetType_otapCompleted: |
cotigac | 0:c2d52562f36b | 348 | case packetType_otapFailed: |
cotigac | 0:c2d52562f36b | 349 | break; |
cotigac | 0:c2d52562f36b | 350 | |
cotigac | 0:c2d52562f36b | 351 | /* TSI Status */ |
cotigac | 0:c2d52562f36b | 352 | case packetType_buttonsGroupSendActive: |
cotigac | 2:bb66c19c3c04 | 353 | activeTsiGroup = rxPacket->data[0]; |
cotigac | 0:c2d52562f36b | 354 | break; |
cotigac | 0:c2d52562f36b | 355 | |
cotigac | 0:c2d52562f36b | 356 | /* Advertisement Mode Info */ |
cotigac | 0:c2d52562f36b | 357 | case packetType_advModeSend: |
cotigac | 2:bb66c19c3c04 | 358 | advertisementMode = rxPacket->data[0]; |
cotigac | 0:c2d52562f36b | 359 | break; |
cotigac | 0:c2d52562f36b | 360 | |
cotigac | 0:c2d52562f36b | 361 | /* Link State */ |
cotigac | 0:c2d52562f36b | 362 | case packetType_linkStateSend: |
cotigac | 2:bb66c19c3c04 | 363 | linkState = rxPacket->data[0]; |
cotigac | 0:c2d52562f36b | 364 | break; |
cotigac | 0:c2d52562f36b | 365 | |
cotigac | 0:c2d52562f36b | 366 | /* ANCS Service Notification Received */ |
cotigac | 0:c2d52562f36b | 367 | case packetType_notification: |
cotigac | 1:f6f9b24aea57 | 368 | if(notificationsCb != NULL) notificationsCb(rxPacket->data[0], rxPacket->data[1]); |
cotigac | 0:c2d52562f36b | 369 | break; |
cotigac | 0:c2d52562f36b | 370 | |
cotigac | 0:c2d52562f36b | 371 | /* Build version */ |
cotigac | 0:c2d52562f36b | 372 | case packetType_buildVersion: |
cotigac | 2:bb66c19c3c04 | 373 | kw40_version.ver_patchNumber = rxPacket->data[2]; |
cotigac | 2:bb66c19c3c04 | 374 | kw40_version.ver_minorNumber = rxPacket->data[1]; |
cotigac | 2:bb66c19c3c04 | 375 | kw40_version.ver_majorNumber = rxPacket->data[0]; |
cotigac | 0:c2d52562f36b | 376 | break; |
cotigac | 0:c2d52562f36b | 377 | |
cotigac | 0:c2d52562f36b | 378 | case packetType_OK: |
cotigac | 0:c2d52562f36b | 379 | /* do nothing, the flag is set in the RxTask */ |
cotigac | 0:c2d52562f36b | 380 | break; |
cotigac | 0:c2d52562f36b | 381 | |
cotigac | 0:c2d52562f36b | 382 | default: |
cotigac | 0:c2d52562f36b | 383 | break; |
cotigac | 0:c2d52562f36b | 384 | } |
cotigac | 0:c2d52562f36b | 385 | } |
cotigac | 2:bb66c19c3c04 | 386 | |
cotigac | 2:bb66c19c3c04 | 387 | void KW40Z::SendBatteryLevel(uint8_t percentage) |
cotigac | 2:bb66c19c3c04 | 388 | { |
cotigac | 2:bb66c19c3c04 | 389 | hostInterface_packet_t txPacket = {0}; |
cotigac | 2:bb66c19c3c04 | 390 | |
cotigac | 2:bb66c19c3c04 | 391 | txPacket.start1 = gHostInterface_startByte1; |
cotigac | 2:bb66c19c3c04 | 392 | txPacket.start2 = gHostInterface_startByte2; |
cotigac | 2:bb66c19c3c04 | 393 | txPacket.type = packetType_batteryLevel; |
cotigac | 2:bb66c19c3c04 | 394 | txPacket.length = 1; |
cotigac | 2:bb66c19c3c04 | 395 | txPacket.data[0] = percentage; |
cotigac | 2:bb66c19c3c04 | 396 | txPacket.data[1] = gHostInterface_trailerByte; |
cotigac | 2:bb66c19c3c04 | 397 | |
cotigac | 2:bb66c19c3c04 | 398 | SendPacket(&txPacket, true); |
cotigac | 2:bb66c19c3c04 | 399 | } |
cotigac | 2:bb66c19c3c04 | 400 | |
cotigac | 2:bb66c19c3c04 | 401 | void KW40Z::SendAccel(uint8_t x, uint8_t y, uint8_t z) |
cotigac | 2:bb66c19c3c04 | 402 | { |
cotigac | 2:bb66c19c3c04 | 403 | hostInterface_packet_t txPacket = {0}; |
cotigac | 2:bb66c19c3c04 | 404 | |
cotigac | 2:bb66c19c3c04 | 405 | txPacket.start1 = gHostInterface_startByte1; |
cotigac | 2:bb66c19c3c04 | 406 | txPacket.start2 = gHostInterface_startByte2; |
cotigac | 2:bb66c19c3c04 | 407 | txPacket.type = packetType_accel; |
cotigac | 2:bb66c19c3c04 | 408 | txPacket.length = 3; |
cotigac | 2:bb66c19c3c04 | 409 | txPacket.data[0] = x; |
cotigac | 2:bb66c19c3c04 | 410 | txPacket.data[1] = y; |
cotigac | 2:bb66c19c3c04 | 411 | txPacket.data[2] = z; |
cotigac | 2:bb66c19c3c04 | 412 | txPacket.data[3] = gHostInterface_trailerByte; |
cotigac | 2:bb66c19c3c04 | 413 | |
cotigac | 2:bb66c19c3c04 | 414 | SendPacket(&txPacket, true); |
cotigac | 2:bb66c19c3c04 | 415 | } |
cotigac | 2:bb66c19c3c04 | 416 | |
cotigac | 2:bb66c19c3c04 | 417 | void KW40Z::SendGyro(uint8_t x, uint8_t y, uint8_t z) |
cotigac | 2:bb66c19c3c04 | 418 | { |
cotigac | 2:bb66c19c3c04 | 419 | hostInterface_packet_t txPacket = {0}; |
cotigac | 2:bb66c19c3c04 | 420 | |
cotigac | 2:bb66c19c3c04 | 421 | txPacket.start1 = gHostInterface_startByte1; |
cotigac | 2:bb66c19c3c04 | 422 | txPacket.start2 = gHostInterface_startByte2; |
cotigac | 2:bb66c19c3c04 | 423 | txPacket.type = packetType_gyro; |
cotigac | 2:bb66c19c3c04 | 424 | txPacket.length = 3; |
cotigac | 2:bb66c19c3c04 | 425 | txPacket.data[0] = x; |
cotigac | 2:bb66c19c3c04 | 426 | txPacket.data[1] = y; |
cotigac | 2:bb66c19c3c04 | 427 | txPacket.data[2] = z; |
cotigac | 2:bb66c19c3c04 | 428 | txPacket.data[3] = gHostInterface_trailerByte; |
cotigac | 2:bb66c19c3c04 | 429 | |
cotigac | 2:bb66c19c3c04 | 430 | SendPacket(&txPacket, true); |
cotigac | 2:bb66c19c3c04 | 431 | } |
cotigac | 2:bb66c19c3c04 | 432 | |
cotigac | 2:bb66c19c3c04 | 433 | void KW40Z::SendMag(uint8_t x, uint8_t y, uint8_t z) |
cotigac | 2:bb66c19c3c04 | 434 | { |
cotigac | 2:bb66c19c3c04 | 435 | hostInterface_packet_t txPacket = {0}; |
cotigac | 2:bb66c19c3c04 | 436 | |
cotigac | 2:bb66c19c3c04 | 437 | txPacket.start1 = gHostInterface_startByte1; |
cotigac | 2:bb66c19c3c04 | 438 | txPacket.start2 = gHostInterface_startByte2; |
cotigac | 2:bb66c19c3c04 | 439 | txPacket.type = packetType_magnet; |
cotigac | 2:bb66c19c3c04 | 440 | txPacket.length = 3; |
cotigac | 2:bb66c19c3c04 | 441 | txPacket.data[0] = x; |
cotigac | 2:bb66c19c3c04 | 442 | txPacket.data[1] = y; |
cotigac | 2:bb66c19c3c04 | 443 | txPacket.data[2] = z; |
cotigac | 2:bb66c19c3c04 | 444 | txPacket.data[3] = gHostInterface_trailerByte; |
cotigac | 2:bb66c19c3c04 | 445 | |
cotigac | 2:bb66c19c3c04 | 446 | SendPacket(&txPacket, true); |
cotigac | 2:bb66c19c3c04 | 447 | } |
cotigac | 2:bb66c19c3c04 | 448 | |
cotigac | 2:bb66c19c3c04 | 449 | void KW40Z::SendAmbientLight(uint8_t percentage) |
cotigac | 2:bb66c19c3c04 | 450 | { |
cotigac | 2:bb66c19c3c04 | 451 | hostInterface_packet_t txPacket = {0}; |
cotigac | 2:bb66c19c3c04 | 452 | |
cotigac | 2:bb66c19c3c04 | 453 | txPacket.start1 = gHostInterface_startByte1; |
cotigac | 2:bb66c19c3c04 | 454 | txPacket.start2 = gHostInterface_startByte2; |
cotigac | 2:bb66c19c3c04 | 455 | txPacket.type = packetType_ambiLight; |
cotigac | 2:bb66c19c3c04 | 456 | txPacket.length = 1; |
cotigac | 2:bb66c19c3c04 | 457 | txPacket.data[0] = percentage; |
cotigac | 2:bb66c19c3c04 | 458 | txPacket.data[1] = gHostInterface_trailerByte; |
cotigac | 2:bb66c19c3c04 | 459 | |
cotigac | 2:bb66c19c3c04 | 460 | SendPacket(&txPacket, true); |
cotigac | 2:bb66c19c3c04 | 461 | } |
cotigac | 2:bb66c19c3c04 | 462 | |
cotigac | 2:bb66c19c3c04 | 463 | void KW40Z::SendTemperature(uint16_t celsius) |
cotigac | 2:bb66c19c3c04 | 464 | { |
cotigac | 2:bb66c19c3c04 | 465 | hostInterface_packet_t txPacket = {0}; |
cotigac | 2:bb66c19c3c04 | 466 | |
cotigac | 2:bb66c19c3c04 | 467 | txPacket.start1 = gHostInterface_startByte1; |
cotigac | 2:bb66c19c3c04 | 468 | txPacket.start2 = gHostInterface_startByte2; |
cotigac | 2:bb66c19c3c04 | 469 | txPacket.type = packetType_temperature; |
cotigac | 2:bb66c19c3c04 | 470 | txPacket.length = 2; |
cotigac | 2:bb66c19c3c04 | 471 | memcpy(&txPacket.data[0],(uint8_t*)&celsius,txPacket.length); |
cotigac | 2:bb66c19c3c04 | 472 | txPacket.data[2] = 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::SendHumidity(uint16_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_humidity; |
cotigac | 2:bb66c19c3c04 | 484 | txPacket.length = 2; |
cotigac | 2:bb66c19c3c04 | 485 | memcpy(&txPacket.data[0],(uint8_t*)&percentage,txPacket.length); |
cotigac | 2:bb66c19c3c04 | 486 | txPacket.data[2] = 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::SendPressure(uint16_t pascal) |
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_pressure; |
cotigac | 2:bb66c19c3c04 | 498 | txPacket.length = 2; |
cotigac | 2:bb66c19c3c04 | 499 | memcpy(&txPacket.data[0],(uint8_t*)&pascal,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 | |
khuang | 3:9e92f113c671 | 505 | void KW40Z::SendHeartRate(uint8_t rate) |
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_steps; |
cotigac | 2:bb66c19c3c04 | 512 | txPacket.length = 1; |
cotigac | 2:bb66c19c3c04 | 513 | txPacket.data[0] = rate; |
cotigac | 2:bb66c19c3c04 | 514 | txPacket.data[1] = 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::SendSteps(uint16_t steps) |
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_steps; |
cotigac | 2:bb66c19c3c04 | 526 | txPacket.length = 2; |
cotigac | 2:bb66c19c3c04 | 527 | memcpy(&txPacket.data[0],(uint8_t*)&steps,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 | |
cotigac | 2:bb66c19c3c04 | 533 | void KW40Z::SendCalories(uint16_t calories) |
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_calories; |
cotigac | 2:bb66c19c3c04 | 540 | txPacket.length = 2; |
cotigac | 2:bb66c19c3c04 | 541 | memcpy(&txPacket.data[0],(uint8_t*)&calories,txPacket.length); |
cotigac | 2:bb66c19c3c04 | 542 | txPacket.data[2] = 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::SendAlert(uint8_t *pData, uint8_t length) |
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_alertOut; |
cotigac | 2:bb66c19c3c04 | 554 | txPacket.length = length; |
cotigac | 2:bb66c19c3c04 | 555 | memcpy(&txPacket.data[0],pData,length); |
cotigac | 2:bb66c19c3c04 | 556 | txPacket.data[length] = 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::ToggleTsiGroup(void) |
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_buttonsGroupToggleActive; |
cotigac | 2:bb66c19c3c04 | 568 | txPacket.length = 0; |
cotigac | 2:bb66c19c3c04 | 569 | txPacket.data[0] = gHostInterface_trailerByte; |
cotigac | 2:bb66c19c3c04 | 570 | |
cotigac | 2:bb66c19c3c04 | 571 | SendPacket(&txPacket, true); |
cotigac | 2:bb66c19c3c04 | 572 | } |
cotigac | 2:bb66c19c3c04 | 573 | |
cotigac | 2:bb66c19c3c04 | 574 | void KW40Z::ToggleAdvertisementMode(void) |
cotigac | 2:bb66c19c3c04 | 575 | { |
cotigac | 2:bb66c19c3c04 | 576 | hostInterface_packet_t txPacket = {0}; |
cotigac | 2:bb66c19c3c04 | 577 | |
cotigac | 2:bb66c19c3c04 | 578 | txPacket.start1 = gHostInterface_startByte1; |
cotigac | 2:bb66c19c3c04 | 579 | txPacket.start2 = gHostInterface_startByte2; |
cotigac | 2:bb66c19c3c04 | 580 | txPacket.type = packetType_advModeToggle; |
cotigac | 2:bb66c19c3c04 | 581 | txPacket.length = 0; |
cotigac | 2:bb66c19c3c04 | 582 | txPacket.data[0] = gHostInterface_trailerByte; |
cotigac | 2:bb66c19c3c04 | 583 | |
cotigac | 2:bb66c19c3c04 | 584 | SendPacket(&txPacket, true); |
cotigac | 2:bb66c19c3c04 | 585 | } |
cotigac | 2:bb66c19c3c04 | 586 | |
cotigac | 2:bb66c19c3c04 | 587 | void KW40Z::SendSetApplicationMode(gui_current_app_t mode) |
cotigac | 2:bb66c19c3c04 | 588 | { |
cotigac | 2:bb66c19c3c04 | 589 | hostInterface_packet_t txPacket = {0}; |
cotigac | 2:bb66c19c3c04 | 590 | |
cotigac | 2:bb66c19c3c04 | 591 | txPacket.start1 = gHostInterface_startByte1; |
cotigac | 2:bb66c19c3c04 | 592 | txPacket.start2 = gHostInterface_startByte2; |
cotigac | 2:bb66c19c3c04 | 593 | txPacket.type = packetType_appMode; |
cotigac | 2:bb66c19c3c04 | 594 | txPacket.length = 1; |
cotigac | 2:bb66c19c3c04 | 595 | txPacket.data[0] = (uint8_t)mode; |
cotigac | 2:bb66c19c3c04 | 596 | txPacket.data[1] = gHostInterface_trailerByte; |
cotigac | 2:bb66c19c3c04 | 597 | |
cotigac | 2:bb66c19c3c04 | 598 | SendPacket(&txPacket, true); |
cotigac | 2:bb66c19c3c04 | 599 | } |
cotigac | 2:bb66c19c3c04 | 600 | |
cotigac | 2:bb66c19c3c04 | 601 | void KW40Z::SendGetActiveTsiGroup(void) |
cotigac | 2:bb66c19c3c04 | 602 | { |
cotigac | 2:bb66c19c3c04 | 603 | hostInterface_packet_t txPacket = {0}; |
cotigac | 2:bb66c19c3c04 | 604 | |
cotigac | 2:bb66c19c3c04 | 605 | txPacket.start1 = gHostInterface_startByte1; |
cotigac | 2:bb66c19c3c04 | 606 | txPacket.start2 = gHostInterface_startByte2; |
cotigac | 2:bb66c19c3c04 | 607 | txPacket.type = packetType_buttonsGroupGetActive; |
cotigac | 2:bb66c19c3c04 | 608 | txPacket.length = 0; |
cotigac | 2:bb66c19c3c04 | 609 | txPacket.data[0] = gHostInterface_trailerByte; |
cotigac | 2:bb66c19c3c04 | 610 | |
cotigac | 2:bb66c19c3c04 | 611 | SendPacket(&txPacket, false); |
cotigac | 2:bb66c19c3c04 | 612 | } |
cotigac | 2:bb66c19c3c04 | 613 | |
cotigac | 2:bb66c19c3c04 | 614 | void KW40Z::SendGetAdvertisementMode(void) |
cotigac | 2:bb66c19c3c04 | 615 | { |
cotigac | 2:bb66c19c3c04 | 616 | hostInterface_packet_t txPacket = {0}; |
cotigac | 2:bb66c19c3c04 | 617 | |
cotigac | 2:bb66c19c3c04 | 618 | txPacket.start1 = gHostInterface_startByte1; |
cotigac | 2:bb66c19c3c04 | 619 | txPacket.start2 = gHostInterface_startByte2; |
cotigac | 2:bb66c19c3c04 | 620 | txPacket.type = packetType_advModeGet; |
cotigac | 2:bb66c19c3c04 | 621 | txPacket.length = 0; |
cotigac | 2:bb66c19c3c04 | 622 | txPacket.data[0] = gHostInterface_trailerByte; |
cotigac | 2:bb66c19c3c04 | 623 | |
cotigac | 2:bb66c19c3c04 | 624 | SendPacket(&txPacket, false); |
cotigac | 2:bb66c19c3c04 | 625 | } |
cotigac | 2:bb66c19c3c04 | 626 | |
cotigac | 2:bb66c19c3c04 | 627 | void KW40Z::SendGetLinkState(void) |
cotigac | 2:bb66c19c3c04 | 628 | { |
cotigac | 2:bb66c19c3c04 | 629 | hostInterface_packet_t txPacket = {0}; |
cotigac | 2:bb66c19c3c04 | 630 | |
cotigac | 2:bb66c19c3c04 | 631 | txPacket.start1 = gHostInterface_startByte1; |
cotigac | 2:bb66c19c3c04 | 632 | txPacket.start2 = gHostInterface_startByte2; |
cotigac | 2:bb66c19c3c04 | 633 | txPacket.type = packetType_linkStateGet; |
cotigac | 2:bb66c19c3c04 | 634 | txPacket.length = 0; |
cotigac | 2:bb66c19c3c04 | 635 | txPacket.data[0] = gHostInterface_trailerByte; |
cotigac | 2:bb66c19c3c04 | 636 | |
cotigac | 2:bb66c19c3c04 | 637 | SendPacket(&txPacket, false); |
cotigac | 2:bb66c19c3c04 | 638 | } |
cotigac | 2:bb66c19c3c04 | 639 | |
cotigac | 2:bb66c19c3c04 | 640 | void KW40Z::SendGetVersion(void) |
cotigac | 2:bb66c19c3c04 | 641 | { |
cotigac | 2:bb66c19c3c04 | 642 | hostInterface_packet_t txPacket = {0}; |
cotigac | 2:bb66c19c3c04 | 643 | |
cotigac | 2:bb66c19c3c04 | 644 | txPacket.start1 = gHostInterface_startByte1; |
cotigac | 2:bb66c19c3c04 | 645 | txPacket.start2 = gHostInterface_startByte2; |
cotigac | 2:bb66c19c3c04 | 646 | txPacket.type = packetType_buildVersion; |
cotigac | 2:bb66c19c3c04 | 647 | txPacket.length = 3; |
cotigac | 2:bb66c19c3c04 | 648 | txPacket.data[0] = HEXIWEAR_VERSION_MAJOR; |
cotigac | 2:bb66c19c3c04 | 649 | txPacket.data[1] = HEXIWEAR_VERSION_MINOR; |
cotigac | 2:bb66c19c3c04 | 650 | txPacket.data[2] = HEXIWEAR_VERSION_PATCH; |
cotigac | 2:bb66c19c3c04 | 651 | txPacket.data[3] = gHostInterface_trailerByte; |
cotigac | 2:bb66c19c3c04 | 652 | |
cotigac | 2:bb66c19c3c04 | 653 | SendPacket(&txPacket, false); |
cotigac | 2:bb66c19c3c04 | 654 | } |
cotigac | 2:bb66c19c3c04 | 655 | |
cotigac | 2:bb66c19c3c04 | 656 | void KW40Z::SendPacketOK(void) |
cotigac | 2:bb66c19c3c04 | 657 | { |
cotigac | 2:bb66c19c3c04 | 658 | hostInterface_packet_t txPacket = {0}; |
cotigac | 2:bb66c19c3c04 | 659 | |
cotigac | 2:bb66c19c3c04 | 660 | txPacket.start1 = gHostInterface_startByte1; |
cotigac | 2:bb66c19c3c04 | 661 | txPacket.start2 = gHostInterface_startByte2; |
cotigac | 2:bb66c19c3c04 | 662 | txPacket.type = packetType_OK; |
cotigac | 2:bb66c19c3c04 | 663 | txPacket.length = 0; |
cotigac | 2:bb66c19c3c04 | 664 | txPacket.data[0] = gHostInterface_trailerByte; |
cotigac | 2:bb66c19c3c04 | 665 | |
cotigac | 2:bb66c19c3c04 | 666 | SendPacket(&txPacket, false); |
cotigac | 2:bb66c19c3c04 | 667 | } |
khuang | 3:9e92f113c671 | 668 | |
khuang | 3:9e92f113c671 | 669 | uint8_t KW40Z::GetAdvertisementMode(void) |
khuang | 3:9e92f113c671 | 670 | { |
khuang | 3:9e92f113c671 | 671 | return advertisementMode; |
khuang | 3:9e92f113c671 | 672 | } |
khuang | 3:9e92f113c671 | 673 | |
khuang | 3:9e92f113c671 | 674 | uint32_t KW40Z::GetPassKey(void) |
khuang | 3:9e92f113c671 | 675 | { |
khuang | 3:9e92f113c671 | 676 | return bondPassKey; |
khuang | 3:9e92f113c671 | 677 | } |
khuang | 5:8c7c1cc024ed | 678 | |
khuang | 5:8c7c1cc024ed | 679 | uint8_t KW40Z::GetLinkState(void) |
khuang | 5:8c7c1cc024ed | 680 | { |
khuang | 5:8c7c1cc024ed | 681 | return linkState; |
khuang | 5:8c7c1cc024ed | 682 | } |
khuang | 5:8c7c1cc024ed | 683 | |
khuang | 5:8c7c1cc024ed | 684 | hexiwear_version_t KW40Z::GetVersion(void) |
khuang | 5:8c7c1cc024ed | 685 | { |
khuang | 5:8c7c1cc024ed | 686 | return kw40_version; |
khuang | 5:8c7c1cc024ed | 687 | } |
khuang | 5:8c7c1cc024ed | 688 | |
khuang | 5:8c7c1cc024ed | 689 | uint8_t KW40Z::GetTsiGroup(void) |
khuang | 5:8c7c1cc024ed | 690 | { |
khuang | 5:8c7c1cc024ed | 691 | return activeTsiGroup; |
khuang | 5:8c7c1cc024ed | 692 | } |