Skip to content

Commit

Permalink
Merge pull request #32 from obones/getFrequency_setFrequency
Browse files Browse the repository at this point in the history
Add getFrequency and setFrequency
  • Loading branch information
cpainchaud authored Apr 30, 2021
2 parents 8d64286 + 1111d24 commit afc2a13
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
28 changes: 28 additions & 0 deletions RFLink/1_Radio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,34 @@ namespace RFLink { namespace Radio {
refreshParametersFromConfig();
}

int32_t getFrequency()
{
return params::frequency;
}

/// Sets the frequency of the transceiver, and returns the previously set frequency
int32_t setFrequency(int32_t newFrequency)
{
int32_t result = getFrequency();
switch(hardware)
{
case HardwareType::HW_RFM69CW_t:
case HardwareType::HW_RFM69HCW_t:
radio.setFrequency(newFrequency);
break;
case HardwareType::HW_SX1278_t:
radio_SX1278->setFrequency(newFrequency / 1000000.0);
break;
case HardwareType::HW_RFM69NEW_t:
radio_RFM69->setFrequency(newFrequency / 1000000.0);
break;
default:
return 0; // other hardware cannot change its frequency
}
params::frequency = newFrequency;
return result;
}

HardwareType hardwareIDFromString(const char *name) {
for(int i=0; i<hardwareNames_count; i++) {
if(strcmp(hardwareNames[i], name) == 0)
Expand Down
6 changes: 6 additions & 0 deletions RFLink/1_Radio.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,12 @@ namespace RFLink { namespace Radio {
void paramsUpdatedCallback();
void refreshParametersFromConfig();

/// Returns the current frequency of the transceiver in Hertz
int32_t getFrequency();

/// Sets the frequency of the transceiver in Hertz, and returns the previously set frequency, or 0 if it does not support setting the frequency
int32_t setFrequency(int32_t newFrequency);


/**
* return HardwareType::HW_EOF_t when not found
Expand Down

0 comments on commit afc2a13

Please sign in to comment.