[FL-976] Removing lambdas (#1849)
* Removing lambdas... * Wake the fk up, Gordon! We have a citadel to burn! * Here comes the Nihilanth * Lambda documentation Co-authored-by: あく <alleteam@gmail.com>
This commit is contained in:
@@ -67,17 +67,17 @@ void subghz_view_receiver_set_lock(SubGhzViewReceiver* subghz_receiver, SubGhzLo
|
||||
if(lock == SubGhzLockOn) {
|
||||
subghz_receiver->lock = lock;
|
||||
with_view_model(
|
||||
subghz_receiver->view, (SubGhzViewReceiverModel * model) {
|
||||
model->bar_show = SubGhzViewReceiverBarShowLock;
|
||||
return true;
|
||||
});
|
||||
subghz_receiver->view,
|
||||
SubGhzViewReceiverModel * model,
|
||||
{ model->bar_show = SubGhzViewReceiverBarShowLock; },
|
||||
true);
|
||||
furi_timer_start(subghz_receiver->timer, pdMS_TO_TICKS(1000));
|
||||
} else {
|
||||
with_view_model(
|
||||
subghz_receiver->view, (SubGhzViewReceiverModel * model) {
|
||||
model->bar_show = SubGhzViewReceiverBarShowDefault;
|
||||
return true;
|
||||
});
|
||||
subghz_receiver->view,
|
||||
SubGhzViewReceiverModel * model,
|
||||
{ model->bar_show = SubGhzViewReceiverBarShowDefault; },
|
||||
true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -95,7 +95,9 @@ static void subghz_view_receiver_update_offset(SubGhzViewReceiver* subghz_receiv
|
||||
furi_assert(subghz_receiver);
|
||||
|
||||
with_view_model(
|
||||
subghz_receiver->view, (SubGhzViewReceiverModel * model) {
|
||||
subghz_receiver->view,
|
||||
SubGhzViewReceiverModel * model,
|
||||
{
|
||||
size_t history_item = model->history_item;
|
||||
uint16_t bounds = history_item > 3 ? 2 : history_item;
|
||||
|
||||
@@ -107,8 +109,8 @@ static void subghz_view_receiver_update_offset(SubGhzViewReceiver* subghz_receiv
|
||||
} else if(model->list_offset > model->idx - bounds) {
|
||||
model->list_offset = CLAMP(model->idx - 1, (int16_t)(history_item - bounds), 0);
|
||||
}
|
||||
return true;
|
||||
});
|
||||
},
|
||||
true);
|
||||
}
|
||||
|
||||
void subghz_view_receiver_add_item_to_menu(
|
||||
@@ -117,7 +119,9 @@ void subghz_view_receiver_add_item_to_menu(
|
||||
uint8_t type) {
|
||||
furi_assert(subghz_receiver);
|
||||
with_view_model(
|
||||
subghz_receiver->view, (SubGhzViewReceiverModel * model) {
|
||||
subghz_receiver->view,
|
||||
SubGhzViewReceiverModel * model,
|
||||
{
|
||||
SubGhzReceiverMenuItem* item_menu =
|
||||
SubGhzReceiverMenuItemArray_push_raw(model->history->data);
|
||||
item_menu->item_str = furi_string_alloc_set(name);
|
||||
@@ -128,9 +132,8 @@ void subghz_view_receiver_add_item_to_menu(
|
||||
} else {
|
||||
model->history_item++;
|
||||
}
|
||||
|
||||
return true;
|
||||
});
|
||||
},
|
||||
true);
|
||||
subghz_view_receiver_update_offset(subghz_receiver);
|
||||
}
|
||||
|
||||
@@ -141,12 +144,14 @@ void subghz_view_receiver_add_data_statusbar(
|
||||
const char* history_stat_str) {
|
||||
furi_assert(subghz_receiver);
|
||||
with_view_model(
|
||||
subghz_receiver->view, (SubGhzViewReceiverModel * model) {
|
||||
subghz_receiver->view,
|
||||
SubGhzViewReceiverModel * model,
|
||||
{
|
||||
furi_string_set(model->frequency_str, frequency_str);
|
||||
furi_string_set(model->preset_str, preset_str);
|
||||
furi_string_set(model->history_stat_str, history_stat_str);
|
||||
return true;
|
||||
});
|
||||
},
|
||||
true);
|
||||
}
|
||||
|
||||
static void subghz_view_receiver_draw_frame(Canvas* canvas, uint16_t idx, bool scrollbar) {
|
||||
@@ -240,10 +245,10 @@ static void subghz_view_receiver_timer_callback(void* context) {
|
||||
furi_assert(context);
|
||||
SubGhzViewReceiver* subghz_receiver = context;
|
||||
with_view_model(
|
||||
subghz_receiver->view, (SubGhzViewReceiverModel * model) {
|
||||
model->bar_show = SubGhzViewReceiverBarShowDefault;
|
||||
return true;
|
||||
});
|
||||
subghz_receiver->view,
|
||||
SubGhzViewReceiverModel * model,
|
||||
{ model->bar_show = SubGhzViewReceiverBarShowDefault; },
|
||||
true);
|
||||
if(subghz_receiver->lock_count < UNLOCK_CNT) {
|
||||
subghz_receiver->callback(
|
||||
SubGhzCustomEventViewReceiverOffDisplay, subghz_receiver->context);
|
||||
@@ -260,10 +265,10 @@ bool subghz_view_receiver_input(InputEvent* event, void* context) {
|
||||
|
||||
if(subghz_receiver->lock == SubGhzLockOn) {
|
||||
with_view_model(
|
||||
subghz_receiver->view, (SubGhzViewReceiverModel * model) {
|
||||
model->bar_show = SubGhzViewReceiverBarShowToUnlockPress;
|
||||
return true;
|
||||
});
|
||||
subghz_receiver->view,
|
||||
SubGhzViewReceiverModel * model,
|
||||
{ model->bar_show = SubGhzViewReceiverBarShowToUnlockPress; },
|
||||
true);
|
||||
if(subghz_receiver->lock_count == 0) {
|
||||
furi_timer_start(subghz_receiver->timer, pdMS_TO_TICKS(1000));
|
||||
}
|
||||
@@ -274,10 +279,10 @@ bool subghz_view_receiver_input(InputEvent* event, void* context) {
|
||||
// subghz_receiver->callback(
|
||||
// SubGhzCustomEventViewReceiverUnlock, subghz_receiver->context);
|
||||
with_view_model(
|
||||
subghz_receiver->view, (SubGhzViewReceiverModel * model) {
|
||||
model->bar_show = SubGhzViewReceiverBarShowUnlock;
|
||||
return true;
|
||||
});
|
||||
subghz_receiver->view,
|
||||
SubGhzViewReceiverModel * model,
|
||||
{ model->bar_show = SubGhzViewReceiverBarShowUnlock; },
|
||||
true);
|
||||
//subghz_receiver->lock = SubGhzLockOff;
|
||||
furi_timer_start(subghz_receiver->timer, pdMS_TO_TICKS(650));
|
||||
}
|
||||
@@ -291,29 +296,35 @@ bool subghz_view_receiver_input(InputEvent* event, void* context) {
|
||||
event->key == InputKeyUp &&
|
||||
(event->type == InputTypeShort || event->type == InputTypeRepeat)) {
|
||||
with_view_model(
|
||||
subghz_receiver->view, (SubGhzViewReceiverModel * model) {
|
||||
subghz_receiver->view,
|
||||
SubGhzViewReceiverModel * model,
|
||||
{
|
||||
if(model->idx != 0) model->idx--;
|
||||
return true;
|
||||
});
|
||||
},
|
||||
true);
|
||||
} else if(
|
||||
event->key == InputKeyDown &&
|
||||
(event->type == InputTypeShort || event->type == InputTypeRepeat)) {
|
||||
with_view_model(
|
||||
subghz_receiver->view, (SubGhzViewReceiverModel * model) {
|
||||
subghz_receiver->view,
|
||||
SubGhzViewReceiverModel * model,
|
||||
{
|
||||
if(model->idx != model->history_item - 1) model->idx++;
|
||||
return true;
|
||||
});
|
||||
},
|
||||
true);
|
||||
} else if(event->key == InputKeyLeft && event->type == InputTypeShort) {
|
||||
subghz_receiver->callback(SubGhzCustomEventViewReceiverConfig, subghz_receiver->context);
|
||||
} else if(event->key == InputKeyOk && event->type == InputTypeShort) {
|
||||
with_view_model(
|
||||
subghz_receiver->view, (SubGhzViewReceiverModel * model) {
|
||||
subghz_receiver->view,
|
||||
SubGhzViewReceiverModel * model,
|
||||
{
|
||||
if(model->history_item != 0) {
|
||||
subghz_receiver->callback(
|
||||
SubGhzCustomEventViewReceiverOK, subghz_receiver->context);
|
||||
}
|
||||
return false;
|
||||
});
|
||||
},
|
||||
false);
|
||||
}
|
||||
|
||||
subghz_view_receiver_update_offset(subghz_receiver);
|
||||
@@ -329,7 +340,9 @@ void subghz_view_receiver_exit(void* context) {
|
||||
furi_assert(context);
|
||||
SubGhzViewReceiver* subghz_receiver = context;
|
||||
with_view_model(
|
||||
subghz_receiver->view, (SubGhzViewReceiverModel * model) {
|
||||
subghz_receiver->view,
|
||||
SubGhzViewReceiverModel * model,
|
||||
{
|
||||
furi_string_reset(model->frequency_str);
|
||||
furi_string_reset(model->preset_str);
|
||||
furi_string_reset(model->history_stat_str);
|
||||
@@ -342,8 +355,8 @@ void subghz_view_receiver_exit(void* context) {
|
||||
model->idx = 0;
|
||||
model->list_offset = 0;
|
||||
model->history_item = 0;
|
||||
return false;
|
||||
});
|
||||
},
|
||||
false);
|
||||
furi_timer_stop(subghz_receiver->timer);
|
||||
}
|
||||
|
||||
@@ -364,15 +377,17 @@ SubGhzViewReceiver* subghz_view_receiver_alloc() {
|
||||
view_set_exit_callback(subghz_receiver->view, subghz_view_receiver_exit);
|
||||
|
||||
with_view_model(
|
||||
subghz_receiver->view, (SubGhzViewReceiverModel * model) {
|
||||
subghz_receiver->view,
|
||||
SubGhzViewReceiverModel * model,
|
||||
{
|
||||
model->frequency_str = furi_string_alloc();
|
||||
model->preset_str = furi_string_alloc();
|
||||
model->history_stat_str = furi_string_alloc();
|
||||
model->bar_show = SubGhzViewReceiverBarShowDefault;
|
||||
model->history = malloc(sizeof(SubGhzReceiverHistory));
|
||||
SubGhzReceiverMenuItemArray_init(model->history->data);
|
||||
return true;
|
||||
});
|
||||
},
|
||||
true);
|
||||
subghz_receiver->timer =
|
||||
furi_timer_alloc(subghz_view_receiver_timer_callback, FuriTimerTypeOnce, subghz_receiver);
|
||||
return subghz_receiver;
|
||||
@@ -382,7 +397,9 @@ void subghz_view_receiver_free(SubGhzViewReceiver* subghz_receiver) {
|
||||
furi_assert(subghz_receiver);
|
||||
|
||||
with_view_model(
|
||||
subghz_receiver->view, (SubGhzViewReceiverModel * model) {
|
||||
subghz_receiver->view,
|
||||
SubGhzViewReceiverModel * model,
|
||||
{
|
||||
furi_string_free(model->frequency_str);
|
||||
furi_string_free(model->preset_str);
|
||||
furi_string_free(model->history_stat_str);
|
||||
@@ -393,8 +410,8 @@ void subghz_view_receiver_free(SubGhzViewReceiver* subghz_receiver) {
|
||||
}
|
||||
SubGhzReceiverMenuItemArray_clear(model->history->data);
|
||||
free(model->history);
|
||||
return false;
|
||||
});
|
||||
},
|
||||
false);
|
||||
furi_timer_free(subghz_receiver->timer);
|
||||
view_free(subghz_receiver->view);
|
||||
free(subghz_receiver);
|
||||
@@ -409,20 +426,19 @@ uint16_t subghz_view_receiver_get_idx_menu(SubGhzViewReceiver* subghz_receiver)
|
||||
furi_assert(subghz_receiver);
|
||||
uint32_t idx = 0;
|
||||
with_view_model(
|
||||
subghz_receiver->view, (SubGhzViewReceiverModel * model) {
|
||||
idx = model->idx;
|
||||
return false;
|
||||
});
|
||||
subghz_receiver->view, SubGhzViewReceiverModel * model, { idx = model->idx; }, false);
|
||||
return idx;
|
||||
}
|
||||
|
||||
void subghz_view_receiver_set_idx_menu(SubGhzViewReceiver* subghz_receiver, uint16_t idx) {
|
||||
furi_assert(subghz_receiver);
|
||||
with_view_model(
|
||||
subghz_receiver->view, (SubGhzViewReceiverModel * model) {
|
||||
subghz_receiver->view,
|
||||
SubGhzViewReceiverModel * model,
|
||||
{
|
||||
model->idx = idx;
|
||||
if(model->idx > 2) model->list_offset = idx - 2;
|
||||
return true;
|
||||
});
|
||||
},
|
||||
true);
|
||||
subghz_view_receiver_update_offset(subghz_receiver);
|
||||
}
|
||||
|
@@ -132,12 +132,14 @@ void subghz_frequency_analyzer_pair_callback(
|
||||
}
|
||||
//update history
|
||||
with_view_model(
|
||||
instance->view, (SubGhzFrequencyAnalyzerModel * model) {
|
||||
instance->view,
|
||||
SubGhzFrequencyAnalyzerModel * model,
|
||||
{
|
||||
model->history_frequency[2] = model->history_frequency[1];
|
||||
model->history_frequency[1] = model->history_frequency[0];
|
||||
model->history_frequency[0] = model->frequency;
|
||||
return false;
|
||||
});
|
||||
},
|
||||
false);
|
||||
} else if((rssi != 0.f) && (!instance->locked)) {
|
||||
if(instance->callback) {
|
||||
instance->callback(SubGhzCustomEventSceneAnalyzerLock, instance->context);
|
||||
@@ -146,12 +148,14 @@ void subghz_frequency_analyzer_pair_callback(
|
||||
|
||||
instance->locked = (rssi != 0.f);
|
||||
with_view_model(
|
||||
instance->view, (SubGhzFrequencyAnalyzerModel * model) {
|
||||
instance->view,
|
||||
SubGhzFrequencyAnalyzerModel * model,
|
||||
{
|
||||
model->rssi = rssi;
|
||||
model->frequency = frequency;
|
||||
model->signal = signal;
|
||||
return true;
|
||||
});
|
||||
},
|
||||
true);
|
||||
}
|
||||
|
||||
void subghz_frequency_analyzer_enter(void* context) {
|
||||
@@ -169,14 +173,16 @@ void subghz_frequency_analyzer_enter(void* context) {
|
||||
subghz_frequency_analyzer_worker_start(instance->worker);
|
||||
|
||||
with_view_model(
|
||||
instance->view, (SubGhzFrequencyAnalyzerModel * model) {
|
||||
instance->view,
|
||||
SubGhzFrequencyAnalyzerModel * model,
|
||||
{
|
||||
model->rssi = 0;
|
||||
model->frequency = 0;
|
||||
model->history_frequency[2] = 0;
|
||||
model->history_frequency[1] = 0;
|
||||
model->history_frequency[0] = 0;
|
||||
return true;
|
||||
});
|
||||
},
|
||||
true);
|
||||
}
|
||||
|
||||
void subghz_frequency_analyzer_exit(void* context) {
|
||||
@@ -190,10 +196,7 @@ void subghz_frequency_analyzer_exit(void* context) {
|
||||
subghz_frequency_analyzer_worker_free(instance->worker);
|
||||
|
||||
with_view_model(
|
||||
instance->view, (SubGhzFrequencyAnalyzerModel * model) {
|
||||
model->rssi = 0;
|
||||
return true;
|
||||
});
|
||||
instance->view, SubGhzFrequencyAnalyzerModel * model, { model->rssi = 0; }, true);
|
||||
}
|
||||
|
||||
SubGhzFrequencyAnalyzer* subghz_frequency_analyzer_alloc() {
|
||||
@@ -210,10 +213,7 @@ SubGhzFrequencyAnalyzer* subghz_frequency_analyzer_alloc() {
|
||||
view_set_exit_callback(instance->view, subghz_frequency_analyzer_exit);
|
||||
|
||||
with_view_model(
|
||||
instance->view, (SubGhzFrequencyAnalyzerModel * model) {
|
||||
model->rssi = 0;
|
||||
return true;
|
||||
});
|
||||
instance->view, SubGhzFrequencyAnalyzerModel * model, { model->rssi = 0; }, true);
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
@@ -45,11 +45,13 @@ void subghz_read_raw_add_data_statusbar(
|
||||
const char* preset_str) {
|
||||
furi_assert(instance);
|
||||
with_view_model(
|
||||
instance->view, (SubGhzReadRAWModel * model) {
|
||||
instance->view,
|
||||
SubGhzReadRAWModel * model,
|
||||
{
|
||||
furi_string_set(model->frequency_str, frequency_str);
|
||||
furi_string_set(model->preset_str, preset_str);
|
||||
return true;
|
||||
});
|
||||
},
|
||||
true);
|
||||
}
|
||||
|
||||
void subghz_read_raw_add_data_rssi(SubGhzReadRAW* instance, float rssi) {
|
||||
@@ -63,31 +65,35 @@ void subghz_read_raw_add_data_rssi(SubGhzReadRAW* instance, float rssi) {
|
||||
}
|
||||
|
||||
with_view_model(
|
||||
instance->view, (SubGhzReadRAWModel * model) {
|
||||
instance->view,
|
||||
SubGhzReadRAWModel * model,
|
||||
{
|
||||
model->rssi_history[model->ind_write++] = u_rssi;
|
||||
if(model->ind_write > SUBGHZ_READ_RAW_RSSI_HISTORY_SIZE) {
|
||||
model->rssi_history_end = true;
|
||||
model->ind_write = 0;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
},
|
||||
true);
|
||||
}
|
||||
|
||||
void subghz_read_raw_update_sample_write(SubGhzReadRAW* instance, size_t sample) {
|
||||
furi_assert(instance);
|
||||
|
||||
with_view_model(
|
||||
instance->view, (SubGhzReadRAWModel * model) {
|
||||
furi_string_printf(model->sample_write, "%d spl.", sample);
|
||||
return false;
|
||||
});
|
||||
instance->view,
|
||||
SubGhzReadRAWModel * model,
|
||||
{ furi_string_printf(model->sample_write, "%d spl.", sample); },
|
||||
false);
|
||||
}
|
||||
|
||||
void subghz_read_raw_stop_send(SubGhzReadRAW* instance) {
|
||||
furi_assert(instance);
|
||||
|
||||
with_view_model(
|
||||
instance->view, (SubGhzReadRAWModel * model) {
|
||||
instance->view,
|
||||
SubGhzReadRAWModel * model,
|
||||
{
|
||||
switch(model->status) {
|
||||
case SubGhzReadRAWStatusTXRepeat:
|
||||
case SubGhzReadRAWStatusLoadKeyTXRepeat:
|
||||
@@ -105,19 +111,21 @@ void subghz_read_raw_stop_send(SubGhzReadRAW* instance) {
|
||||
model->status = SubGhzReadRAWStatusIDLE;
|
||||
break;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
},
|
||||
true);
|
||||
}
|
||||
|
||||
void subghz_read_raw_update_sin(SubGhzReadRAW* instance) {
|
||||
furi_assert(instance);
|
||||
with_view_model(
|
||||
instance->view, (SubGhzReadRAWModel * model) {
|
||||
instance->view,
|
||||
SubGhzReadRAWModel * model,
|
||||
{
|
||||
if(model->ind_sin++ > 62) {
|
||||
model->ind_sin = 0;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
},
|
||||
true);
|
||||
}
|
||||
|
||||
static int8_t subghz_read_raw_tab_sin(uint8_t x) {
|
||||
@@ -286,9 +294,11 @@ bool subghz_read_raw_input(InputEvent* event, void* context) {
|
||||
//further check of events is not needed, we exit
|
||||
return false;
|
||||
} else if(event->key == InputKeyOk && event->type == InputTypePress) {
|
||||
uint8_t ret = false;
|
||||
with_view_model(
|
||||
instance->view, (SubGhzReadRAWModel * model) {
|
||||
uint8_t ret = false;
|
||||
instance->view,
|
||||
SubGhzReadRAWModel * model,
|
||||
{
|
||||
switch(model->status) {
|
||||
case SubGhzReadRAWStatusIDLE:
|
||||
// Start TX
|
||||
@@ -314,11 +324,13 @@ bool subghz_read_raw_input(InputEvent* event, void* context) {
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return ret;
|
||||
});
|
||||
},
|
||||
ret);
|
||||
} else if(event->key == InputKeyOk && event->type == InputTypeRelease) {
|
||||
with_view_model(
|
||||
instance->view, (SubGhzReadRAWModel * model) {
|
||||
instance->view,
|
||||
SubGhzReadRAWModel * model,
|
||||
{
|
||||
if(model->status == SubGhzReadRAWStatusTXRepeat) {
|
||||
// Stop repeat TX
|
||||
model->status = SubGhzReadRAWStatusTX;
|
||||
@@ -326,11 +338,13 @@ bool subghz_read_raw_input(InputEvent* event, void* context) {
|
||||
// Stop repeat TX
|
||||
model->status = SubGhzReadRAWStatusLoadKeyTX;
|
||||
}
|
||||
return false;
|
||||
});
|
||||
},
|
||||
false);
|
||||
} else if(event->key == InputKeyBack && event->type == InputTypeShort) {
|
||||
with_view_model(
|
||||
instance->view, (SubGhzReadRAWModel * model) {
|
||||
instance->view,
|
||||
SubGhzReadRAWModel * model,
|
||||
{
|
||||
switch(model->status) {
|
||||
case SubGhzReadRAWStatusREC:
|
||||
//Stop REC
|
||||
@@ -357,11 +371,13 @@ bool subghz_read_raw_input(InputEvent* event, void* context) {
|
||||
instance->callback(SubGhzCustomEventViewReadRAWBack, instance->context);
|
||||
break;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
},
|
||||
true);
|
||||
} else if(event->key == InputKeyLeft && event->type == InputTypeShort) {
|
||||
with_view_model(
|
||||
instance->view, (SubGhzReadRAWModel * model) {
|
||||
instance->view,
|
||||
SubGhzReadRAWModel * model,
|
||||
{
|
||||
if(model->status == SubGhzReadRAWStatusStart) {
|
||||
//Config
|
||||
instance->callback(SubGhzCustomEventViewReadRAWConfig, instance->context);
|
||||
@@ -376,11 +392,13 @@ bool subghz_read_raw_input(InputEvent* event, void* context) {
|
||||
furi_string_reset(model->file_name);
|
||||
instance->callback(SubGhzCustomEventViewReadRAWErase, instance->context);
|
||||
}
|
||||
return true;
|
||||
});
|
||||
},
|
||||
true);
|
||||
} else if(event->key == InputKeyRight && event->type == InputTypeShort) {
|
||||
with_view_model(
|
||||
instance->view, (SubGhzReadRAWModel * model) {
|
||||
instance->view,
|
||||
SubGhzReadRAWModel * model,
|
||||
{
|
||||
if(model->status == SubGhzReadRAWStatusIDLE) {
|
||||
//Save
|
||||
instance->callback(SubGhzCustomEventViewReadRAWSave, instance->context);
|
||||
@@ -388,11 +406,13 @@ bool subghz_read_raw_input(InputEvent* event, void* context) {
|
||||
//More
|
||||
instance->callback(SubGhzCustomEventViewReadRAWMore, instance->context);
|
||||
}
|
||||
return true;
|
||||
});
|
||||
},
|
||||
true);
|
||||
} else if(event->key == InputKeyOk && event->type == InputTypeShort) {
|
||||
with_view_model(
|
||||
instance->view, (SubGhzReadRAWModel * model) {
|
||||
instance->view,
|
||||
SubGhzReadRAWModel * model,
|
||||
{
|
||||
if(model->status == SubGhzReadRAWStatusStart) {
|
||||
//Record
|
||||
instance->callback(SubGhzCustomEventViewReadRAWREC, instance->context);
|
||||
@@ -404,8 +424,8 @@ bool subghz_read_raw_input(InputEvent* event, void* context) {
|
||||
instance->callback(SubGhzCustomEventViewReadRAWIDLE, instance->context);
|
||||
model->status = SubGhzReadRAWStatusIDLE;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
},
|
||||
true);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -419,36 +439,42 @@ void subghz_read_raw_set_status(
|
||||
switch(status) {
|
||||
case SubGhzReadRAWStatusStart:
|
||||
with_view_model(
|
||||
instance->view, (SubGhzReadRAWModel * model) {
|
||||
instance->view,
|
||||
SubGhzReadRAWModel * model,
|
||||
{
|
||||
model->status = SubGhzReadRAWStatusStart;
|
||||
model->rssi_history_end = false;
|
||||
model->ind_write = 0;
|
||||
furi_string_reset(model->file_name);
|
||||
furi_string_set(model->sample_write, "0 spl.");
|
||||
return true;
|
||||
});
|
||||
},
|
||||
true);
|
||||
break;
|
||||
case SubGhzReadRAWStatusIDLE:
|
||||
with_view_model(
|
||||
instance->view, (SubGhzReadRAWModel * model) {
|
||||
model->status = SubGhzReadRAWStatusIDLE;
|
||||
return true;
|
||||
});
|
||||
instance->view,
|
||||
SubGhzReadRAWModel * model,
|
||||
{ model->status = SubGhzReadRAWStatusIDLE; },
|
||||
true);
|
||||
break;
|
||||
case SubGhzReadRAWStatusLoadKeyTX:
|
||||
with_view_model(
|
||||
instance->view, (SubGhzReadRAWModel * model) {
|
||||
instance->view,
|
||||
SubGhzReadRAWModel * model,
|
||||
{
|
||||
model->status = SubGhzReadRAWStatusLoadKeyIDLE;
|
||||
model->rssi_history_end = false;
|
||||
model->ind_write = 0;
|
||||
furi_string_set(model->file_name, file_name);
|
||||
furi_string_set(model->sample_write, "RAW");
|
||||
return true;
|
||||
});
|
||||
},
|
||||
true);
|
||||
break;
|
||||
case SubGhzReadRAWStatusSaveKey:
|
||||
with_view_model(
|
||||
instance->view, (SubGhzReadRAWModel * model) {
|
||||
instance->view,
|
||||
SubGhzReadRAWModel * model,
|
||||
{
|
||||
model->status = SubGhzReadRAWStatusLoadKeyIDLE;
|
||||
if(!model->ind_write) {
|
||||
furi_string_set(model->file_name, file_name);
|
||||
@@ -456,8 +482,8 @@ void subghz_read_raw_set_status(
|
||||
} else {
|
||||
furi_string_reset(model->file_name);
|
||||
}
|
||||
return true;
|
||||
});
|
||||
},
|
||||
true);
|
||||
break;
|
||||
|
||||
default:
|
||||
@@ -476,15 +502,17 @@ void subghz_read_raw_exit(void* context) {
|
||||
SubGhzReadRAW* instance = context;
|
||||
|
||||
with_view_model(
|
||||
instance->view, (SubGhzReadRAWModel * model) {
|
||||
instance->view,
|
||||
SubGhzReadRAWModel * model,
|
||||
{
|
||||
if(model->status != SubGhzReadRAWStatusIDLE &&
|
||||
model->status != SubGhzReadRAWStatusStart &&
|
||||
model->status != SubGhzReadRAWStatusLoadKeyIDLE) {
|
||||
instance->callback(SubGhzCustomEventViewReadRAWIDLE, instance->context);
|
||||
model->status = SubGhzReadRAWStatusStart;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
},
|
||||
true);
|
||||
}
|
||||
|
||||
SubGhzReadRAW* subghz_read_raw_alloc() {
|
||||
@@ -500,14 +528,16 @@ SubGhzReadRAW* subghz_read_raw_alloc() {
|
||||
view_set_exit_callback(instance->view, subghz_read_raw_exit);
|
||||
|
||||
with_view_model(
|
||||
instance->view, (SubGhzReadRAWModel * model) {
|
||||
instance->view,
|
||||
SubGhzReadRAWModel * model,
|
||||
{
|
||||
model->frequency_str = furi_string_alloc();
|
||||
model->preset_str = furi_string_alloc();
|
||||
model->sample_write = furi_string_alloc();
|
||||
model->file_name = furi_string_alloc();
|
||||
model->rssi_history = malloc(SUBGHZ_READ_RAW_RSSI_HISTORY_SIZE * sizeof(uint8_t));
|
||||
return true;
|
||||
});
|
||||
},
|
||||
true);
|
||||
|
||||
return instance;
|
||||
}
|
||||
@@ -516,14 +546,16 @@ void subghz_read_raw_free(SubGhzReadRAW* instance) {
|
||||
furi_assert(instance);
|
||||
|
||||
with_view_model(
|
||||
instance->view, (SubGhzReadRAWModel * model) {
|
||||
instance->view,
|
||||
SubGhzReadRAWModel * model,
|
||||
{
|
||||
furi_string_free(model->frequency_str);
|
||||
furi_string_free(model->preset_str);
|
||||
furi_string_free(model->sample_write);
|
||||
furi_string_free(model->file_name);
|
||||
free(model->rssi_history);
|
||||
return true;
|
||||
});
|
||||
},
|
||||
true);
|
||||
view_free(instance->view);
|
||||
free(instance);
|
||||
}
|
||||
|
@@ -89,7 +89,9 @@ bool subghz_test_carrier_input(InputEvent* event, void* context) {
|
||||
}
|
||||
|
||||
with_view_model(
|
||||
subghz_test_carrier->view, (SubGhzTestCarrierModel * model) {
|
||||
subghz_test_carrier->view,
|
||||
SubGhzTestCarrierModel * model,
|
||||
{
|
||||
furi_hal_subghz_idle();
|
||||
|
||||
if(event->key == InputKeyLeft) {
|
||||
@@ -125,9 +127,8 @@ bool subghz_test_carrier_input(InputEvent* event, void* context) {
|
||||
SubGhzTestCarrierEventOnlyRx, subghz_test_carrier->context);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
});
|
||||
},
|
||||
true);
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -142,15 +143,17 @@ void subghz_test_carrier_enter(void* context) {
|
||||
furi_hal_gpio_init(&gpio_cc1101_g0, GpioModeInput, GpioPullNo, GpioSpeedLow);
|
||||
|
||||
with_view_model(
|
||||
subghz_test_carrier->view, (SubGhzTestCarrierModel * model) {
|
||||
subghz_test_carrier->view,
|
||||
SubGhzTestCarrierModel * model,
|
||||
{
|
||||
model->frequency = subghz_frequencies_433_92_testing; // 433
|
||||
model->real_frequency =
|
||||
furi_hal_subghz_set_frequency(subghz_frequencies_testing[model->frequency]);
|
||||
model->path = FuriHalSubGhzPathIsolate; // isolate
|
||||
model->rssi = 0.0f;
|
||||
model->status = SubGhzTestCarrierModelStatusRx;
|
||||
return true;
|
||||
});
|
||||
},
|
||||
true);
|
||||
|
||||
furi_hal_subghz_rx();
|
||||
|
||||
@@ -172,13 +175,14 @@ void subghz_test_carrier_rssi_timer_callback(void* context) {
|
||||
SubGhzTestCarrier* subghz_test_carrier = context;
|
||||
|
||||
with_view_model(
|
||||
subghz_test_carrier->view, (SubGhzTestCarrierModel * model) {
|
||||
subghz_test_carrier->view,
|
||||
SubGhzTestCarrierModel * model,
|
||||
{
|
||||
if(model->status == SubGhzTestCarrierModelStatusRx) {
|
||||
model->rssi = furi_hal_subghz_get_rssi();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
});
|
||||
},
|
||||
false);
|
||||
}
|
||||
|
||||
SubGhzTestCarrier* subghz_test_carrier_alloc() {
|
||||
|
@@ -68,7 +68,9 @@ static void subghz_test_packet_rssi_timer_callback(void* context) {
|
||||
SubGhzTestPacket* instance = context;
|
||||
|
||||
with_view_model(
|
||||
instance->view, (SubGhzTestPacketModel * model) {
|
||||
instance->view,
|
||||
SubGhzTestPacketModel * model,
|
||||
{
|
||||
if(model->status == SubGhzTestPacketModelStatusRx) {
|
||||
model->rssi = furi_hal_subghz_get_rssi();
|
||||
model->packets = instance->packet_rx;
|
||||
@@ -77,8 +79,8 @@ static void subghz_test_packet_rssi_timer_callback(void* context) {
|
||||
SUBGHZ_TEST_PACKET_COUNT -
|
||||
subghz_encoder_princeton_for_testing_get_repeat_left(instance->encoder);
|
||||
}
|
||||
return true;
|
||||
});
|
||||
},
|
||||
true);
|
||||
}
|
||||
|
||||
static void subghz_test_packet_draw(Canvas* canvas, SubGhzTestPacketModel* model) {
|
||||
@@ -137,7 +139,9 @@ static bool subghz_test_packet_input(InputEvent* event, void* context) {
|
||||
}
|
||||
|
||||
with_view_model(
|
||||
instance->view, (SubGhzTestPacketModel * model) {
|
||||
instance->view,
|
||||
SubGhzTestPacketModel * model,
|
||||
{
|
||||
if(model->status == SubGhzTestPacketModelStatusRx) {
|
||||
furi_hal_subghz_stop_async_rx();
|
||||
} else if(model->status == SubGhzTestPacketModelStatusTx) {
|
||||
@@ -179,9 +183,8 @@ static bool subghz_test_packet_input(InputEvent* event, void* context) {
|
||||
instance->callback(SubGhzTestPacketEventOnlyRx, instance->context);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
});
|
||||
},
|
||||
true);
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -194,15 +197,17 @@ void subghz_test_packet_enter(void* context) {
|
||||
furi_hal_subghz_load_preset(FuriHalSubGhzPresetOok650Async);
|
||||
|
||||
with_view_model(
|
||||
instance->view, (SubGhzTestPacketModel * model) {
|
||||
instance->view,
|
||||
SubGhzTestPacketModel * model,
|
||||
{
|
||||
model->frequency = subghz_frequencies_433_92_testing;
|
||||
model->real_frequency =
|
||||
furi_hal_subghz_set_frequency(subghz_frequencies_testing[model->frequency]);
|
||||
model->path = FuriHalSubGhzPathIsolate; // isolate
|
||||
model->rssi = 0.0f;
|
||||
model->status = SubGhzTestPacketModelStatusRx;
|
||||
return true;
|
||||
});
|
||||
},
|
||||
true);
|
||||
|
||||
furi_hal_subghz_start_async_rx(subghz_test_packet_rx_callback, instance);
|
||||
|
||||
@@ -217,15 +222,17 @@ void subghz_test_packet_exit(void* context) {
|
||||
|
||||
// Reinitialize IC to default state
|
||||
with_view_model(
|
||||
instance->view, (SubGhzTestPacketModel * model) {
|
||||
instance->view,
|
||||
SubGhzTestPacketModel * model,
|
||||
{
|
||||
if(model->status == SubGhzTestPacketModelStatusRx) {
|
||||
furi_hal_subghz_stop_async_rx();
|
||||
} else if(model->status == SubGhzTestPacketModelStatusTx) {
|
||||
subghz_encoder_princeton_for_testing_stop(instance->encoder, furi_get_tick());
|
||||
furi_hal_subghz_stop_async_tx();
|
||||
}
|
||||
return true;
|
||||
});
|
||||
},
|
||||
true);
|
||||
furi_hal_subghz_sleep();
|
||||
}
|
||||
|
||||
|
@@ -77,7 +77,9 @@ bool subghz_test_static_input(InputEvent* event, void* context) {
|
||||
}
|
||||
|
||||
with_view_model(
|
||||
instance->view, (SubGhzTestStaticModel * model) {
|
||||
instance->view,
|
||||
SubGhzTestStaticModel * model,
|
||||
{
|
||||
if(event->type == InputTypeShort) {
|
||||
if(event->key == InputKeyLeft) {
|
||||
if(model->frequency > 0) model->frequency--;
|
||||
@@ -128,9 +130,8 @@ bool subghz_test_static_input(InputEvent* event, void* context) {
|
||||
}
|
||||
furi_record_close(RECORD_NOTIFICATION);
|
||||
}
|
||||
|
||||
return true;
|
||||
});
|
||||
},
|
||||
true);
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -147,13 +148,14 @@ void subghz_test_static_enter(void* context) {
|
||||
instance->status_tx = SubGhzTestStaticStatusIDLE;
|
||||
|
||||
with_view_model(
|
||||
instance->view, (SubGhzTestStaticModel * model) {
|
||||
instance->view,
|
||||
SubGhzTestStaticModel * model,
|
||||
{
|
||||
model->frequency = subghz_frequencies_433_92_testing;
|
||||
model->real_frequency = subghz_frequencies_testing[model->frequency];
|
||||
model->button = 0;
|
||||
|
||||
return true;
|
||||
});
|
||||
},
|
||||
true);
|
||||
}
|
||||
|
||||
void subghz_test_static_exit(void* context) {
|
||||
|
@@ -35,13 +35,15 @@ void subghz_view_transmitter_add_data_to_show(
|
||||
uint8_t show_button) {
|
||||
furi_assert(subghz_transmitter);
|
||||
with_view_model(
|
||||
subghz_transmitter->view, (SubGhzViewTransmitterModel * model) {
|
||||
subghz_transmitter->view,
|
||||
SubGhzViewTransmitterModel * model,
|
||||
{
|
||||
furi_string_set(model->key_str, key_str);
|
||||
furi_string_set(model->frequency_str, frequency_str);
|
||||
furi_string_set(model->preset_str, preset_str);
|
||||
model->show_button = show_button;
|
||||
return true;
|
||||
});
|
||||
},
|
||||
true);
|
||||
}
|
||||
|
||||
static void subghz_view_transmitter_button_right(Canvas* canvas, const char* str) {
|
||||
@@ -95,23 +97,27 @@ bool subghz_view_transmitter_input(InputEvent* event, void* context) {
|
||||
|
||||
if(event->key == InputKeyBack && event->type == InputTypeShort) {
|
||||
with_view_model(
|
||||
subghz_transmitter->view, (SubGhzViewTransmitterModel * model) {
|
||||
subghz_transmitter->view,
|
||||
SubGhzViewTransmitterModel * model,
|
||||
{
|
||||
furi_string_reset(model->frequency_str);
|
||||
furi_string_reset(model->preset_str);
|
||||
furi_string_reset(model->key_str);
|
||||
model->show_button = 0;
|
||||
return false;
|
||||
});
|
||||
},
|
||||
false);
|
||||
return false;
|
||||
}
|
||||
|
||||
with_view_model(
|
||||
subghz_transmitter->view, (SubGhzViewTransmitterModel * model) {
|
||||
subghz_transmitter->view,
|
||||
SubGhzViewTransmitterModel * model,
|
||||
{
|
||||
if(model->show_button) {
|
||||
can_be_sent = true;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
},
|
||||
true);
|
||||
|
||||
if(can_be_sent && event->key == InputKeyOk && event->type == InputTypePress) {
|
||||
subghz_transmitter->callback(
|
||||
@@ -149,12 +155,14 @@ SubGhzViewTransmitter* subghz_view_transmitter_alloc() {
|
||||
view_set_exit_callback(subghz_transmitter->view, subghz_view_transmitter_exit);
|
||||
|
||||
with_view_model(
|
||||
subghz_transmitter->view, (SubGhzViewTransmitterModel * model) {
|
||||
subghz_transmitter->view,
|
||||
SubGhzViewTransmitterModel * model,
|
||||
{
|
||||
model->frequency_str = furi_string_alloc();
|
||||
model->preset_str = furi_string_alloc();
|
||||
model->key_str = furi_string_alloc();
|
||||
return true;
|
||||
});
|
||||
},
|
||||
true);
|
||||
return subghz_transmitter;
|
||||
}
|
||||
|
||||
@@ -162,12 +170,14 @@ void subghz_view_transmitter_free(SubGhzViewTransmitter* subghz_transmitter) {
|
||||
furi_assert(subghz_transmitter);
|
||||
|
||||
with_view_model(
|
||||
subghz_transmitter->view, (SubGhzViewTransmitterModel * model) {
|
||||
subghz_transmitter->view,
|
||||
SubGhzViewTransmitterModel * model,
|
||||
{
|
||||
furi_string_free(model->frequency_str);
|
||||
furi_string_free(model->preset_str);
|
||||
furi_string_free(model->key_str);
|
||||
return true;
|
||||
});
|
||||
},
|
||||
true);
|
||||
view_free(subghz_transmitter->view);
|
||||
free(subghz_transmitter);
|
||||
}
|
||||
|
Reference in New Issue
Block a user