microbit: add RSSI to MicroBitRadio
Added the ability to capture the RSSI value, and an accessor and mutator for the last received RSSI value.
This commit is contained in:
parent
ffc217e7ac
commit
af13c940c1
2 changed files with 64 additions and 4 deletions
|
@ -116,7 +116,19 @@ class MicroBitRadio : MicroBitComponent
|
|||
int queueRxBuf();
|
||||
|
||||
/**
|
||||
* Initialises the radio for use as a multipoint sender/receiver
|
||||
* Sets the RSSI for the most recent packet.
|
||||
*
|
||||
* @param rssi the new rssi value
|
||||
*/
|
||||
int setRSSI(uint8_t rssi);
|
||||
|
||||
/**
|
||||
* Retrieves the current RSSI for the most recent packet.
|
||||
*/
|
||||
int getRSSI();
|
||||
|
||||
/**
|
||||
* Initialises the radio for use as a multipoint sender/receiver
|
||||
* @return MICROBIT_OK on success, MICROBIT_NOT_SUPPORTED if SoftDevice is enabled.
|
||||
*/
|
||||
int enable();
|
||||
|
|
|
@ -31,9 +31,28 @@ extern "C" void RADIO_IRQHandler(void)
|
|||
MicroBitRadio::instance->queueRxBuf();
|
||||
NRF_RADIO->PACKETPTR = (uint32_t) MicroBitRadio::instance->getRxBuf();
|
||||
|
||||
// Start listening for the next packet.
|
||||
NRF_RADIO->EVENTS_END = 0;
|
||||
NRF_RADIO->TASKS_START = 1;
|
||||
if(NRF_RADIO->EVENTS_READY)
|
||||
{
|
||||
NRF_RADIO->EVENTS_READY = 0;
|
||||
|
||||
// Start listening and wait for the END event
|
||||
NRF_RADIO->TASKS_START = 1;
|
||||
}
|
||||
|
||||
if(NRF_RADIO->EVENTS_END)
|
||||
{
|
||||
NRF_RADIO->EVENTS_END = 0;
|
||||
|
||||
if(NRF_RADIO->CRCSTATUS == 1)
|
||||
{
|
||||
uint8_t sample = NRF_RADIO->RSSISAMPLE;
|
||||
|
||||
uBit.radio.setRSSI(sample);
|
||||
}
|
||||
|
||||
// Start listening and wait for the END event
|
||||
NRF_RADIO->TASKS_START = 1;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -48,6 +67,7 @@ MicroBitRadio::MicroBitRadio(uint16_t id) : datagram()
|
|||
this->status = 0;
|
||||
this->group = 0;
|
||||
this->queueDepth = 0;
|
||||
this->rssi = 0;
|
||||
this->rxQueue = NULL;
|
||||
this->rxBuf = NULL;
|
||||
|
||||
|
@ -148,6 +168,34 @@ int MicroBitRadio::queueRxBuf()
|
|||
return MICROBIT_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the RSSI for the most recent packet.
|
||||
*
|
||||
* @param rssi the new rssi value
|
||||
*
|
||||
* @note should only be called from RADIO_IRQHandler...
|
||||
*/
|
||||
int MicroBitRadio::setRSSI(uint8_t rssi)
|
||||
{
|
||||
if (!(status & MICROBIT_RADIO_STATUS_INITIALISED))
|
||||
return MICROBIT_NOT_SUPPORTED;
|
||||
|
||||
this->rssi = rssi;
|
||||
|
||||
return MICROBIT_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the current RSSI for the most recent packet.
|
||||
*/
|
||||
int MicroBitRadio::getRSSI()
|
||||
{
|
||||
if (!(status & MICROBIT_RADIO_STATUS_INITIALISED))
|
||||
return MICROBIT_NOT_SUPPORTED;
|
||||
|
||||
return this->rssi;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialises the radio for use as a multipoint sender/receiver.
|
||||
* This is currently only possible if the BLE stack (Soft Device) is disabled.
|
||||
|
|
Loading…
Reference in a new issue