
USED IMAGE2GLCD
Dependencies: BLE_API SharpLCD_LucidaFont mbed nRF51822
Fork of Renard_YO by
main.cpp@8:bb11edbf5708, 2015-04-24 (annotated)
- Committer:
- andcor02
- Date:
- Fri Apr 24 10:11:59 2015 +0000
- Revision:
- 8:bb11edbf5708
- Parent:
- 7:8712aa56ee92
- Child:
- 9:bae7cfbe8d85
ADDED ANIMATNIONS, DATE AND TIME , MONTH;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
andcor02 | 6:9ea3943e9e24 | 1 | /* mbed Microcontroller Library |
andcor02 | 6:9ea3943e9e24 | 2 | * Copyright (c) 2006-2013 ARM Limited |
andcor02 | 6:9ea3943e9e24 | 3 | * |
andcor02 | 6:9ea3943e9e24 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
andcor02 | 6:9ea3943e9e24 | 5 | * you may not use this file except in compliance with the License. |
andcor02 | 6:9ea3943e9e24 | 6 | * You may obtain a copy of the License at |
andcor02 | 6:9ea3943e9e24 | 7 | * |
andcor02 | 6:9ea3943e9e24 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
andcor02 | 6:9ea3943e9e24 | 9 | * |
andcor02 | 6:9ea3943e9e24 | 10 | * Unless required by applicable law or agreed to in writing, software |
andcor02 | 6:9ea3943e9e24 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
andcor02 | 6:9ea3943e9e24 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
andcor02 | 6:9ea3943e9e24 | 13 | * See the License for the specific language governing permissions and |
andcor02 | 6:9ea3943e9e24 | 14 | * limitations under the License. |
andcor02 | 6:9ea3943e9e24 | 15 | */ |
erigow01 | 0:9bea6067730f | 16 | |
andcor02 | 6:9ea3943e9e24 | 17 | #include "mbed.h" |
andcor02 | 6:9ea3943e9e24 | 18 | #include "SharpLCD.hpp" |
andcor02 | 6:9ea3943e9e24 | 19 | #include "BLEDevice.h" |
andcor02 | 6:9ea3943e9e24 | 20 | #include "icon.h" |
andcor02 | 6:9ea3943e9e24 | 21 | #include "font.h" |
andcor02 | 6:9ea3943e9e24 | 22 | |
andcor02 | 6:9ea3943e9e24 | 23 | Serial pc (USBTX,USBRX); |
andcor02 | 6:9ea3943e9e24 | 24 | |
andcor02 | 6:9ea3943e9e24 | 25 | DigitalOut led1(P0_12); |
andcor02 | 6:9ea3943e9e24 | 26 | DigitalOut motor(P0_1); |
andcor02 | 6:9ea3943e9e24 | 27 | DigitalOut screen(P0_21); |
andcor02 | 6:9ea3943e9e24 | 28 | DigitalIn button(P0_16); |
andcor02 | 8:bb11edbf5708 | 29 | //a50,a60,a70,a80,a90,a100,a110,a120,a130,a140,a150,a160,a170 |
andcor02 | 7:8712aa56ee92 | 30 | |
andcor02 | 7:8712aa56ee92 | 31 | char strn[50]; // incoming tx data |
andcor02 | 7:8712aa56ee92 | 32 | char user[50]; // username to display |
andcor02 | 8:bb11edbf5708 | 33 | uint8_t* rings[2] = {a0,a10}; |
andcor02 | 6:9ea3943e9e24 | 34 | int set=0; |
andcor02 | 6:9ea3943e9e24 | 35 | int set2=0; |
andcor02 | 8:bb11edbf5708 | 36 | int pairing =1; |
andcor02 | 8:bb11edbf5708 | 37 | int anim=0; |
andcor02 | 8:bb11edbf5708 | 38 | int elip=0; |
andcor02 | 6:9ea3943e9e24 | 39 | |
andcor02 | 7:8712aa56ee92 | 40 | int timeUpdate = 1; |
andcor02 | 7:8712aa56ee92 | 41 | time_t unixTime; |
andcor02 | 7:8712aa56ee92 | 42 | char timeStr[50]; // time to display |
andcor02 | 8:bb11edbf5708 | 43 | char dayStr[50]; // day to display |
andcor02 | 8:bb11edbf5708 | 44 | char dateStr[50]; // date to display |
andcor02 | 7:8712aa56ee92 | 45 | Timer mClock; |
andcor02 | 7:8712aa56ee92 | 46 | int clockOffset = 0; |
andcor02 | 7:8712aa56ee92 | 47 | int lastms = 0; |
andcor02 | 6:9ea3943e9e24 | 48 | |
andcor02 | 6:9ea3943e9e24 | 49 | //SharpLCD(PinName enable, PinName cs, PinName mosi, PinName miso_unused, PinName sclk, PinName _unused = NC) |
awatt196 | 3:e73cbdf58f5b | 50 | SharpLCD lcd(P0_0, P0_24, P0_20, P0_22, P0_25, P0_27); |
andcor02 | 6:9ea3943e9e24 | 51 | //SharpLCD lcd(P0_25, P0_24, P0_23, P0_13, P0_22, P0_27); |
awatt196 | 3:e73cbdf58f5b | 52 | uint8_t framebuffer[SharpLCD::SIZEOF_FRAMEBUFFER_FOR_ALLOC]; |
awatt196 | 3:e73cbdf58f5b | 53 | SharpLCD::FrameBuffer fb(framebuffer); |
andcor02 | 7:8712aa56ee92 | 54 | BLEDevice ble; |
andcor02 | 6:9ea3943e9e24 | 55 | //UARTService uart(ble); |
erigow01 | 0:9bea6067730f | 56 | |
andcor02 | 6:9ea3943e9e24 | 57 | // The Nordic UART Service |
andcor02 | 6:9ea3943e9e24 | 58 | static const uint8_t uart_base_uuid[] = {0x6e, 0x40, 0x00, 0x01, 0xb5, 0xa3, 0xf3, 0x93, 0xe0, 0xa9, 0xe5,0x0e, 0x24, 0xdc, 0xca, 0x9e}; |
andcor02 | 6:9ea3943e9e24 | 59 | static const uint8_t uart_tx_uuid[] = {0x6e, 0x40, 0x00, 0x02, 0xb5, 0xa3, 0xf3, 0x93, 0xe0, 0xa9, 0xe5,0x0e, 0x24, 0xdc, 0xca, 0x9e}; |
andcor02 | 6:9ea3943e9e24 | 60 | static const uint8_t uart_rx_uuid[] = {0x6e, 0x40, 0x00, 0x03, 0xb5, 0xa3, 0xf3, 0x93, 0xe0, 0xa9, 0xe5,0x0e, 0x24, 0xdc, 0xca, 0x9e}; |
andcor02 | 6:9ea3943e9e24 | 61 | static const uint8_t uart_base_uuid_rev[] = {0x9e, 0xca, 0xdc, 0x24, 0x0e, 0xe5, 0xa9, 0xe0, 0x93, 0xf3, 0xa3, 0xb5, 0x01, 0x00, 0x40, 0x6e}; |
andcor02 | 6:9ea3943e9e24 | 62 | uint8_t txPayload[50] = {0}; |
andcor02 | 6:9ea3943e9e24 | 63 | uint8_t rxPayload[50] = {0}; |
andcor02 | 6:9ea3943e9e24 | 64 | GattCharacteristic txCharacteristic (uart_tx_uuid, txPayload, 1, 50, |
andcor02 | 6:9ea3943e9e24 | 65 | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE_WITHOUT_RESPONSE); |
andcor02 | 6:9ea3943e9e24 | 66 | GattCharacteristic rxCharacteristic (uart_rx_uuid, rxPayload, 1, 50, |
andcor02 | 7:8712aa56ee92 | 67 | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ); |
andcor02 | 6:9ea3943e9e24 | 68 | GattCharacteristic *uartChars[] = {&txCharacteristic, &rxCharacteristic}; |
andcor02 | 6:9ea3943e9e24 | 69 | GattService uartService(uart_base_uuid, uartChars, sizeof(uartChars) / sizeof(GattCharacteristic *)); |
erigow01 | 0:9bea6067730f | 70 | |
awatt196 | 3:e73cbdf58f5b | 71 | |
andcor02 | 6:9ea3943e9e24 | 72 | void screenSetup() |
andcor02 | 6:9ea3943e9e24 | 73 | { |
andcor02 | 6:9ea3943e9e24 | 74 | screen=1; |
andcor02 | 6:9ea3943e9e24 | 75 | wait_ms(200); |
andcor02 | 6:9ea3943e9e24 | 76 | lcd.enableDisplay(); |
andcor02 | 6:9ea3943e9e24 | 77 | fb.clear(); |
awatt196 | 3:e73cbdf58f5b | 78 | lcd.clear(); |
andcor02 | 8:bb11edbf5708 | 79 | |
andcor02 | 8:bb11edbf5708 | 80 | |
andcor02 | 8:bb11edbf5708 | 81 | } |
andcor02 | 8:bb11edbf5708 | 82 | |
andcor02 | 8:bb11edbf5708 | 83 | void showPairing() |
andcor02 | 8:bb11edbf5708 | 84 | { |
andcor02 | 8:bb11edbf5708 | 85 | fb.clear(); |
andcor02 | 8:bb11edbf5708 | 86 | fb.bitBlit( sScreen, 96, 96, 0, 0); |
andcor02 | 8:bb11edbf5708 | 87 | fb.bitBlit(rings[anim], 32, 32, 2, 57); |
andcor02 | 8:bb11edbf5708 | 88 | switch (elip) { |
andcor02 | 8:bb11edbf5708 | 89 | |
andcor02 | 8:bb11edbf5708 | 90 | case 0: fb.printString(lookupFontFace("Lucida 8pt", 8), |
andcor02 | 8:bb11edbf5708 | 91 | 38, |
andcor02 | 8:bb11edbf5708 | 92 | 80, |
andcor02 | 8:bb11edbf5708 | 93 | BLACK, |
andcor02 | 8:bb11edbf5708 | 94 | "Pairing"); |
andcor02 | 8:bb11edbf5708 | 95 | break; |
andcor02 | 8:bb11edbf5708 | 96 | case 1: fb.printString(lookupFontFace("Lucida 8pt", 8), |
andcor02 | 8:bb11edbf5708 | 97 | 38, |
andcor02 | 8:bb11edbf5708 | 98 | 80, |
andcor02 | 8:bb11edbf5708 | 99 | BLACK, |
andcor02 | 8:bb11edbf5708 | 100 | "Pairing.."); |
andcor02 | 8:bb11edbf5708 | 101 | break; |
andcor02 | 8:bb11edbf5708 | 102 | |
andcor02 | 8:bb11edbf5708 | 103 | case 2: fb.printString(lookupFontFace("Lucida 8pt", 8), |
andcor02 | 8:bb11edbf5708 | 104 | 38, |
andcor02 | 8:bb11edbf5708 | 105 | 80, |
andcor02 | 8:bb11edbf5708 | 106 | BLACK, |
andcor02 | 8:bb11edbf5708 | 107 | "Pairing..."); |
andcor02 | 8:bb11edbf5708 | 108 | break; |
andcor02 | 8:bb11edbf5708 | 109 | |
andcor02 | 8:bb11edbf5708 | 110 | case 3: fb.printString(lookupFontFace("Lucida 8pt", 8), |
andcor02 | 8:bb11edbf5708 | 111 | 38, |
andcor02 | 8:bb11edbf5708 | 112 | 80, |
andcor02 | 8:bb11edbf5708 | 113 | BLACK, |
andcor02 | 8:bb11edbf5708 | 114 | "Pairing..."); |
andcor02 | 8:bb11edbf5708 | 115 | break; |
andcor02 | 8:bb11edbf5708 | 116 | |
andcor02 | 8:bb11edbf5708 | 117 | |
andcor02 | 8:bb11edbf5708 | 118 | } |
andcor02 | 8:bb11edbf5708 | 119 | |
andcor02 | 8:bb11edbf5708 | 120 | |
andcor02 | 8:bb11edbf5708 | 121 | lcd.drawFrameBuffer(fb); |
andcor02 | 8:bb11edbf5708 | 122 | elip++; |
andcor02 | 8:bb11edbf5708 | 123 | anim++; |
andcor02 | 8:bb11edbf5708 | 124 | wait(0.15); |
andcor02 | 8:bb11edbf5708 | 125 | |
andcor02 | 8:bb11edbf5708 | 126 | |
andcor02 | 8:bb11edbf5708 | 127 | if (anim>=2) { |
andcor02 | 8:bb11edbf5708 | 128 | anim = 0; |
andcor02 | 8:bb11edbf5708 | 129 | } |
andcor02 | 8:bb11edbf5708 | 130 | |
andcor02 | 8:bb11edbf5708 | 131 | if (elip>=4) { |
andcor02 | 8:bb11edbf5708 | 132 | elip = 0; |
andcor02 | 8:bb11edbf5708 | 133 | } |
erigow01 | 0:9bea6067730f | 134 | } |
erigow01 | 0:9bea6067730f | 135 | |
andcor02 | 6:9ea3943e9e24 | 136 | void disconnectionCallback(Gap::Handle_t handle, Gap::DisconnectionReason_t reason) |
andcor02 | 6:9ea3943e9e24 | 137 | { |
andcor02 | 6:9ea3943e9e24 | 138 | ble.startAdvertising(); // restart advertising |
erigow01 | 0:9bea6067730f | 139 | } |
erigow01 | 0:9bea6067730f | 140 | |
andcor02 | 6:9ea3943e9e24 | 141 | void onDataWritten(const GattCharacteristicWriteCBParams *params) |
andcor02 | 6:9ea3943e9e24 | 142 | { |
andcor02 | 6:9ea3943e9e24 | 143 | uint16_t txHandle = txCharacteristic.getValueAttribute().getHandle(); |
andcor02 | 7:8712aa56ee92 | 144 | uint16_t bytesRead; |
andcor02 | 7:8712aa56ee92 | 145 | |
andcor02 | 6:9ea3943e9e24 | 146 | if (params->charHandle == txHandle) { |
andcor02 | 6:9ea3943e9e24 | 147 | memset(strn, 0, sizeof(strn)); |
andcor02 | 6:9ea3943e9e24 | 148 | ble.readCharacteristicValue(txHandle, txPayload, &bytesRead); |
andcor02 | 6:9ea3943e9e24 | 149 | strncpy(strn,(const char*)txPayload,bytesRead); |
andcor02 | 6:9ea3943e9e24 | 150 | set=1; |
andcor02 | 7:8712aa56ee92 | 151 | pc.printf ("\n\r Payload length: %d", bytesRead); |
andcor02 | 7:8712aa56ee92 | 152 | /*pc.printf("\n\r Payload: "); |
andcor02 | 7:8712aa56ee92 | 153 | for (int i=0;i<10;i++) { |
andcor02 | 7:8712aa56ee92 | 154 | pc.printf("%c", (char)txPayload[i]); |
andcor02 | 7:8712aa56ee92 | 155 | }*/ |
andcor02 | 7:8712aa56ee92 | 156 | pc.printf ("\n\r Received: %s", strn); |
erigow01 | 0:9bea6067730f | 157 | } |
erigow01 | 0:9bea6067730f | 158 | } |
erigow01 | 0:9bea6067730f | 159 | |
andcor02 | 6:9ea3943e9e24 | 160 | void bleSetup() |
andcor02 | 6:9ea3943e9e24 | 161 | { |
andcor02 | 6:9ea3943e9e24 | 162 | //Init ble |
andcor02 | 6:9ea3943e9e24 | 163 | ble.init(); |
andcor02 | 6:9ea3943e9e24 | 164 | //and handlers... |
andcor02 | 6:9ea3943e9e24 | 165 | ble.onDisconnection((Gap::DisconnectionEventCallback_t)&disconnectionCallback); |
andcor02 | 6:9ea3943e9e24 | 166 | ble.onDataWritten(onDataWritten); |
andcor02 | 6:9ea3943e9e24 | 167 | // setup advertising |
andcor02 | 6:9ea3943e9e24 | 168 | ble.accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED); |
andcor02 | 6:9ea3943e9e24 | 169 | ble.setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED); |
andcor02 | 6:9ea3943e9e24 | 170 | ble.accumulateAdvertisingPayload(GapAdvertisingData::SHORTENED_LOCAL_NAME, |
andcor02 | 7:8712aa56ee92 | 171 | (const uint8_t *)"YO!", sizeof("YO!") - 1); |
andcor02 | 6:9ea3943e9e24 | 172 | ble.accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_128BIT_SERVICE_IDS, |
andcor02 | 6:9ea3943e9e24 | 173 | (const uint8_t *)uart_base_uuid_rev, sizeof(uart_base_uuid)); |
andcor02 | 6:9ea3943e9e24 | 174 | ble.setAdvertisingInterval(160); // 100ms; in multiples of 0.625ms. |
andcor02 | 6:9ea3943e9e24 | 175 | ble.startAdvertising(); |
andcor02 | 6:9ea3943e9e24 | 176 | ble.addService(uartService); |
erigow01 | 0:9bea6067730f | 177 | } |
erigow01 | 0:9bea6067730f | 178 | |
andcor02 | 7:8712aa56ee92 | 179 | void setTime(int newTime) { |
andcor02 | 7:8712aa56ee92 | 180 | unixTime = newTime; |
andcor02 | 7:8712aa56ee92 | 181 | struct tm* timeinfo = localtime (&unixTime); |
andcor02 | 8:bb11edbf5708 | 182 | strftime (timeStr, 20, "%R", timeinfo); |
andcor02 | 8:bb11edbf5708 | 183 | strftime (dayStr, 20, "%A", timeinfo); |
andcor02 | 8:bb11edbf5708 | 184 | strftime (dateStr, 20, "%B %e", timeinfo); |
andcor02 | 7:8712aa56ee92 | 185 | } |
erigow01 | 0:9bea6067730f | 186 | |
andcor02 | 7:8712aa56ee92 | 187 | // Main LCD display function, add all framebuffer updates here ONLY |
andcor02 | 7:8712aa56ee92 | 188 | void updateLCD() { |
andcor02 | 6:9ea3943e9e24 | 189 | fb.clear(); |
andcor02 | 8:bb11edbf5708 | 190 | |
andcor02 | 8:bb11edbf5708 | 191 | //fb.bitBlit(YO, 80, 50, 0, 40); |
andcor02 | 6:9ea3943e9e24 | 192 | fb.printString(lookupFontFace("Lucida 8pt", 8), |
andcor02 | 8:bb11edbf5708 | 193 | 60, |
andcor02 | 8:bb11edbf5708 | 194 | 65, |
andcor02 | 6:9ea3943e9e24 | 195 | BLACK, |
andcor02 | 7:8712aa56ee92 | 196 | user); |
andcor02 | 7:8712aa56ee92 | 197 | |
andcor02 | 7:8712aa56ee92 | 198 | fb.printString(lookupFontFace("Lucida 8pt", 8), |
andcor02 | 8:bb11edbf5708 | 199 | 35, |
andcor02 | 8:bb11edbf5708 | 200 | 16, |
andcor02 | 7:8712aa56ee92 | 201 | BLACK, |
andcor02 | 7:8712aa56ee92 | 202 | timeStr); |
andcor02 | 8:bb11edbf5708 | 203 | |
andcor02 | 8:bb11edbf5708 | 204 | fb.printString(lookupFontFace("Lucida 8pt", 8), |
andcor02 | 8:bb11edbf5708 | 205 | 35, |
andcor02 | 8:bb11edbf5708 | 206 | 35, |
andcor02 | 8:bb11edbf5708 | 207 | BLACK, |
andcor02 | 8:bb11edbf5708 | 208 | dayStr); |
andcor02 | 7:8712aa56ee92 | 209 | |
andcor02 | 8:bb11edbf5708 | 210 | fb.printString(lookupFontFace("Lucida 8pt", 8), |
andcor02 | 8:bb11edbf5708 | 211 | 35, |
andcor02 | 8:bb11edbf5708 | 212 | 60, |
andcor02 | 8:bb11edbf5708 | 213 | BLACK, |
andcor02 | 8:bb11edbf5708 | 214 | dateStr); |
andcor02 | 8:bb11edbf5708 | 215 | |
andcor02 | 6:9ea3943e9e24 | 216 | lcd.drawFrameBuffer(fb); |
andcor02 | 7:8712aa56ee92 | 217 | } |
andcor02 | 7:8712aa56ee92 | 218 | |
andcor02 | 7:8712aa56ee92 | 219 | int main(void) { |
andcor02 | 7:8712aa56ee92 | 220 | |
andcor02 | 7:8712aa56ee92 | 221 | screenSetup(); |
andcor02 | 7:8712aa56ee92 | 222 | bleSetup(); |
andcor02 | 7:8712aa56ee92 | 223 | |
andcor02 | 7:8712aa56ee92 | 224 | led1 = 0; |
andcor02 | 7:8712aa56ee92 | 225 | set2 = 0; |
andcor02 | 8:bb11edbf5708 | 226 | |
andcor02 | 7:8712aa56ee92 | 227 | uint16_t rxHandle = rxCharacteristic.getValueAttribute().getHandle(); |
andcor02 | 7:8712aa56ee92 | 228 | |
andcor02 | 7:8712aa56ee92 | 229 | // Initial time update |
andcor02 | 7:8712aa56ee92 | 230 | pc.printf("\n\r Updating time"); |
andcor02 | 7:8712aa56ee92 | 231 | char cmd[5] = "time"; |
andcor02 | 7:8712aa56ee92 | 232 | ble.updateCharacteristicValue(rxHandle, (const uint8_t*)cmd, 4); |
andcor02 | 8:bb11edbf5708 | 233 | |
andcor02 | 8:bb11edbf5708 | 234 | while (true) { |
andcor02 | 8:bb11edbf5708 | 235 | |
andcor02 | 8:bb11edbf5708 | 236 | if (pairing){ |
andcor02 | 8:bb11edbf5708 | 237 | showPairing(); |
andcor02 | 8:bb11edbf5708 | 238 | } |
andcor02 | 6:9ea3943e9e24 | 239 | |
andcor02 | 7:8712aa56ee92 | 240 | if(set){ |
andcor02 | 7:8712aa56ee92 | 241 | if (timeUpdate) { |
andcor02 | 7:8712aa56ee92 | 242 | setTime(atoi(strn)); |
andcor02 | 7:8712aa56ee92 | 243 | pc.printf("\n\r New time: %s", timeStr); |
andcor02 | 7:8712aa56ee92 | 244 | timeUpdate = 0; |
andcor02 | 8:bb11edbf5708 | 245 | pairing=0; |
andcor02 | 7:8712aa56ee92 | 246 | mClock.start(); |
andcor02 | 7:8712aa56ee92 | 247 | } else { |
andcor02 | 7:8712aa56ee92 | 248 | strncpy(user, strn, sizeof(strn)); |
andcor02 | 7:8712aa56ee92 | 249 | } |
andcor02 | 7:8712aa56ee92 | 250 | set = 0; |
andcor02 | 7:8712aa56ee92 | 251 | } |
andcor02 | 7:8712aa56ee92 | 252 | |
andcor02 | 7:8712aa56ee92 | 253 | if(!button && !set2){ |
andcor02 | 7:8712aa56ee92 | 254 | set2 = 1; |
andcor02 | 7:8712aa56ee92 | 255 | uint16_t bytesToSend = strlen(user); |
andcor02 | 7:8712aa56ee92 | 256 | memcpy(rxPayload, user, bytesToSend); |
andcor02 | 7:8712aa56ee92 | 257 | ble.updateCharacteristicValue(rxHandle, rxPayload, bytesToSend); |
andcor02 | 7:8712aa56ee92 | 258 | pc.printf ("\n\r Sending %s", user); |
andcor02 | 7:8712aa56ee92 | 259 | } else if (button){ |
andcor02 | 7:8712aa56ee92 | 260 | set2 = 0; |
andcor02 | 7:8712aa56ee92 | 261 | } |
andcor02 | 7:8712aa56ee92 | 262 | |
andcor02 | 7:8712aa56ee92 | 263 | clockOffset = mClock.read_ms(); |
andcor02 | 7:8712aa56ee92 | 264 | if (clockOffset >= 1000) { |
andcor02 | 7:8712aa56ee92 | 265 | clockOffset += lastms; |
andcor02 | 7:8712aa56ee92 | 266 | int addTime = unixTime + (clockOffset/1000); |
andcor02 | 7:8712aa56ee92 | 267 | lastms = clockOffset%1000; // e.g. 2564 - 2000 = 564 |
andcor02 | 7:8712aa56ee92 | 268 | mClock.reset(); |
andcor02 | 7:8712aa56ee92 | 269 | setTime(addTime); |
andcor02 | 7:8712aa56ee92 | 270 | |
andcor02 | 7:8712aa56ee92 | 271 | // do all the framebuffer updating here every second |
andcor02 | 7:8712aa56ee92 | 272 | updateLCD(); |
andcor02 | 7:8712aa56ee92 | 273 | } |
andcor02 | 6:9ea3943e9e24 | 274 | } |
erigow01 | 0:9bea6067730f | 275 | } |