From d2a91e9302731a1c4fc2a24a592fd393a5389a94 Mon Sep 17 00:00:00 2001 From: Martin/Geno <geno+dev@fireorbit.de> Date: Mon, 26 Aug 2019 10:21:16 +0200 Subject: [PATCH] ble: card10 svc - put bg leds into function --- epicardium/ble/card10.c | 104 ++++++++++++++++------------------------ 1 file changed, 40 insertions(+), 64 deletions(-) diff --git a/epicardium/ble/card10.c b/epicardium/ble/card10.c index 27231114..2378244a 100644 --- a/epicardium/ble/card10.c +++ b/epicardium/ble/card10.c @@ -533,6 +533,38 @@ static uint8_t setTime(uint8_t *pValue) return ATT_SUCCESS; } +/* + * Set a rgb led + */ +static uint8_t setRGBLed(uint8_t led, uint8_t *pValue) +{ + epic_leds_set(led, pValue[0], pValue[1], pValue[2]); + APP_TRACE_INFO4( + "ble-card10: set rgb led %d: #%02x%02x%02x\n", + led, + pValue[0], + pValue[1], + pValue[2] + ); + return ATT_SUCCESS; +} + +/* + * Get value of a rgb led + */ +static uint8_t getRGBLed(uint8_t led, attsAttr_t *pAttr) +{ + epic_leds_get_rgb(led, pAttr->pValue); + APP_TRACE_INFO4( + "ble-card10: set rgb led %d: #%02x%02x%02x\n", + led, + pAttr->pValue[0], + pAttr->pValue[1], + pAttr->pValue[2] + ); + return ATT_SUCCESS; +} + /* * BLE card10 write callback. */ @@ -573,41 +605,13 @@ static uint8_t writeCard10CB( return ATT_SUCCESS; // bg leds case CARD10_LED_BG_BOTTOM_LEFT_VAL_HDL: - epic_leds_set(11, pValue[0], pValue[1], pValue[2]); - APP_TRACE_INFO3( - "ble-card10: set bg bottom left: #%02x%02x%02x\n", - pValue[0], - pValue[1], - pValue[2] - ); - return ATT_SUCCESS; + return setRGBLed(11, pValue); case CARD10_LED_BG_BOTTOM_RIGHT_VAL_HDL: - epic_leds_set(12, pValue[0], pValue[1], pValue[2]); - APP_TRACE_INFO3( - "ble-card10: set bg bottom right: #%02x%02x%02x\n", - pValue[0], - pValue[1], - pValue[2] - ); - return ATT_SUCCESS; + return setRGBLed(12, pValue); case CARD10_LED_BG_TOP_RIGHT_VAL_HDL: - epic_leds_set(13, pValue[0], pValue[1], pValue[2]); - APP_TRACE_INFO3( - "ble-card10: set bg top right: #%02x%02x%02x\n", - pValue[0], - pValue[1], - pValue[2] - ); - return ATT_SUCCESS; + return setRGBLed(13, pValue); case CARD10_LED_BG_TOP_LEFT_VAL_HDL: - epic_leds_set(14, pValue[0], pValue[1], pValue[2]); - APP_TRACE_INFO3( - "ble-card10: set bg top left: #%02x%02x%02x\n", - pValue[0], - pValue[1], - pValue[2] - ); - return ATT_SUCCESS; + return setRGBLed(14, pValue); // dim case CARD10_LEDS_BOTTOM_DIM_VAL_HDL: ui8 = pValue[0]; @@ -773,41 +777,13 @@ static uint8_t readCard10CB( return ATT_SUCCESS; // background leds case CARD10_LED_BG_BOTTOM_LEFT_VAL_HDL: - epic_leds_get_rgb(11, pAttr->pValue); - APP_TRACE_INFO3( - "ble-card10: set bg bottom left: #%02x%02x%02x\n", - pAttr->pValue[0], - pAttr->pValue[1], - pAttr->pValue[2] - ); - return ATT_SUCCESS; + return getRGBLed(11, pAttr); case CARD10_LED_BG_BOTTOM_RIGHT_VAL_HDL: - epic_leds_get_rgb(12, pAttr->pValue); - APP_TRACE_INFO3( - "ble-card10: get bg bottom right: #%02x%02x%02x\n", - pAttr->pValue[0], - pAttr->pValue[1], - pAttr->pValue[2] - ); - return ATT_SUCCESS; + return getRGBLed(12, pAttr); case CARD10_LED_BG_TOP_RIGHT_VAL_HDL: - epic_leds_get_rgb(13, pAttr->pValue); - APP_TRACE_INFO3( - "ble-card10: get bg top right: #%02x%02x%02x\n", - pAttr->pValue[0], - pAttr->pValue[1], - pAttr->pValue[2] - ); - return ATT_SUCCESS; + return getRGBLed(13, pAttr); case CARD10_LED_BG_TOP_LEFT_VAL_HDL: - epic_leds_get_rgb(14, pAttr->pValue); - APP_TRACE_INFO3( - "ble-card10: get bg top left: #%02x%02x%02x\n", - pAttr->pValue[0], - pAttr->pValue[1], - pAttr->pValue[2] - ); - return ATT_SUCCESS; + return getRGBLed(14, pAttr); // personal state case CARD10_PERSONAL_STATE_VAL_HDL: ui16 = epic_personal_state_get(); -- GitLab