mirror of
https://github.com/Next-Flip/Momentum-Firmware.git
synced 2026-05-03 04:49:59 -07:00
BLE Spam refactor random/set/custom mode handling
This commit is contained in:
@@ -72,7 +72,7 @@ static const char* type_names[ContinuityTypeCOUNT] = {
|
||||
[ContinuityTypeCustomCrash] = "Continuity Custom",
|
||||
};
|
||||
static const char* get_name(const ProtocolCfg* _cfg) {
|
||||
const ContinuityCfg* cfg = &_cfg->continuity;
|
||||
const ContinuityCfg* cfg = &_cfg->specific.continuity;
|
||||
return type_names[cfg->type];
|
||||
}
|
||||
|
||||
@@ -87,8 +87,8 @@ static uint8_t packet_sizes[ContinuityTypeCOUNT] = {
|
||||
[ContinuityTypeNearbyInfo] = HEADER_LEN + 5,
|
||||
[ContinuityTypeCustomCrash] = HEADER_LEN + 11,
|
||||
};
|
||||
static void make_packet(uint8_t* _size, uint8_t** _packet, const ProtocolCfg* _cfg) {
|
||||
const ContinuityCfg* cfg = _cfg ? &_cfg->continuity : NULL;
|
||||
static void make_packet(uint8_t* _size, uint8_t** _packet, ProtocolCfg* _cfg) {
|
||||
ContinuityCfg* cfg = _cfg ? &_cfg->specific.continuity : NULL;
|
||||
|
||||
ContinuityType type;
|
||||
if(cfg && cfg->type != 0x00) {
|
||||
@@ -139,14 +139,18 @@ static void make_packet(uint8_t* _size, uint8_t** _packet, const ProtocolCfg* _c
|
||||
|
||||
case ContinuityTypeProximityPair: {
|
||||
uint16_t model;
|
||||
if(cfg && cfg->data.proximity_pair.model != 0x0000) {
|
||||
model = cfg->data.proximity_pair.model;
|
||||
} else {
|
||||
switch(cfg ? _cfg->mode : ProtocolModeRandom) {
|
||||
case ProtocolModeRandom:
|
||||
default:
|
||||
model = pp_models[rand() % pp_models_count].value;
|
||||
break;
|
||||
case ProtocolModeValue:
|
||||
model = cfg->data.proximity_pair.model;
|
||||
break;
|
||||
}
|
||||
|
||||
uint8_t prefix;
|
||||
if(cfg && cfg->data.proximity_pair.prefix == 0x00) {
|
||||
if(cfg && cfg->data.proximity_pair.prefix != 0x00) {
|
||||
prefix = cfg->data.proximity_pair.prefix;
|
||||
} else {
|
||||
if(model == 0x0055 || model == 0x0030)
|
||||
@@ -209,10 +213,14 @@ static void make_packet(uint8_t* _size, uint8_t** _packet, const ProtocolCfg* _c
|
||||
|
||||
case ContinuityTypeNearbyAction: {
|
||||
uint8_t action;
|
||||
if(cfg && cfg->data.nearby_action.action != 0x00) {
|
||||
action = cfg->data.nearby_action.action;
|
||||
} else {
|
||||
switch(cfg ? _cfg->mode : ProtocolModeRandom) {
|
||||
case ProtocolModeRandom:
|
||||
default:
|
||||
action = na_actions[rand() % na_actions_count].value;
|
||||
break;
|
||||
case ProtocolModeValue:
|
||||
action = cfg->data.nearby_action.action;
|
||||
break;
|
||||
}
|
||||
|
||||
uint8_t flags;
|
||||
@@ -293,7 +301,8 @@ enum {
|
||||
};
|
||||
static void config_callback(void* _ctx, uint32_t index) {
|
||||
Ctx* ctx = _ctx;
|
||||
ContinuityCfg* cfg = &ctx->attack->payload.cfg.continuity;
|
||||
ProtocolCfg* _cfg = &ctx->attack->payload.cfg;
|
||||
ContinuityCfg* cfg = &_cfg->specific.continuity;
|
||||
scene_manager_set_scene_state(ctx->scene_manager, SceneConfig, index);
|
||||
switch(cfg->type) {
|
||||
case ContinuityTypeProximityPair: {
|
||||
@@ -341,19 +350,22 @@ static void config_callback(void* _ctx, uint32_t index) {
|
||||
}
|
||||
}
|
||||
static void pp_model_changed(VariableItem* item) {
|
||||
ContinuityCfg* cfg = variable_item_get_context(item);
|
||||
ProtocolCfg* _cfg = variable_item_get_context(item);
|
||||
ContinuityCfg* cfg = &_cfg->specific.continuity;
|
||||
uint8_t index = variable_item_get_current_value_index(item);
|
||||
if(index) {
|
||||
index--;
|
||||
_cfg->mode = ProtocolModeValue;
|
||||
cfg->data.proximity_pair.model = pp_models[index].value;
|
||||
variable_item_set_current_value_text(item, pp_models[index].name);
|
||||
} else {
|
||||
cfg->data.proximity_pair.model = 0x0000;
|
||||
_cfg->mode = ProtocolModeRandom;
|
||||
variable_item_set_current_value_text(item, "Random");
|
||||
}
|
||||
}
|
||||
static void pp_prefix_changed(VariableItem* item) {
|
||||
ContinuityCfg* cfg = variable_item_get_context(item);
|
||||
ProtocolCfg* _cfg = variable_item_get_context(item);
|
||||
ContinuityCfg* cfg = &_cfg->specific.continuity;
|
||||
uint8_t index = variable_item_get_current_value_index(item);
|
||||
if(index) {
|
||||
index--;
|
||||
@@ -365,33 +377,39 @@ static void pp_prefix_changed(VariableItem* item) {
|
||||
}
|
||||
}
|
||||
static void na_action_changed(VariableItem* item) {
|
||||
ContinuityCfg* cfg = variable_item_get_context(item);
|
||||
ProtocolCfg* _cfg = variable_item_get_context(item);
|
||||
ContinuityCfg* cfg = &_cfg->specific.continuity;
|
||||
uint8_t index = variable_item_get_current_value_index(item);
|
||||
if(index) {
|
||||
index--;
|
||||
_cfg->mode = ProtocolModeValue;
|
||||
cfg->data.nearby_action.action = na_actions[index].value;
|
||||
variable_item_set_current_value_text(item, na_actions[index].name);
|
||||
} else {
|
||||
cfg->data.nearby_action.action = 0x00;
|
||||
_cfg->mode = ProtocolModeRandom;
|
||||
variable_item_set_current_value_text(item, "Random");
|
||||
}
|
||||
}
|
||||
static void extra_config(Ctx* ctx) {
|
||||
ContinuityCfg* cfg = &ctx->attack->payload.cfg.continuity;
|
||||
ProtocolCfg* _cfg = &ctx->attack->payload.cfg;
|
||||
ContinuityCfg* cfg = &_cfg->specific.continuity;
|
||||
VariableItemList* list = ctx->variable_item_list;
|
||||
VariableItem* item;
|
||||
size_t value_index;
|
||||
|
||||
switch(cfg->type) {
|
||||
case ContinuityTypeProximityPair: {
|
||||
item =
|
||||
variable_item_list_add(list, "Model Code", pp_models_count + 1, pp_model_changed, cfg);
|
||||
item = variable_item_list_add(
|
||||
list, "Model Code", pp_models_count + 1, pp_model_changed, _cfg);
|
||||
const char* model_name = NULL;
|
||||
char model_name_buf[5];
|
||||
if(cfg->data.proximity_pair.model == 0x0000) {
|
||||
switch(_cfg->mode) {
|
||||
case ProtocolModeRandom:
|
||||
default:
|
||||
model_name = "Random";
|
||||
value_index = 0;
|
||||
} else {
|
||||
break;
|
||||
case ProtocolModeValue:
|
||||
for(uint8_t i = 0; i < pp_models_count; i++) {
|
||||
if(cfg->data.proximity_pair.model == pp_models[i].value) {
|
||||
model_name = pp_models[i].name;
|
||||
@@ -405,12 +423,13 @@ static void extra_config(Ctx* ctx) {
|
||||
model_name = model_name_buf;
|
||||
value_index = pp_models_count + 1;
|
||||
}
|
||||
break;
|
||||
}
|
||||
variable_item_set_current_value_index(item, value_index);
|
||||
variable_item_set_current_value_text(item, model_name);
|
||||
|
||||
item =
|
||||
variable_item_list_add(list, "Prefix", pp_prefixes_count + 1, pp_prefix_changed, cfg);
|
||||
variable_item_list_add(list, "Prefix", pp_prefixes_count + 1, pp_prefix_changed, _cfg);
|
||||
const char* prefix_name = NULL;
|
||||
char prefix_name_buf[3];
|
||||
if(cfg->data.proximity_pair.prefix == 0x00) {
|
||||
@@ -440,13 +459,16 @@ static void extra_config(Ctx* ctx) {
|
||||
}
|
||||
case ContinuityTypeNearbyAction: {
|
||||
item = variable_item_list_add(
|
||||
list, "Action Type", na_actions_count + 1, na_action_changed, cfg);
|
||||
list, "Action Type", na_actions_count + 1, na_action_changed, _cfg);
|
||||
const char* action_name = NULL;
|
||||
char action_name_buf[3];
|
||||
if(cfg->data.nearby_action.action == 0x00) {
|
||||
switch(_cfg->mode) {
|
||||
case ProtocolModeRandom:
|
||||
default:
|
||||
action_name = "Random";
|
||||
value_index = 0;
|
||||
} else {
|
||||
break;
|
||||
case ProtocolModeValue:
|
||||
for(uint8_t i = 0; i < na_actions_count; i++) {
|
||||
if(cfg->data.nearby_action.action == na_actions[i].value) {
|
||||
action_name = na_actions[i].name;
|
||||
@@ -463,6 +485,7 @@ static void extra_config(Ctx* ctx) {
|
||||
action_name = action_name_buf;
|
||||
value_index = na_actions_count + 1;
|
||||
}
|
||||
break;
|
||||
}
|
||||
variable_item_set_current_value_index(item, value_index);
|
||||
variable_item_set_current_value_text(item, action_name);
|
||||
@@ -503,7 +526,7 @@ static uint8_t config_counts[ContinuityTypeCOUNT] = {
|
||||
[ContinuityTypeCustomCrash] = ConfigCcCOUNT - ConfigExtraStart - 1,
|
||||
};
|
||||
static uint8_t config_count(const ProtocolCfg* _cfg) {
|
||||
const ContinuityCfg* cfg = &_cfg->continuity;
|
||||
const ContinuityCfg* cfg = &_cfg->specific.continuity;
|
||||
return config_counts[cfg->type];
|
||||
}
|
||||
|
||||
@@ -517,16 +540,18 @@ const Protocol protocol_continuity = {
|
||||
|
||||
static void pp_model_callback(void* _ctx, uint32_t index) {
|
||||
Ctx* ctx = _ctx;
|
||||
ContinuityCfg* cfg = &ctx->attack->payload.cfg.continuity;
|
||||
ProtocolCfg* _cfg = &ctx->attack->payload.cfg;
|
||||
ContinuityCfg* cfg = &_cfg->specific.continuity;
|
||||
switch(index) {
|
||||
case 0:
|
||||
cfg->data.proximity_pair.model = 0x0000;
|
||||
_cfg->mode = ProtocolModeRandom;
|
||||
scene_manager_previous_scene(ctx->scene_manager);
|
||||
break;
|
||||
case pp_models_count + 1:
|
||||
scene_manager_next_scene(ctx->scene_manager, SceneContinuityPpModelCustom);
|
||||
break;
|
||||
default:
|
||||
_cfg->mode = ProtocolModeValue;
|
||||
cfg->data.proximity_pair.model = pp_models[index - 1].value;
|
||||
scene_manager_previous_scene(ctx->scene_manager);
|
||||
break;
|
||||
@@ -534,27 +559,28 @@ static void pp_model_callback(void* _ctx, uint32_t index) {
|
||||
}
|
||||
void scene_continuity_pp_model_on_enter(void* _ctx) {
|
||||
Ctx* ctx = _ctx;
|
||||
ContinuityCfg* cfg = &ctx->attack->payload.cfg.continuity;
|
||||
ProtocolCfg* _cfg = &ctx->attack->payload.cfg;
|
||||
ContinuityCfg* cfg = &_cfg->specific.continuity;
|
||||
Submenu* submenu = ctx->submenu;
|
||||
uint32_t selected = 0;
|
||||
bool found = false;
|
||||
submenu_reset(submenu);
|
||||
|
||||
submenu_add_item(submenu, "Random", 0, pp_model_callback, ctx);
|
||||
if(cfg->data.proximity_pair.model == 0x0000) {
|
||||
found = true;
|
||||
if(_cfg->mode == ProtocolModeRandom) {
|
||||
selected = 0;
|
||||
}
|
||||
|
||||
bool found = false;
|
||||
for(uint8_t i = 0; i < pp_models_count; i++) {
|
||||
submenu_add_item(submenu, pp_models[i].name, i + 1, pp_model_callback, ctx);
|
||||
if(!found && cfg->data.proximity_pair.model == pp_models[i].value) {
|
||||
if(!found && _cfg->mode == ProtocolModeValue &&
|
||||
cfg->data.proximity_pair.model == pp_models[i].value) {
|
||||
found = true;
|
||||
selected = i + 1;
|
||||
}
|
||||
}
|
||||
submenu_add_item(submenu, "Custom", pp_models_count + 1, pp_model_callback, ctx);
|
||||
if(!found) {
|
||||
found = true;
|
||||
if(!found && _cfg->mode == ProtocolModeValue) {
|
||||
selected = pp_models_count + 1;
|
||||
}
|
||||
|
||||
@@ -573,14 +599,17 @@ void scene_continuity_pp_model_on_exit(void* _ctx) {
|
||||
|
||||
static void pp_model_custom_callback(void* _ctx) {
|
||||
Ctx* ctx = _ctx;
|
||||
ContinuityCfg* cfg = &ctx->attack->payload.cfg.continuity;
|
||||
ProtocolCfg* _cfg = &ctx->attack->payload.cfg;
|
||||
ContinuityCfg* cfg = &_cfg->specific.continuity;
|
||||
_cfg->mode = ProtocolModeValue;
|
||||
cfg->data.proximity_pair.model = (ctx->byte_store[0] << 0x08) + (ctx->byte_store[1] << 0x00);
|
||||
scene_manager_previous_scene(ctx->scene_manager);
|
||||
scene_manager_previous_scene(ctx->scene_manager);
|
||||
}
|
||||
void scene_continuity_pp_model_custom_on_enter(void* _ctx) {
|
||||
Ctx* ctx = _ctx;
|
||||
ContinuityCfg* cfg = &ctx->attack->payload.cfg.continuity;
|
||||
ProtocolCfg* _cfg = &ctx->attack->payload.cfg;
|
||||
ContinuityCfg* cfg = &_cfg->specific.continuity;
|
||||
ByteInput* byte_input = ctx->byte_input;
|
||||
|
||||
byte_input_set_header_text(byte_input, "Enter custom Model Code");
|
||||
@@ -604,7 +633,8 @@ void scene_continuity_pp_model_custom_on_exit(void* _ctx) {
|
||||
|
||||
static void pp_prefix_callback(void* _ctx, uint32_t index) {
|
||||
Ctx* ctx = _ctx;
|
||||
ContinuityCfg* cfg = &ctx->attack->payload.cfg.continuity;
|
||||
ProtocolCfg* _cfg = &ctx->attack->payload.cfg;
|
||||
ContinuityCfg* cfg = &_cfg->specific.continuity;
|
||||
switch(index) {
|
||||
case 0:
|
||||
cfg->data.proximity_pair.prefix = 0x00;
|
||||
@@ -621,7 +651,8 @@ static void pp_prefix_callback(void* _ctx, uint32_t index) {
|
||||
}
|
||||
void scene_continuity_pp_prefix_on_enter(void* _ctx) {
|
||||
Ctx* ctx = _ctx;
|
||||
ContinuityCfg* cfg = &ctx->attack->payload.cfg.continuity;
|
||||
ProtocolCfg* _cfg = &ctx->attack->payload.cfg;
|
||||
ContinuityCfg* cfg = &_cfg->specific.continuity;
|
||||
Submenu* submenu = ctx->submenu;
|
||||
uint32_t selected = 0;
|
||||
bool found = false;
|
||||
@@ -632,6 +663,7 @@ void scene_continuity_pp_prefix_on_enter(void* _ctx) {
|
||||
found = true;
|
||||
selected = 0;
|
||||
}
|
||||
|
||||
for(uint8_t i = 0; i < pp_prefixes_count; i++) {
|
||||
submenu_add_item(submenu, pp_prefixes[i].name, i + 1, pp_prefix_callback, ctx);
|
||||
if(!found && cfg->data.proximity_pair.prefix == pp_prefixes[i].value) {
|
||||
@@ -641,7 +673,6 @@ void scene_continuity_pp_prefix_on_enter(void* _ctx) {
|
||||
}
|
||||
submenu_add_item(submenu, "Custom", pp_prefixes_count + 1, pp_prefix_callback, ctx);
|
||||
if(!found) {
|
||||
found = true;
|
||||
selected = pp_prefixes_count + 1;
|
||||
}
|
||||
|
||||
@@ -660,14 +691,16 @@ void scene_continuity_pp_prefix_on_exit(void* _ctx) {
|
||||
|
||||
static void pp_prefix_custom_callback(void* _ctx) {
|
||||
Ctx* ctx = _ctx;
|
||||
ContinuityCfg* cfg = &ctx->attack->payload.cfg.continuity;
|
||||
ProtocolCfg* _cfg = &ctx->attack->payload.cfg;
|
||||
ContinuityCfg* cfg = &_cfg->specific.continuity;
|
||||
cfg->data.proximity_pair.prefix = (ctx->byte_store[0] << 0x00);
|
||||
scene_manager_previous_scene(ctx->scene_manager);
|
||||
scene_manager_previous_scene(ctx->scene_manager);
|
||||
}
|
||||
void scene_continuity_pp_prefix_custom_on_enter(void* _ctx) {
|
||||
Ctx* ctx = _ctx;
|
||||
ContinuityCfg* cfg = &ctx->attack->payload.cfg.continuity;
|
||||
ProtocolCfg* _cfg = &ctx->attack->payload.cfg;
|
||||
ContinuityCfg* cfg = &_cfg->specific.continuity;
|
||||
ByteInput* byte_input = ctx->byte_input;
|
||||
|
||||
byte_input_set_header_text(byte_input, "Enter custom Prefix");
|
||||
@@ -690,16 +723,18 @@ void scene_continuity_pp_prefix_custom_on_exit(void* _ctx) {
|
||||
|
||||
static void na_action_callback(void* _ctx, uint32_t index) {
|
||||
Ctx* ctx = _ctx;
|
||||
ContinuityCfg* cfg = &ctx->attack->payload.cfg.continuity;
|
||||
ProtocolCfg* _cfg = &ctx->attack->payload.cfg;
|
||||
ContinuityCfg* cfg = &_cfg->specific.continuity;
|
||||
switch(index) {
|
||||
case 0:
|
||||
cfg->data.nearby_action.action = 0x00;
|
||||
_cfg->mode = ProtocolModeRandom;
|
||||
scene_manager_previous_scene(ctx->scene_manager);
|
||||
break;
|
||||
case na_actions_count + 1:
|
||||
scene_manager_next_scene(ctx->scene_manager, SceneContinuityNaActionCustom);
|
||||
break;
|
||||
default:
|
||||
_cfg->mode = ProtocolModeValue;
|
||||
cfg->data.nearby_action.action = na_actions[index - 1].value;
|
||||
scene_manager_previous_scene(ctx->scene_manager);
|
||||
break;
|
||||
@@ -707,27 +742,28 @@ static void na_action_callback(void* _ctx, uint32_t index) {
|
||||
}
|
||||
void scene_continuity_na_action_on_enter(void* _ctx) {
|
||||
Ctx* ctx = _ctx;
|
||||
ContinuityCfg* cfg = &ctx->attack->payload.cfg.continuity;
|
||||
ProtocolCfg* _cfg = &ctx->attack->payload.cfg;
|
||||
ContinuityCfg* cfg = &_cfg->specific.continuity;
|
||||
Submenu* submenu = ctx->submenu;
|
||||
uint32_t selected = 0;
|
||||
bool found = false;
|
||||
submenu_reset(submenu);
|
||||
|
||||
submenu_add_item(submenu, "Random", 0, na_action_callback, ctx);
|
||||
if(cfg->data.nearby_action.action == 0x00) {
|
||||
found = true;
|
||||
if(_cfg->mode == ProtocolModeRandom) {
|
||||
selected = 0;
|
||||
}
|
||||
|
||||
bool found = false;
|
||||
for(uint8_t i = 0; i < na_actions_count; i++) {
|
||||
submenu_add_item(submenu, na_actions[i].name, i + 1, na_action_callback, ctx);
|
||||
if(!found && cfg->data.nearby_action.action == na_actions[i].value) {
|
||||
if(!found && _cfg->mode == ProtocolModeValue &&
|
||||
cfg->data.nearby_action.action == na_actions[i].value) {
|
||||
found = true;
|
||||
selected = i + 1;
|
||||
}
|
||||
}
|
||||
submenu_add_item(submenu, "Custom", na_actions_count + 1, na_action_callback, ctx);
|
||||
if(!found) {
|
||||
found = true;
|
||||
if(!found && _cfg->mode == ProtocolModeValue) {
|
||||
selected = na_actions_count + 1;
|
||||
}
|
||||
|
||||
@@ -746,14 +782,17 @@ void scene_continuity_na_action_on_exit(void* _ctx) {
|
||||
|
||||
static void na_action_custom_callback(void* _ctx) {
|
||||
Ctx* ctx = _ctx;
|
||||
ContinuityCfg* cfg = &ctx->attack->payload.cfg.continuity;
|
||||
ProtocolCfg* _cfg = &ctx->attack->payload.cfg;
|
||||
ContinuityCfg* cfg = &_cfg->specific.continuity;
|
||||
_cfg->mode = ProtocolModeValue;
|
||||
cfg->data.nearby_action.action = (ctx->byte_store[0] << 0x00);
|
||||
scene_manager_previous_scene(ctx->scene_manager);
|
||||
scene_manager_previous_scene(ctx->scene_manager);
|
||||
}
|
||||
void scene_continuity_na_action_custom_on_enter(void* _ctx) {
|
||||
Ctx* ctx = _ctx;
|
||||
ContinuityCfg* cfg = &ctx->attack->payload.cfg.continuity;
|
||||
ProtocolCfg* _cfg = &ctx->attack->payload.cfg;
|
||||
ContinuityCfg* cfg = &_cfg->specific.continuity;
|
||||
ByteInput* byte_input = ctx->byte_input;
|
||||
|
||||
byte_input_set_header_text(byte_input, "Enter custom Action Type");
|
||||
@@ -780,7 +819,8 @@ static void na_flags_callback(void* _ctx) {
|
||||
}
|
||||
void scene_continuity_na_flags_on_enter(void* _ctx) {
|
||||
Ctx* ctx = _ctx;
|
||||
ContinuityCfg* cfg = &ctx->attack->payload.cfg.continuity;
|
||||
ProtocolCfg* _cfg = &ctx->attack->payload.cfg;
|
||||
ContinuityCfg* cfg = &_cfg->specific.continuity;
|
||||
ByteInput* byte_input = ctx->byte_input;
|
||||
|
||||
byte_input_set_header_text(byte_input, "Press back for automatic");
|
||||
@@ -801,6 +841,7 @@ bool scene_continuity_na_flags_on_event(void* _ctx, SceneManagerEvent event) {
|
||||
}
|
||||
void scene_continuity_na_flags_on_exit(void* _ctx) {
|
||||
Ctx* ctx = _ctx;
|
||||
ContinuityCfg* cfg = &ctx->attack->payload.cfg.continuity;
|
||||
ProtocolCfg* _cfg = &ctx->attack->payload.cfg;
|
||||
ContinuityCfg* cfg = &_cfg->specific.continuity;
|
||||
cfg->data.nearby_action.flags = (ctx->byte_store[0] << 0x00);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user