Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed integer frequency to string, without using float #100

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/_txRx.ino
Original file line number Diff line number Diff line change
Expand Up @@ -654,7 +654,7 @@ int buildPacket(uint8_t *buff_up, struct LoraUp *LoraUp, bool internal)
#else
// _JSONENCODE undefined, this is default
// ---------------------------------------
ftoa((double)freqs[gwayConfig.ch].upFreq / 1000000, cfreq, 6); // XXX This can be done better
__freqToCharMhz(freqs[gwayConfig.ch].upFreq, cfreq);
if ((LoraUp->sf<6) || (LoraUp->sf>12)) { // Lora datarate & bandwidth SF6-SF12, 16-19 useful chars */
LoraUp->sf=7;
}
Expand Down
15 changes: 15 additions & 0 deletions src/_utils.ino
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,21 @@ int mStat(uint8_t intr, String & response)

// ============== NUMBER FUNCTIONS ============================================

// ----------------------------------------------------------------------------
// Convert the given LoRa frequency, in Hz, to Mhz in a string
// It does not use float conversion, as float isnt accurate.
// Parameters:
// freq is the freq to convert, from 100000000 to 999999999 Hz
// *out is the strinf buffer, minimum 11 chars.
// ----------------------------------------------------------------------------
void __freqToCharMhz(uint32_t freq, char *out) {
itoa(freq, out, 10);

for (int i = 10; i > 2; i--){
out[i] = out[i-1];
}
out[3] = '.';
}

// ----------------------------------------------------------------------------
// Convert a float to string for printing
Expand Down