diff options
Diffstat (limited to 'source/controller.cpp')
-rwxr-xr-x | source/controller.cpp | 133 |
1 files changed, 36 insertions, 97 deletions
diff --git a/source/controller.cpp b/source/controller.cpp index c4ea12c..bd316b5 100755 --- a/source/controller.cpp +++ b/source/controller.cpp @@ -1,115 +1,54 @@ -/********************************************************************* - This is an example for our nRF52 based Bluefruit LE modules - - Pick one up today in the adafruit shop! - - Adafruit invests time and resources providing this open source code, - please support Adafruit and open-source hardware by purchasing - products from Adafruit! - - MIT license, check LICENSE for more information - All text above, and the splash screen below must be included in - any redistribution -*********************************************************************/ - // sharp takes < ~0.05uA #include <bluefruit.h> -#include <cmath> #include "driverSharp.h" +#include "rtc.hpp" BLEUart bleuart; -// Function prototypes for packetparser.cpp -uint8_t readPacket (BLEUart *ble_uart, uint16_t timeout); -float parsefloat (uint8_t *buffer); -void printHex (const uint8_t * data, const uint32_t numBytes); - -// Packet buffer -extern uint8_t packetbuffer[]; - -void startAdv(void); - -void setup(void) +void app_error_handler_bare([[maybe_unused]] uint32_t error_code) { - Serial.begin(115200); - while ( !Serial ) delay(10); // for nrf52840 with native usb - - Serial.println(F("Initializing...")); - - sharpInit(); - - Bluefruit.begin(); - // Set max power. Accepted values are: -40, -30, -20, -16, -12, -8, -4, 0, 4 - Bluefruit.setTxPower(-20);//4); - Bluefruit.setName("Bluefruit52"); - - // Configure and start the BLE Uart service - bleuart.begin(); - - // Set up and start advertising - startAdv(); - - Serial.println(F("Ready.")); + Serial.println("Received an error"); + while (1); } -void startAdv(void) +void setup(void) { - // Advertising packet - Bluefruit.Advertising.addFlags(BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE); - Bluefruit.Advertising.addTxPower(); - - // Include the BLE UART (AKA 'NUS') 128-bit UUID - Bluefruit.Advertising.addService(bleuart); - - // Secondary Scan Response packet (optional) - // Since there is no room for 'Name' in Advertising packet - Bluefruit.ScanResponse.addName(); - - /* Start Advertising - * - Enable auto advertising if disconnected - * - Interval: fast mode = 20 ms, slow mode = 152.5 ms - * - Timeout for fast mode is 30 seconds - * - Start(timeout) with timeout = 0 will advertise forever (until connected) - * - * For recommended advertising interval - * https://developer.apple.com/library/content/qa/qa1931/_index.html - */ - Bluefruit.Advertising.restartOnDisconnect(true); - Bluefruit.Advertising.setInterval(32, 244); // in unit of 0.625 ms - Bluefruit.Advertising.setFastTimeout(30); // number of seconds in fast mode - Bluefruit.Advertising.start(0); // 0 = Don't stop advertising after n seconds + Serial.begin(115200); + while (!Serial) + delay(10); + + Serial.println(F("Initializing...")); + + RTC::begin(); + Sharp::begin(); + + Bluefruit.begin(); + // Accepted values are: -40, -30, -20, -16, -12, -8, -4, 0, 4 + Bluefruit.setTxPower(-20); + Bluefruit.setName("smartwatch"); + + // Configure and start the BLE Uart service + bleuart.begin(); + + // Advertising packet + Bluefruit.Advertising.addFlags(BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE); + Bluefruit.Advertising.addTxPower(); + Bluefruit.Advertising.addService(bleuart); + Bluefruit.ScanResponse.addName(); + Bluefruit.Advertising.restartOnDisconnect(true); + Bluefruit.Advertising.setInterval(32, 244); // in unit of 0.625 ms + Bluefruit.Advertising.setFastTimeout(30); // number of seconds in fast mode + Bluefruit.Advertising.start(0); // 0 = Don't stop advertising after n seconds + + Serial.println(F("Ready.")); } -/**************************************************************************/ -/*! - @brief Constantly poll for new command or response data -*/ -/**************************************************************************/ void loop(void) { - //static unsigned int i = 0; - //auto y = 8.7L * std::sin(i++ / -0.5L); - //bleuart.print(i); - //bleuart.print(','); - //bleuart.println((int)y); - //delay(900); - // Wait for new data to arrive - - uint8_t len = readPacket(&bleuart, 500); - if (len == 0) return; - - // Buttons - if (packetbuffer[1] == 'B') { - uint8_t buttnum = packetbuffer[2] - '0'; - boolean pressed = packetbuffer[3] - '0'; - Serial.print ("Button "); Serial.print(buttnum); - if (pressed) { - Serial.println(" pressed"); - } else { - Serial.println(" released"); - } - } + if (bleuart.available()) + Serial.print((char)bleuart.read()); + delay(10); } |