diff --git a/Documentation/bluetooth/card10.rst b/Documentation/bluetooth/card10.rst index f38bb9195441a97730e04f00afe459773b74bb03..d611b616f8c843268090f711aa7940c933cfdeb3 100644 --- a/Documentation/bluetooth/card10.rst +++ b/Documentation/bluetooth/card10.rst @@ -60,14 +60,19 @@ The current draft uses following service specification: UUID: ``42230216-2342-2342-2342-234223422342`` write -- LEDs above characteristic: +- LEDs powersafe characteristic: - UUID: ``42230220-2342-2342-2342-234223422342`` + UUID: ``42230217-2342-2342-2342-234223422342`` + write + +- flashlight characteristic: + + UUID: ``42230218-2342-2342-2342-234223422342`` write -- Single rgb led characteristic: +- LEDs above characteristic: - UUID: ``422302ef-2342-2342-2342-234223422342`` + UUID: ``42230220-2342-2342-2342-234223422342`` write - Light sensor characteristic: @@ -129,26 +134,28 @@ LEDs dim <Position> characteristic The LEDs dim <Position> characteristic makes it possible to dim LEDs by position. Just write a ``uint8`` between ``1`` and ``8``. -LEDs above characteristic +LEDs powersafe characteristic --------------------------------- -This characteristic set every 11 leds on the top module at once. -Single rgb led characteristic ---------------------------------- +This characteristic makes it possible to set the LEDs in powersafe mode. +Even when set to zero, the RGB LEDs still individually consume ~1mA. +Powersave intelligently switches the supply power in groups. +This introduces delays in the magnitude of ~10µs, so it can be disabled for high speed applications such as POV -This characteristic makes it possible to address every single rgb led. -Just write a byte array ``uint18`` address of led and three ``uint8`` for the rgb color. +- enabled: ``0x01`` +- disabled: ``0x00`` -Dataformat: +Flashlight characteristic +--------------------------------- -====== ===== ===== ===== - 0-1 2 3 4 ------- ----- ----- ----- -led nr red green blue +This characteristic makes it possible to activate the flashlight. -- set led 14 red: ``0x0e00ff0000`` -- set led 14 blue: ``0x0e000000ff`` -- disable led 14: ``0x0e00000000`` +- enabled: ``0x01`` +- disabled: ``0x00`` + +LEDs above characteristic +--------------------------------- +This characteristic set every 11 leds on the top module at once. Light sensor characteristic --------------------------------- diff --git a/epicardium/ble/ble.c b/epicardium/ble/ble.c index ad9f9296a1b19b6c001200e0c6812066e4019d86..eeef8df781af059f18ae9f71c20c6ed08fac7821 100644 --- a/epicardium/ble/ble.c +++ b/epicardium/ble/ble.c @@ -46,8 +46,8 @@ static int lasttick = 0; extern void StackInit(void); extern void AppInit(void); extern void bleuart_init(void); -extern void bleCard10_init(void); extern void bleFileTransfer_init(void); +extern void bleCard10_init(void); /*************************************************************************************************/ void PalSysAssertTrap(void) @@ -205,8 +205,8 @@ void vBleTask(void *pvParameters) AttsDynInit(); bleuart_init(); - bleCard10_init(); bleFileTransfer_init(); + bleCard10_init(); lasttick = xTaskGetTickCount(); diff --git a/epicardium/ble/card10.c b/epicardium/ble/card10.c index cc08dec7686d36b0f52aebe05ba08156738819ec..e7aa58fabe98d6fc78474223b008562e8fbc63ea 100644 --- a/epicardium/ble/card10.c +++ b/epicardium/ble/card10.c @@ -65,12 +65,15 @@ enum { /*!< \brief dim leds on top characteristic */ CARD10_LEDS_TOP_DIM_CH_HDL, CARD10_LEDS_TOP_DIM_VAL_HDL, + /*!< \brief led powersafe characteristic */ + CARD10_LED_POWERSAFE_CH_HDL, + CARD10_LED_POWERSAFE_VAL_HDL, + /*!< \brief flashlight characteristic */ + CARD10_FLASHLIGHT_CH_HDL, + CARD10_FLASHLIGHT_VAL_HDL, /*!< \brief leds above characteristic */ CARD10_LEDS_ABOVE_CH_HDL, CARD10_LEDS_ABOVE_VAL_HDL, - /*!< \brief single led characteristic */ - CARD10_LED_S_CH_HDL, - CARD10_LED_S_VAL_HDL, /*!< \brief light sensor characteristic */ CARD10_LIGHT_SENSOR_CH_HDL, CARD10_LIGHT_SENSOR_VAL_HDL, @@ -188,6 +191,28 @@ static const uint8_t UUID_attChar_leds_top_dim[] = { CARD10_UUID_SUFFIX, 0x16, CARD10_UUID_PREFIX }; +/* BLE UUID for card10 powersafe */ +static const uint8_t UUID_char_led_powersafe[] = { + ATT_PROP_WRITE, + UINT16_TO_BYTES(CARD10_LED_POWERSAFE_VAL_HDL), + CARD10_UUID_SUFFIX, 0x17, CARD10_UUID_PREFIX +}; + +static const uint8_t UUID_attChar_led_powersafe[] = { + CARD10_UUID_SUFFIX, 0x17, CARD10_UUID_PREFIX +}; + +/* BLE UUID for card10 flashlight */ +static const uint8_t UUID_char_flashlight[] = { + ATT_PROP_WRITE, + UINT16_TO_BYTES(CARD10_FLASHLIGHT_VAL_HDL), + CARD10_UUID_SUFFIX, 0x18, CARD10_UUID_PREFIX +}; + +static const uint8_t UUID_attChar_flashlight[] = { + CARD10_UUID_SUFFIX, 0x18, CARD10_UUID_PREFIX +}; + /* BLE UUID for card10 above leds */ static const uint8_t UUID_char_leds_above[] = { ATT_PROP_WRITE, @@ -198,17 +223,6 @@ static const uint8_t UUID_char_leds_above[] = { static const uint8_t UUID_attChar_leds_above[] = { CARD10_UUID_SUFFIX, 0x20, CARD10_UUID_PREFIX }; - -/* BLE UUID for card10 char led single (debugging) */ -static const uint8_t UUID_char_led_s[] = { - ATT_PROP_WRITE, - UINT16_TO_BYTES(CARD10_LED_S_VAL_HDL), - CARD10_UUID_SUFFIX, 0xef, CARD10_UUID_PREFIX -}; - -static const uint8_t UUID_attChar_led_s[] = { - CARD10_UUID_SUFFIX, 0xef, CARD10_UUID_PREFIX -}; // starting at 0xf0 with read only characteristics /* BLE UUID for card10 char light sensor */ @@ -433,44 +447,65 @@ static void *addCard10GroupDyn(void) ATTS_PERMIT_WRITE | ATTS_PERMIT_WRITE_ENC | ATTS_PERMIT_WRITE_AUTH); - // ABOVE LEDS + // led powersafe AttsDynAddAttrConst( pSHdl, attChUuid, - UUID_char_leds_above, - sizeof(UUID_char_leds_above), + UUID_char_led_powersafe, + sizeof(UUID_char_led_powersafe), 0, ATTS_PERMIT_READ ); AttsDynAddAttr( pSHdl, - UUID_attChar_leds_above, + UUID_attChar_led_powersafe, NULL, 0, - 11 * 3 * sizeof(uint8_t), + sizeof(uint8_t), + ATTS_SET_WRITE_CBACK, + ATTS_PERMIT_WRITE | ATTS_PERMIT_WRITE_ENC | + ATTS_PERMIT_WRITE_AUTH); + + // flashlight + + AttsDynAddAttrConst( + pSHdl, + attChUuid, + UUID_char_flashlight, + sizeof(UUID_char_flashlight), + 0, + ATTS_PERMIT_READ + ); + + AttsDynAddAttr( + pSHdl, + UUID_attChar_flashlight, + NULL, + 0, + sizeof(uint8_t), ATTS_SET_WRITE_CBACK, ATTS_PERMIT_WRITE | ATTS_PERMIT_WRITE_ENC | ATTS_PERMIT_WRITE_AUTH); - // SINGLE LED + // ABOVE LEDS AttsDynAddAttrConst( pSHdl, attChUuid, - UUID_char_led_s, - sizeof(UUID_char_led_s), + UUID_char_leds_above, + sizeof(UUID_char_leds_above), 0, ATTS_PERMIT_READ ); AttsDynAddAttr( pSHdl, - UUID_attChar_led_s, + UUID_attChar_leds_above, NULL, 0, - sizeof(uint16_t) + 3 * sizeof(uint8_t), + 11 * 3 * sizeof(uint8_t), ATTS_SET_WRITE_CBACK, ATTS_PERMIT_WRITE | ATTS_PERMIT_WRITE_ENC | ATTS_PERMIT_WRITE_AUTH); @@ -611,6 +646,16 @@ static uint8_t writeCard10CB( } APP_TRACE_INFO1("dim top invalid value (1-8): %d\n", ui8); return ATT_ERR_RANGE; + // led powersafe + case CARD10_LED_POWERSAFE_VAL_HDL: + epic_leds_set_powersave(pValue[0]); + APP_TRACE_INFO1("set powersafe to: %d\n", pValue[0]); + return ATT_SUCCESS; + // flashlight + case CARD10_FLASHLIGHT_VAL_HDL: + epic_set_flashlight(pValue[0]); + APP_TRACE_INFO1("set flashlight to: %d\n", pValue[0]); + return ATT_SUCCESS; // leds above case CARD10_LEDS_ABOVE_VAL_HDL: for (ui16 = 0; ui16 < 11; ui16++) { @@ -628,18 +673,6 @@ static uint8_t writeCard10CB( pValue[ui16 * 3 + 2] ); } - // single led - case CARD10_LED_S_VAL_HDL: - BYTES_TO_UINT16(ui16, pValue); - epic_leds_set(ui16, pValue[2], pValue[3], pValue[4]); - APP_TRACE_INFO4( - "ble-card10: set single led %ld to #%02x%02x%02x\n", - ui16, - pValue[2], - pValue[3], - pValue[4] - ); - return ATT_SUCCESS; default: APP_TRACE_INFO1( "ble-card10: unsupported characteristic: %c\n", handle