Skip to content

Commit

Permalink
fix #17
Browse files Browse the repository at this point in the history
  • Loading branch information
dernasherbrezon committed Nov 19, 2024
1 parent a791fcf commit 0c6da92
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
8 changes: 8 additions & 0 deletions examples/transmit_fsk_beacon/main/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@ sx127x device;

void app_main() {
ESP_LOGI(TAG, "starting up");
ESP_ERROR_CHECK(gpio_set_direction((gpio_num_t) RST, GPIO_MODE_INPUT_OUTPUT));
ESP_ERROR_CHECK(gpio_set_level((gpio_num_t) RST, 0));
vTaskDelay(pdMS_TO_TICKS(5));
ESP_ERROR_CHECK(gpio_set_level((gpio_num_t) RST, 1));
vTaskDelay(pdMS_TO_TICKS(10));
ESP_LOGI(TAG, "sx127x was reset");
ESP_ERROR_CHECK(gpio_reset_pin((gpio_num_t) RST));

spi_bus_config_t config = {
.mosi_io_num = MOSI,
.miso_io_num = MISO,
Expand Down
10 changes: 2 additions & 8 deletions src/sx127x.c
Original file line number Diff line number Diff line change
Expand Up @@ -980,10 +980,7 @@ int sx127x_fsk_ook_tx_start_beacon(const uint8_t *data, uint8_t data_length, uin
float timer2_resolution = 0.0f;
uint8_t timer2_coefficient = 0;

if (interval_ms <= 255 * p1) {
timer1_resolution = p1;
timer1_coefficient = (uint8_t) (interval_ms / p1);
} else if (interval_ms <= 255 * p1 * 2) {
if (interval_ms <= 255 * p1 * 2) {
timer1_resolution = p1;
timer2_resolution = p1;
timer1_coefficient = (uint8_t) (interval_ms / p1 / 2);
Expand All @@ -1008,10 +1005,7 @@ int sx127x_fsk_ook_tx_start_beacon(const uint8_t *data, uint8_t data_length, uin
timer2_resolution = p3;
timer1_coefficient = (uint8_t) (interval_ms / p3 / 2);
}

if (timer2_resolution != 0) {
timer2_coefficient = (uint8_t) ((interval_ms - timer1_resolution * timer1_coefficient) / timer2_resolution);
}
timer2_coefficient = (uint8_t) ((interval_ms - timer1_resolution * timer1_coefficient) / timer2_resolution);

uint8_t timer_resolution = 0b00000000;
if (timer1_resolution == p1) {
Expand Down
6 changes: 3 additions & 3 deletions test/test_sx127x.c
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,9 @@ void test_fsk_ook_beacon() {

// test different timer settings
TEST_ASSERT_EQUAL_INT(SX127X_OK, sx127x_fsk_ook_tx_start_beacon(data, sizeof(data), 15, device));
TEST_ASSERT_EQUAL_INT(234, registers[0x39]);
TEST_ASSERT_EQUAL_INT(0, registers[0x3a]);
TEST_ASSERT_EQUAL_INT(0b00000111, registers[0x38]);
TEST_ASSERT_EQUAL_INT(117, registers[0x39]);
TEST_ASSERT_EQUAL_INT(117, registers[0x3a]);
TEST_ASSERT_EQUAL_INT(0b00000101, registers[0x38]);
TEST_ASSERT_EQUAL_INT(SX127X_OK, sx127x_fsk_ook_tx_start_beacon(data, sizeof(data), 20, device));
TEST_ASSERT_EQUAL_INT(156, registers[0x39]);
TEST_ASSERT_EQUAL_INT(156, registers[0x3a]);
Expand Down

0 comments on commit 0c6da92

Please sign in to comment.