This commit is contained in:
Morgan 'ARR\!' Allen 2020-02-22 08:56:41 -08:00
parent 26dd375b9d
commit 2d1a05d447

View file

@ -243,6 +243,18 @@ void lora32_enable_continuous_rx(lora32_cfg_t *lora) {
lora32_write_reg(lora, REG_OP_MODE, MODE_LONG_RANGE_MODE | MODE_RX_CONTINUOUS); lora32_write_reg(lora, REG_OP_MODE, MODE_LONG_RANGE_MODE | MODE_RX_CONTINUOUS);
} }
void lora32_enable_cad(lora32_cfg_t *lora) {
if((lora->cad_done != NULL) | (lora->cad_detected != NULL)) {
ESP_LOGD(TAG, "Setting DIO0 to CAD Detect");
lora32_write_reg(lora, REG_DIO_MAPPING_1, DIO0_MODE_CADDET);
}
ESP_LOGD(TAG, "Enabling CAD Detection Mode");
lora32_write_reg(lora, REG_OP_MODE, MODE_LONG_RANGE_MODE | MODE_CAD_DETECT);
}
void lora32_set_coding_rate(lora32_cfg_t *lora, uint8_t d) { void lora32_set_coding_rate(lora32_cfg_t *lora, uint8_t d) {
if(d < 5) d = 5; if(d < 5) d = 5;
else if(d > 8) d = 8; else if(d > 8) d = 8;
@ -284,7 +296,6 @@ static void IRAM_ATTR lora32_dio0_task(void *arg) {
ESP_LOGD(TAG, "clearing irqs"); ESP_LOGD(TAG, "clearing irqs");
lora32_write_reg(lora, REG_IRQ_FLAGS, irqs); lora32_write_reg(lora, REG_IRQ_FLAGS, irqs);
// is this the right check? seems to work but looks off
// TODO handle header validation // TODO handle header validation
if((irqs & IRQ_RX_DONE) == IRQ_RX_DONE) { if((irqs & IRQ_RX_DONE) == IRQ_RX_DONE) {
lora32_handle_receive(lora); lora32_handle_receive(lora);
@ -293,6 +304,22 @@ static void IRAM_ATTR lora32_dio0_task(void *arg) {
if((irqs & IRQ_TX_DONE) == IRQ_TX_DONE) { if((irqs & IRQ_TX_DONE) == IRQ_TX_DONE) {
if(lora->tx_done != NULL) lora->tx_done(); if(lora->tx_done != NULL) lora->tx_done();
} }
bool cad_detected = false;
if((irqs & IRQ_CAD_DETECTED) == IRQ_CAD_DETECTED) {
// this is for the next clause, CAD Done callback gets true/false
cad_detected = true;
// no need for arg, cad_detected callback is always presummed true
if(lora->cad_detected != NULL) lora->cad_detected();
}
if((irqs & IRQ_CAD_DONE) == IRQ_CAD_DONE) {
// cad_done gets true/false from above, when activity is detected
// these *should* fire at the same time, defaults to false
if(lora->cad_done != NULL) lora->cad_done(cad_detected);
}
} }
} }