Skip to content

Commit 33b443c

Browse files
authored
Merge pull request #6 from tixlegeek/main
Added sensitivity to configuration following jamisonderek's work
2 parents b266e9b + ef0218c commit 33b443c

7 files changed

+57
-3
lines changed

401lightMessengerApp/401LightMsg_acc.c

+2
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,8 @@ static int32_t app_acc_worker(void* ctx) {
187187
// The shader updating function is the callback associated to the "color"
188188
color_animation_callback shader = appData->shader;
189189
lis2dh12_init(&app->data->lis2dh12);
190+
lis2dh12_set_sensitivity(
191+
&app->data->lis2dh12, lightmsg_sensitivity_value[light_msg_data->sensitivity]);
190192

191193
while(running) {
192194
// Checks if the thread must be ended.

401lightMessengerApp/401LightMsg_config.c

+34
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,16 @@ const char* const lightmsg_brightness_text[] = {
3030
"Blinding",
3131
};
3232

33+
const uint8_t lightmsg_sensitivity_value[] = {
34+
60, // Low sensitivity
35+
40, // High sensitivity
36+
};
37+
38+
const char* const lightmsg_sensitivity_text[] = {
39+
"Low",
40+
"High",
41+
};
42+
3343
const uint32_t lightmsg_colors_flat[] = {
3444
0xFF0000, // COLOR_RED
3545
0x7F0F00, // COLOR_ORANGE
@@ -248,6 +258,20 @@ void on_change_brightness(VariableItem* item) {
248258
variable_item_set_current_value_text(item, lightmsg_brightness_text[index]);
249259
}
250260

261+
/**
262+
* @brief Callback function to handle sensitivity menu
263+
*
264+
* @param item Selected item
265+
*/
266+
void on_change_sensitivity(VariableItem* item) {
267+
AppContext* app = variable_item_get_context(item);
268+
Configuration* light_msg_data = (Configuration*)app->data->config;
269+
uint8_t index = variable_item_get_current_value_index(item);
270+
light_msg_data->sensitivity = index;
271+
272+
variable_item_set_current_value_text(item, lightmsg_sensitivity_text[index]);
273+
}
274+
251275
/**
252276
* @brief Callback function to handle color menu
253277
*
@@ -303,6 +327,16 @@ AppConfig* app_config_alloc(void* ctx) {
303327
variable_item_set_current_value_text(
304328
item, lightmsg_brightness_text[light_msg_data->brightness]);
305329
#endif
330+
item = variable_item_list_add(
331+
appConfig->list,
332+
"Sensitivity",
333+
COUNT_OF(lightmsg_sensitivity_text),
334+
on_change_sensitivity,
335+
app);
336+
variable_item_set_current_value_index(item, light_msg_data->sensitivity); // 0,10,20,30,...
337+
variable_item_set_current_value_text(
338+
item, lightmsg_sensitivity_text[light_msg_data->sensitivity]);
339+
306340
item = variable_item_list_add(
307341
appConfig->list, "Color", COUNT_OF(lightmsg_color_text), on_change_color, app);
308342
variable_item_set_current_value_index(item, light_msg_data->color); // 0,10,20,30,...

401lightMessengerApp/401LightMsg_config.h

+3
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ typedef enum {
5050
extern const double lightmsg_brightness_value[];
5151
extern const char* const lightmsg_brightness_text[];
5252

53+
extern const uint8_t lightmsg_sensitivity_value[];
54+
extern const char* const lightmsg_sensitivity_text[];
55+
5356
#define COLOR_RED 0
5457
#define COLOR_ORANGE 1
5558
#define COLOR_YELLOW 2

401lightMessengerApp/401_config.c

+6-1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ void config_default_init(Configuration* config) {
4040
config->bitmapPath[LIGHTMSG_MAX_BITMAPPATH_LEN + 1] = '\0';
4141
config->color = LIGHTMSG_DEFAULT_COLOR; // Default color
4242
config->brightness = LIGHTMSG_DEFAULT_BRIGHTNESS; // Default brightness
43+
config->sensitivity = LIGHTMSG_DEFAULT_SENSIBILITY; // Default sensitivity
4344
config->orientation = LIGHTMSG_DEFAULT_ORIENTATION; // Default orientation (e.g., false)
4445
}
4546

@@ -79,6 +80,7 @@ l401_err config_to_json(Configuration* config, char** jsontxt) {
7980
// overrites brightness setting
8081
cJSON_AddNumberToObject(
8182
json, "brightness", LightMsg_BrightnessBlinding); // (double)config->brightness);
83+
cJSON_AddNumberToObject(json, "sensitivity", (double)config->sensitivity);
8284
cJSON_AddBoolToObject(json, "orientation", config->orientation);
8385

8486
// Convert cJSON object to string
@@ -133,11 +135,13 @@ l401_err json_to_config(char* jsontxt, Configuration* config) {
133135
cJSON* json_bitmapPath = cJSON_GetObjectItemCaseSensitive(json, "bitmapPath");
134136
cJSON* json_color = cJSON_GetObjectItemCaseSensitive(json, "color");
135137
cJSON* json_brightness = cJSON_GetObjectItemCaseSensitive(json, "brightness");
138+
cJSON* json_sensitivity = cJSON_GetObjectItemCaseSensitive(json, "sensitivity");
136139
cJSON* json_orientation = cJSON_GetObjectItemCaseSensitive(json, "orientation");
137140

138141
if(!cJSON_IsString(json_version) || !cJSON_IsString(json_text) ||
139142
!cJSON_IsString(json_bitmapPath) || !cJSON_IsNumber(json_color) ||
140-
!cJSON_IsNumber(json_brightness) || !cJSON_IsBool(json_orientation)) {
143+
!cJSON_IsNumber(json_brightness) || !cJSON_IsNumber(json_sensitivity) ||
144+
!cJSON_IsBool(json_orientation)) {
141145
cJSON_Delete(json);
142146
FURI_LOG_E(TAG, "Error: Malformed configuration");
143147
return L401_ERR_MALFORMED;
@@ -153,6 +157,7 @@ l401_err json_to_config(char* jsontxt, Configuration* config) {
153157
// config->text = strdup(json_text->valuestring);
154158
config->color = (uint8_t)json_color->valuedouble;
155159
config->brightness = (uint8_t)json_brightness->valuedouble;
160+
config->sensitivity = (uint8_t)json_sensitivity->valuedouble;
156161
config->orientation = cJSON_IsTrue(json_orientation) ? true : false;
157162
cJSON_Delete(json);
158163
return L401_OK;

401lightMessengerApp/401_config.h

+2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#define LIGHTMSG_VERSION "1.0"
1515
#define LIGHTMSG_DEFAULT_ORIENTATION 0
1616
#define LIGHTMSG_DEFAULT_BRIGHTNESS 3
17+
#define LIGHTMSG_DEFAULT_SENSIBILITY 1
1718
#define LIGHTMSG_DEFAULT_COLOR 1
1819
#define LIGHTMSG_DEFAULT_TEXT "Lab401"
1920
#define LIGHTMSG_DEFAULT_BITMAPPATH LIGHTMSGCONF_SAVE_FOLDER
@@ -27,6 +28,7 @@ typedef struct {
2728
char bitmapPath[LIGHTMSG_MAX_BITMAPPATH_LEN + 1];
2829
uint8_t color;
2930
uint8_t brightness;
31+
uint8_t sensitivity;
3032
bool orientation;
3133
color_animation_callback cb;
3234
} Configuration;

401lightMessengerApp/drivers/lis2xx12_wrapper.c

+9-2
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ int32_t lis2dh12_init(void* stmdev) {
4646
lis2dh12_int1_gen_conf_set(stmdev, &int1_cfg);
4747

4848
lis2dh12_int1_pin_notification_mode_set(stmdev, LIS2DH12_INT1_PULSED);
49-
lis2dh12_int1_gen_threshold_set(stmdev, PARAM_INT1_THRESHOLD);
49+
lis2dh12_int1_gen_threshold_set(
50+
stmdev, PARAM_INT1_THRESHOLD); // default threshold, overwritten
5051
lis2dh12_int1_gen_duration_set(stmdev, PARAM_INT1_DURATION);
5152

5253
// lis2dh12 INT2
@@ -57,12 +58,18 @@ int32_t lis2dh12_init(void* stmdev) {
5758
lis2dh12_int2_gen_conf_set(stmdev, &int2_cfg);
5859

5960
lis2dh12_int2_pin_notification_mode_set(stmdev, LIS2DH12_INT2_PULSED);
60-
lis2dh12_int2_gen_threshold_set(stmdev, PARAM_INT2_THRESHOLD);
61+
lis2dh12_int2_gen_threshold_set(
62+
stmdev, PARAM_INT2_THRESHOLD); // default threshold, overwritten
6163
lis2dh12_int2_gen_duration_set(stmdev, PARAM_INT2_DURATION);
6264

6365
return 0;
6466
}
6567

68+
void lis2dh12_set_sensitivity(void* stmdev, uint8_t sensitivity) {
69+
lis2dh12_int1_gen_threshold_set(stmdev, sensitivity);
70+
lis2dh12_int2_gen_threshold_set(stmdev, sensitivity);
71+
}
72+
6673
int32_t platform_write(void* handle, uint8_t reg, const uint8_t* bufp, uint16_t len) {
6774
UNUSED(handle);
6875
furi_hal_i2c_acquire(I2C_BUS);

401lightMessengerApp/drivers/lis2xx12_wrapper.h

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
((byte) & 0x02 ? '1' : '0'), ((byte) & 0x01 ? '1' : '0')
2424

2525
int32_t lis2dh12_init(void* stmdev);
26+
void lis2dh12_set_sensitivity(void* stmdev, uint8_t sensitivity);
2627
int32_t platform_write(void* handle, uint8_t reg, const uint8_t* bufp, uint16_t len);
2728
int32_t platform_read(void* handle, uint8_t reg, uint8_t* bufp, uint16_t len);
2829

0 commit comments

Comments
 (0)