From e6812abe3aa8c1792727738d2843a52726737d8e Mon Sep 17 00:00:00 2001 From: hathach Date: Fri, 4 Jun 2021 14:18:08 +0700 Subject: [PATCH] raytac dongle only has 1 led populated --- boards.txt | 4 +-- .../Peripheral/nrf_blinky/nrf_blinky.ino | 29 ++++++++++++++----- variants/raytac_mdbt50q_rx/variant.h | 6 ++-- 3 files changed, 26 insertions(+), 13 deletions(-) diff --git a/boards.txt b/boards.txt index a581bd5f..0eea1c9d 100644 --- a/boards.txt +++ b/boards.txt @@ -525,8 +525,8 @@ mdbt50qrx.build.f_cpu=64000000 mdbt50qrx.build.board=MDBT50Q_RX mdbt50qrx.build.core=nRF5 mdbt50qrx.build.variant=raytac_mdbt50q_rx -mdbt50qrx.build.usb_manufacturer="Raytac Corporation" -mdbt50qrx.build.usb_product="Raytac MDBT50Q - RX" +mdbt50qrx.build.usb_manufacturer="Raytac" +mdbt50qrx.build.usb_product="nRF52840 Dongle" mdbt50qrx.build.extra_flags=-DNRF52840_XXAA {build.flags.usb} mdbt50qrx.build.ldscript=nrf52840_s140_v6.ld mdbt50qrx.build.vid=0x239A diff --git a/libraries/Bluefruit52Lib/examples/Peripheral/nrf_blinky/nrf_blinky.ino b/libraries/Bluefruit52Lib/examples/Peripheral/nrf_blinky/nrf_blinky.ino index a7fc2559..40e2630a 100644 --- a/libraries/Bluefruit52Lib/examples/Peripheral/nrf_blinky/nrf_blinky.ino +++ b/libraries/Bluefruit52Lib/examples/Peripheral/nrf_blinky/nrf_blinky.ino @@ -130,7 +130,7 @@ void setup() lsbLED.setPermission(SECMODE_OPEN, SECMODE_OPEN); lsbLED.setFixedLen(1); lsbLED.begin(); - lsbLED.write8(0x00); // led = off + lsbLED.write8(0x01); // led = on when connected lsbLED.setWriteCallback(led_write_callback); @@ -167,6 +167,19 @@ void startAdv(void) Bluefruit.Advertising.start(0); // 0 = Don't stop advertising after n seconds } +void setLED(bool on) +{ + // data = 1 -> LED = On + // data = 0 -> LED = Off + digitalWrite(LED_BUILTIN, on ? LED_STATE_ON : (1-LED_STATE_ON)); + +#ifdef PIN_NEOPIXEL + uint32_t c = neopixel.Color(0x00, 0x00, on ? 0x20 : 0x00); + neopixel.fill(c, 0, NEOPIXEL_NUM); + neopixel.show(); +#endif +} + void led_write_callback(uint16_t conn_hdl, BLECharacteristic* chr, uint8_t* data, uint16_t len) { (void) conn_hdl; @@ -175,13 +188,7 @@ void led_write_callback(uint16_t conn_hdl, BLECharacteristic* chr, uint8_t* data // data = 1 -> LED = On // data = 0 -> LED = Off - digitalWrite(LED_BUILTIN, data[0] ? LED_STATE_ON : (1-LED_STATE_ON)); - -#ifdef PIN_NEOPIXEL - uint32_t c = neopixel.Color(0x00, 0x00, data[0] ? 0x20 : 0x00); - neopixel.fill(c, 0, NEOPIXEL_NUM); - neopixel.show(); -#endif + setLED(data[0]); } void loop() @@ -212,6 +219,9 @@ void connect_callback(uint16_t conn_handle) { (void) conn_handle; + setLED(true); + lsbLED.write8(0x01); + connection_count++; Serial.print("Connection count: "); Serial.println(connection_count); @@ -234,6 +244,9 @@ void disconnect_callback(uint16_t conn_handle, uint8_t reason) (void) conn_handle; (void) reason; + setLED(false); + lsbLED.write8(0x00); + Serial.println(); Serial.print("Disconnected, reason = 0x"); Serial.println(reason, HEX); diff --git a/variants/raytac_mdbt50q_rx/variant.h b/variants/raytac_mdbt50q_rx/variant.h index 0ee7fd1b..5a04257e 100644 --- a/variants/raytac_mdbt50q_rx/variant.h +++ b/variants/raytac_mdbt50q_rx/variant.h @@ -44,13 +44,13 @@ extern "C" // LEDs #define PIN_LED1 (0) -#define PIN_LED2 (1) +#define PIN_LED2 (1) // LED2 is not populated by default #define LED_BUILTIN PIN_LED1 -#define LED_CONN PIN_LED2 +#define LED_CONN PIN_LED1 #define LED_RED PIN_LED1 -#define LED_BLUE PIN_LED2 +#define LED_BLUE PIN_LED1 #define LED_STATE_ON 0 // State when LED is litted