summaryrefslogtreecommitdiffstats
path: root/src/common/impl/frequency.c
blob: 4838df8037ec77ffa866b42ca06577c4a7c23573 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include "common/frequency.h"

bool ffFreqAppendNum(uint32_t mhz, FFstrbuf* result) {
    if (mhz == 0) {
        return false;
    }

    const FFOptionsDisplay* options = &instance.config.display;
    bool spaceBeforeUnit = options->freqSpaceBeforeUnit != FF_SPACE_BEFORE_UNIT_NEVER;
    int8_t ndigits = options->freqNdigits;

    if (ndigits >= 0) {
        ffStrbufAppendDouble(result, mhz / 1000., ndigits, true);
        if (spaceBeforeUnit) {
            ffStrbufAppendC(result, ' ');
        }
        ffStrbufAppendS(result, "GHz");
    } else {
        ffStrbufAppendUInt(result, mhz);
        if (spaceBeforeUnit) {
            ffStrbufAppendC(result, ' ');
        }
        ffStrbufAppendS(result, "MHz");
    }
    return true;
}