From f3664f01beb5160b73336b17697223d408b74a7b Mon Sep 17 00:00:00 2001 From: Astro Date: Thu, 19 Sep 2019 15:28:11 +0200 Subject: [PATCH] command_parser: fix float parsing --- firmware/src/command_parser.rs | 6 +++--- firmware/src/main.rs | 5 ++++- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/firmware/src/command_parser.rs b/firmware/src/command_parser.rs index 989abd2..e33a8d7 100644 --- a/firmware/src/command_parser.rs +++ b/firmware/src/command_parser.rs @@ -4,7 +4,7 @@ use nom::{ branch::alt, bytes::complete::{is_a, tag, take_while1}, character::{is_digit, complete::{char, one_of}}, - combinator::{complete, map, value}, + combinator::{complete, map, opt, value}, sequence::{preceded, separated_pair}, multi::{fold_many0, fold_many1}, error::ErrorKind, @@ -133,8 +133,8 @@ fn unsigned(input: &[u8]) -> IResult<&[u8], Result> { } fn float(input: &[u8]) -> IResult<&[u8], Result> { - let (input, sign) = is_a("-")(input)?; - let negative = sign.len() > 0; + let (input, sign) = opt(is_a("-"))(input)?; + let negative = sign.is_some(); let (input, digits) = take_while1(|c| is_digit(c) || c == '.' as u8)(input)?; let result = lexical::parse(digits) .map(|result: f32| if negative { -result } else { result }) diff --git a/firmware/src/main.rs b/firmware/src/main.rs index f4b5ab9..ade8546 100644 --- a/firmware/src/main.rs +++ b/firmware/src/main.rs @@ -1,7 +1,10 @@ #![feature(const_fn, proc_macro_hygiene)] -#![no_std] +#![cfg_attr(not(test), no_std)] #![cfg_attr(not(test), no_main)] +#[cfg(not(test))] +extern crate std; + use cortex_m_rt::entry; use core::fmt::{self, Write}; use smoltcp::time::Instant;