Commit 5663fd18 authored by Rahix's avatar Rahix
Browse files

Merge 'read state of rockets'

See merge request card10/firmware!227
parents 63926052 4893edd6
...@@ -28,7 +28,7 @@ The current draft uses following service specification: ...@@ -28,7 +28,7 @@ The current draft uses following service specification:
- Rockets characteristic: - Rockets characteristic:
UUID: ``42230210-2342-2342-2342-234223422342`` UUID: ``42230210-2342-2342-2342-234223422342``
write no response read and write no response
- Background LED Bottom Left characteristic: - Background LED Bottom Left characteristic:
...@@ -104,6 +104,9 @@ Rockets characteristic ...@@ -104,6 +104,9 @@ Rockets characteristic
The Rockets characteristic makes it possible to address every three rockets. The Rockets characteristic makes it possible to address every three rockets.
Just write there three byte array, one for evey rocket. Just write there three byte array, one for evey rocket.
On read you get the current value of all three rockets.
Range is between 0 and 31 (``0x1f`) if send higher value it will set to max of 31.
Dataformat: Dataformat:
...@@ -113,8 +116,8 @@ Dataformat: ...@@ -113,8 +116,8 @@ Dataformat:
Rocket0 Rocket1 Rocket2 Rocket0 Rocket1 Rocket2
======= ======= ======= ======= ======= =======
- Enable only Rocket0: ``0xff0000`` - Enable only Rocket0: ``0x1f0000``
- Enable all rockets with 50% brightness: ``0x7f7f7f`` - Enable all rockets with 50% brightness: ``0x0f0f0f``
Background LED <Position> characteristic Background LED <Position> characteristic
---------------------------------------- ----------------------------------------
......
...@@ -114,7 +114,7 @@ static const uint8_t UUID_attChar_vibra[] = { ...@@ -114,7 +114,7 @@ static const uint8_t UUID_attChar_vibra[] = {
/* BLE UUID for card10 char rockets */ /* BLE UUID for card10 char rockets */
static const uint8_t UUID_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), UINT16_TO_BYTES(CARD10_ROCKETS_VAL_HDL),
CARD10_UUID_SUFFIX, 0x10, CARD10_UUID_PREFIX CARD10_UUID_SUFFIX, 0x10, CARD10_UUID_PREFIX
}; };
...@@ -123,6 +123,9 @@ static const uint8_t UUID_attChar_rockets[] = { ...@@ -123,6 +123,9 @@ static const uint8_t UUID_attChar_rockets[] = {
CARD10_UUID_SUFFIX, 0x10, CARD10_UUID_PREFIX 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 */ /* BLE UUID for card10 led background bottom left */
static const uint8_t UUID_char_led_bg_bottom_left[] = { static const uint8_t UUID_char_led_bg_bottom_left[] = {
ATT_PROP_READ | ATT_PROP_WRITE_NO_RSP, ATT_PROP_READ | ATT_PROP_WRITE_NO_RSP,
...@@ -338,11 +341,13 @@ static const attsAttr_t card10SvcAttrList[] = { ...@@ -338,11 +341,13 @@ static const attsAttr_t card10SvcAttrList[] = {
}, },
{ {
.pUuid = UUID_attChar_rockets, .pUuid = UUID_attChar_rockets,
.pValue = NULL, .pValue = rocketsValue,
.pLen = &rocketsLen,
.maxLen = 3 * sizeof(uint8_t), .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 | .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 // BG LED Bottom left
...@@ -820,6 +825,17 @@ static uint8_t readCard10CB( ...@@ -820,6 +825,17 @@ static uint8_t readCard10CB(
APP_TRACE_INFO0("ble-card10: read time\n"); APP_TRACE_INFO0("ble-card10: read time\n");
return ATT_SUCCESS; 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;
// background leds // background leds
case CARD10_LED_BG_BOTTOM_LEFT_VAL_HDL: case CARD10_LED_BG_BOTTOM_LEFT_VAL_HDL:
return getRGBLed(11, pAttr); return getRGBLed(11, pAttr);
......
...@@ -96,6 +96,7 @@ typedef _Bool bool; ...@@ -96,6 +96,7 @@ typedef _Bool bool;
#define API_LEDS_SET_ALL_HSV 0x6b #define API_LEDS_SET_ALL_HSV 0x6b
#define API_LEDS_SET_GAMMA_TABLE 0x6c #define API_LEDS_SET_GAMMA_TABLE 0x6c
#define API_LEDS_CLEAR_ALL 0x6d #define API_LEDS_CLEAR_ALL 0x6d
#define API_LEDS_GET_ROCKET 0x6e
#define API_LEDS_GET 0x6f #define API_LEDS_GET 0x6f
#define API_VIBRA_SET 0x70 #define API_VIBRA_SET 0x70
...@@ -739,6 +740,24 @@ API(API_LEDS_UPDATE, void epic_leds_update(void)); ...@@ -739,6 +740,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)); 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 |
* +-------+--------+----------+
* :returns value: Brightness of LED (value between 0 and 31) or ``-EINVAL`` if the LED/rocket does not exists.
*/
API(API_LEDS_GET_ROCKET, int 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. * 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.
* *
......
...@@ -112,6 +112,18 @@ void epic_leds_set_rocket(int led, uint8_t value) ...@@ -112,6 +112,18 @@ void epic_leds_set_rocket(int led, uint8_t value)
pmic_set_led(led, value); pmic_set_led(led, value);
} }
int epic_leds_get_rocket(int led)
{
int ret = 0;
while (hwlock_acquire(HWLOCK_I2C, pdMS_TO_TICKS(1)) < 0) {
vTaskDelay(pdMS_TO_TICKS(1));
}
ret = pmic_get_led(led);
hwlock_release(HWLOCK_I2C);
return ret;
}
void epic_set_flashlight(bool power) void epic_set_flashlight(bool power)
{ {
leds_flashlight(power); leds_flashlight(power);
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
#include "MAX77650-Arduino-Library.h" #include "MAX77650-Arduino-Library.h"
#include <stdint.h> #include <stdint.h>
#include <stdio.h> #include <stdio.h>
#include <errno.h>
static const gpio_cfg_t pmic_interrupt_pin = { static const gpio_cfg_t pmic_interrupt_pin = {
PORT_0, PIN_12, GPIO_FUNC_IN, GPIO_PAD_PULL_UP PORT_0, PIN_12, GPIO_FUNC_IN, GPIO_PAD_PULL_UP
...@@ -123,6 +124,20 @@ void pmic_set_button_callback(pmic_button_callback_fn cb) ...@@ -123,6 +124,20 @@ void pmic_set_button_callback(pmic_button_callback_fn cb)
pmic_button_callback = cb; pmic_button_callback = cb;
} }
int 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();
}
return -EINVAL;
}
void pmic_set_led(uint8_t led, uint8_t val) void pmic_set_led(uint8_t led, uint8_t val)
{ {
if (led == 0) { if (led == 0) {
......
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
void pmic_init(void); void pmic_init(void);
void pmic_set_led(uint8_t led, uint8_t val); void pmic_set_led(uint8_t led, uint8_t val);
int pmic_get_led(uint8_t led);
void pmic_poll(void); void pmic_poll(void);
/* weak, so it can be overwritten by applications */ /* weak, so it can be overwritten by applications */
......
...@@ -72,6 +72,27 @@ def set_rocket(led, value): ...@@ -72,6 +72,27 @@ def set_rocket(led, value):
sys_leds.set_rocket(led, value) sys_leds.set_rocket(led, value)
def get_rocket(led):
"""
Get brightness of one of the rocket LEDs.
:param int led: Choose your rocket!
+-------+--------+----------+
| ID | Color | Location |
+=======+========+==========+
| ``0`` | Blue | Left |
+-------+--------+----------+
| ``1`` | Yellow | Top |
+-------+--------+----------+
| ``2`` | Green | Right |
+-------+--------+----------+
:rtype: int
:returns: Brightness of LED (value between 0 and 31).
"""
return sys_leds.get_rocket(led)
def dim_top(value): def dim_top(value):
""" """
Set global brightness for top RGB LEDs. Set global brightness for top RGB LEDs.
......
...@@ -16,6 +16,7 @@ Q(set_all) ...@@ -16,6 +16,7 @@ Q(set_all)
Q(set_all_hsv) Q(set_all_hsv)
Q(set_flashlight) Q(set_flashlight)
Q(set_rocket) Q(set_rocket)
Q(get_rocket)
Q(set_powersave) Q(set_powersave)
Q(set_gamma) Q(set_gamma)
Q(dim_top) Q(dim_top)
......
...@@ -200,6 +200,19 @@ static mp_obj_t mp_leds_set_rocket(mp_obj_t led_in, mp_obj_t value_in) ...@@ -200,6 +200,19 @@ static mp_obj_t mp_leds_set_rocket(mp_obj_t led_in, mp_obj_t value_in)
} }
static MP_DEFINE_CONST_FUN_OBJ_2(leds_set_rocket_obj, mp_leds_set_rocket); static MP_DEFINE_CONST_FUN_OBJ_2(leds_set_rocket_obj, mp_leds_set_rocket);
static mp_obj_t mp_leds_get_rocket(mp_obj_t led_in)
{
int led = mp_obj_get_int(led_in);
uint8_t ret = epic_leds_get_rocket(led);
if (ret == -EINVAL) {
mp_raise_ValueError(
"invalid value: maybe the led does not exists"
);
}
return MP_OBJ_NEW_SMALL_INT(ret);
}
static MP_DEFINE_CONST_FUN_OBJ_1(leds_get_rocket_obj, mp_leds_get_rocket);
static mp_obj_t mp_leds_dim_top(mp_obj_t dim_in) static mp_obj_t mp_leds_dim_top(mp_obj_t dim_in)
{ {
int dim = mp_obj_get_int(dim_in); int dim = mp_obj_get_int(dim_in);
...@@ -269,6 +282,7 @@ static const mp_rom_map_elem_t leds_module_globals_table[] = { ...@@ -269,6 +282,7 @@ static const mp_rom_map_elem_t leds_module_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR_set_all), MP_ROM_PTR(&leds_set_all_obj) }, { MP_ROM_QSTR(MP_QSTR_set_all), MP_ROM_PTR(&leds_set_all_obj) },
{ MP_ROM_QSTR(MP_QSTR_set_all_hsv), MP_ROM_PTR(&leds_set_all_hsv_obj) }, { MP_ROM_QSTR(MP_QSTR_set_all_hsv), MP_ROM_PTR(&leds_set_all_hsv_obj) },
{ MP_ROM_QSTR(MP_QSTR_set_rocket), MP_ROM_PTR(&leds_set_rocket_obj) }, { MP_ROM_QSTR(MP_QSTR_set_rocket), MP_ROM_PTR(&leds_set_rocket_obj) },
{ MP_ROM_QSTR(MP_QSTR_get_rocket), MP_ROM_PTR(&leds_get_rocket_obj) },
{ MP_ROM_QSTR(MP_QSTR_set_flashlight), { MP_ROM_QSTR(MP_QSTR_set_flashlight),
MP_ROM_PTR(&leds_set_flashlight_obj) }, MP_ROM_PTR(&leds_set_flashlight_obj) },
{ MP_ROM_QSTR(MP_QSTR_update), MP_ROM_PTR(&leds_update_obj) }, { MP_ROM_QSTR(MP_QSTR_update), MP_ROM_PTR(&leds_update_obj) },
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment