From 0f600f98260151193d2e882c15ce477df16038d2 Mon Sep 17 00:00:00 2001 From: Martin/Geno <geno+dev@fireorbit.de> Date: Fri, 23 Aug 2019 18:03:55 +0200 Subject: [PATCH] read state of rockets - with ble support --- epicardium/ble/card10.c | 24 ++++++++++++++++++++---- epicardium/epicardium.h | 19 +++++++++++++++++++ epicardium/modules/leds.c | 4 ++++ lib/card10/pmic.c | 13 ++++++++++++- lib/card10/pmic.h | 1 + 5 files changed, 56 insertions(+), 5 deletions(-) diff --git a/epicardium/ble/card10.c b/epicardium/ble/card10.c index 2105ac02..dd88134e 100644 --- a/epicardium/ble/card10.c +++ b/epicardium/ble/card10.c @@ -114,7 +114,7 @@ static const uint8_t UUID_attChar_vibra[] = { /* BLE UUID for card10 char rockets */ static const uint8_t UUID_char_rockets[] = { - ATT_PROP_WRITE_NO_RSP, + ATT_PROP_READ | ATT_PROP_WRITE_NO_RSP, UINT16_TO_BYTES(CARD10_ROCKETS_VAL_HDL), CARD10_UUID_SUFFIX, 0x10, CARD10_UUID_PREFIX }; @@ -123,6 +123,9 @@ static const uint8_t UUID_attChar_rockets[] = { CARD10_UUID_SUFFIX, 0x10, CARD10_UUID_PREFIX }; +static uint8_t rocketsValue[] = { 0, 0, 0 }; +static uint16_t rocketsLen = sizeof(rocketsValue); + /* BLE UUID for card10 led background bottom left */ static const uint8_t UUID_char_led_bg_bottom_left[] = { ATT_PROP_WRITE_NO_RSP, @@ -302,12 +305,14 @@ static const attsAttr_t card10SvcAttrList[] = { .maxLen = sizeof(UUID_char_rockets), .permissions = ATTS_PERMIT_READ }, { .pUuid = UUID_attChar_rockets, - .pValue = NULL, + .pValue = rocketsValue, + .pLen = &rocketsLen, .maxLen = 3 * sizeof(uint8_t), - .settings = ATTS_SET_WRITE_CBACK, + .settings = (ATTS_SET_WRITE_CBACK | ATTS_SET_READ_CBACK), .permissions = (ATTS_PERMIT_WRITE | ATTS_PERMIT_WRITE_ENC | - ATTS_PERMIT_WRITE_AUTH) }, + ATTS_PERMIT_WRITE_AUTH | ATTS_PERMIT_READ | + ATTS_PERMIT_READ_ENC | ATTS_PERMIT_READ_AUTH) }, // BG LED Bottom left @@ -736,6 +741,17 @@ static uint8_t readCard10CB( APP_TRACE_INFO0("ble-card10: read time\n"); return ATT_SUCCESS; + case CARD10_ROCKETS_VAL_HDL: + pAttr->pValue[0] = epic_leds_get_rocket(0); + pAttr->pValue[1] = epic_leds_get_rocket(1); + pAttr->pValue[2] = epic_leds_get_rocket(2); + APP_TRACE_INFO3( + "ble-card10: get rockets 0:%d, 1:%d, 2:%d\n", + pAttr->pValue[0], + pAttr->pValue[1], + pAttr->pValue[2] + ); + return ATT_SUCCESS; case CARD10_PERSONAL_STATE_VAL_HDL: ui16 = epic_personal_state_get(); *pAttr->pValue = ui16; diff --git a/epicardium/epicardium.h b/epicardium/epicardium.h index 52c02b9f..34c809c9 100644 --- a/epicardium/epicardium.h +++ b/epicardium/epicardium.h @@ -95,6 +95,7 @@ typedef _Bool bool; #define API_LEDS_SET_ALL_HSV 0x6b #define API_LEDS_SET_GAMMA_TABLE 0x6c #define API_LEDS_CLEAR_ALL 0x6d +#define API_LEDS_GET_ROCKET 0x6e #define API_VIBRA_SET 0x70 #define API_VIBRA_VIBRATE 0x71 @@ -706,6 +707,24 @@ API(API_LEDS_UPDATE, void epic_leds_update(void)); */ API(API_LEDS_SET_ROCKET, void epic_leds_set_rocket(int led, uint8_t value)); +/** + * Get the brightness of one of the rocket LEDs. + * + * :param int led: Which LED to get. + * + * +-------+--------+----------+ + * | ID | Color | Location | + * +=======+========+==========+ + * | ``0`` | Blue | Left | + * +-------+--------+----------+ + * | ``1`` | Yellow | Top | + * +-------+--------+----------+ + * | ``2`` | Green | Right | + * +-------+--------+----------+ + * :return uint8_t value: Brightness of LED (value between 0 and 31). + */ +API(API_LEDS_GET_ROCKET, uint8_t epic_leds_get_rocket(int led)); + /** * Turn on the bright side LED which can serve as a flashlight if worn on the left wrist or as a rad tattoo illuminator if worn on the right wrist. * diff --git a/epicardium/modules/leds.c b/epicardium/modules/leds.c index 93b80a99..c4e2ef7b 100644 --- a/epicardium/modules/leds.c +++ b/epicardium/modules/leds.c @@ -100,6 +100,10 @@ void epic_leds_set_rocket(int led, uint8_t value) value = value > 31 ? 31 : value; pmic_set_led(led, value); } +uint8_t epic_leds_get_rocket(int led) +{ + pmic_get_led(led); +} void epic_set_flashlight(bool power) { diff --git a/lib/card10/pmic.c b/lib/card10/pmic.c index 5927ff55..081b32eb 100644 --- a/lib/card10/pmic.c +++ b/lib/card10/pmic.c @@ -122,7 +122,18 @@ void pmic_set_button_callback(pmic_button_callback_fn cb) { pmic_button_callback = cb; } - +uint8_t pmic_get_led(uint8_t led) +{ + if (led == 0) { + return MAX77650_getBRT_LED0(); + } + if (led == 1) { + return MAX77650_getBRT_LED1(); + } + if (led == 2) { + return MAX77650_getBRT_LED2(); + } +} void pmic_set_led(uint8_t led, uint8_t val) { if (led == 0) { diff --git a/lib/card10/pmic.h b/lib/card10/pmic.h index f913c99b..a3a61d46 100644 --- a/lib/card10/pmic.h +++ b/lib/card10/pmic.h @@ -21,6 +21,7 @@ void pmic_init(void); void pmic_set_led(uint8_t led, uint8_t val); +uint8_t pmic_get_led(uint8_t led); void pmic_poll(void); /* weak, so it can be overwritten by applications */ -- GitLab