summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDan McGee <dpmcgee@gmail.com>2011-04-06 10:03:33 -0500
committerDan McGee <dpmcgee@gmail.com>2011-04-06 10:03:33 -0500
commit80bca8b46574046407ffd46bcb3c6f6aecb4c435 (patch)
tree3204f3441b4f39708cb3439c6340f1aea81724d2
parentd7223bd4a05dc3b7a39b3610bef748953376a476 (diff)
downloadonkyocontrol-80bca8b46574046407ffd46bcb3c6f6aecb4c435.tar.gz
onkyocontrol-80bca8b46574046407ffd46bcb3c6f6aecb4c435.zip
Use fixed point parsing for FM frequencies
Signed-off-by: Dan McGee <dpmcgee@gmail.com>
-rw-r--r--command.c14
1 files changed, 10 insertions, 4 deletions
diff --git a/command.c b/command.c
index 1c6dda2..58b0ec0 100644
--- a/command.c
+++ b/command.c
@@ -388,20 +388,26 @@ static int handle_tune(struct receiver *rcvr,
* AM: (1)000 (possible thousands spot, with NO decimal point)
*/
if(strchr(arg, '.')) {
- double freq;
+ long freq, frac_freq;
/* attempt to parse as FM */
errno = 0;
- freq = strtod(arg, &test);
+ freq = strtol(arg, &test, 10);
+ /* this should start parsing after the '.' */
+ frac_freq = strtol(test + 1, &test, 10);
if(errno != 0) {
/* parse error, not a number */
return(-1);
}
- if(freq < 87.4 || freq > 108.0) {
+ /* allowed range: 87.5 to 107.9 inclusive */
+ if(frac_freq < 0 || frac_freq > 9 ||
+ (freq <= 87 && frac_freq < 5) ||
+ freq >= 108) {
/* range error */
return(-1);
}
/* we want to print something like "TUN09790" */
- sprintf(cmdstr, "%05.0f", freq * 100.0);
+ freq = freq * 100 + frac_freq * 10;
+ sprintf(cmdstr, "%05ld", freq);
} else {
long freq;
/* should be AM, single number with no decimal */