BLE RX: Making auto channel timer independent of packet events. (#1608)

This commit is contained in:
Netro 2023-11-28 12:18:15 -05:00 committed by GitHub
parent 175e5e2e8c
commit a6ed6e3099
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 49 additions and 27 deletions

View file

@ -170,17 +170,6 @@ void BLETxView::start() {
baseband::run_image(portapack::spi_flash::image_tag_btle_tx);
transmitter_model.enable();
int randomChannel = channel_number;
if (auto_channel) {
int min = 37;
int max = 39;
randomChannel = min + std::rand() % (max - min + 1);
field_frequency.set_value(get_freq_by_channel_number(randomChannel));
}
// Generate new random Mac Address.
generateRandomMacAddress(randomMac);
@ -201,7 +190,7 @@ void BLETxView::start() {
// Setup next packet configuration.
progressbar.set_max(packets[current_packet].packet_count);
baseband::set_btletx(randomChannel, random_mac ? randomMac : packets[current_packet].macAddress, packets[current_packet].advertisementData, pduType);
baseband::set_btletx(channel_number, random_mac ? randomMac : packets[current_packet].macAddress, packets[current_packet].advertisementData, pduType);
}
void BLETxView::stop() {
@ -226,8 +215,8 @@ void BLETxView::reset() {
// called each 1/60th of second, so 6 = 100ms
void BLETxView::on_timer() {
if (++mscounter == timer_period) {
mscounter = 0;
if (++timer_count == timer_period) {
timer_count = 0;
if (is_active()) {
// Reached end of current packet repeats.
@ -253,6 +242,19 @@ void BLETxView::on_timer() {
}
}
}
if (++auto_channel_counter == auto_channel_period) {
auto_channel_counter = 0;
if (auto_channel) {
int min = 37;
int max = 39;
channel_number = min + std::rand() % (max - min + 1);
field_frequency.set_value(get_freq_by_channel_number(channel_number));
}
}
}
void BLETxView::on_tx_progress(const bool done) {
@ -316,7 +318,7 @@ BLETxView::BLETxView(NavigationView& nav)
options_speed.on_change = [this](size_t, int32_t i) {
timer_period = i;
mscounter = 0;
timer_count = 0;
};
options_adv_type.on_change = [this](size_t, int32_t i) {