stm: Wrap some functions in MICROPY_ENABLE_FLOAT.

This commit is contained in:
Damien George 2014-03-08 15:28:51 +00:00
parent 0c36da0b59
commit 01d50d0d58
3 changed files with 7 additions and 1 deletions

View File

@ -300,7 +300,7 @@ static mp_obj_t adc_all_read_core_vbat(mp_obj_t self_in) {
pyb_obj_adc_all_t *self = self_in;
if (self->is_enabled) {
float data = adc_read_core_vbat();
float data = adc_read_core_vbat();
return mp_obj_new_float(data);
} else {
return mp_const_none;

View File

@ -209,6 +209,7 @@ int pfenv_printf(const pfenv_t *pfenv, const char *fmt, va_list args) {
case 'P': // ?
chrs += pfenv_print_int(pfenv, va_arg(args, int), 0, 16, 'A', flags, width);
break;
#if MICROPY_ENABLE_FLOAT
case 'g':
{
// This is a very hacky approach to printing floats. Micropython
@ -234,6 +235,7 @@ int pfenv_printf(const pfenv_t *pfenv, const char *fmt, va_list args) {
}
break;
}
#endif
default:
pfenv->print_strn(pfenv->data, fmt, 1);
chrs += 1;

View File

@ -124,7 +124,11 @@ static void servo_obj_print(void (*print)(void *env, const char *fmt, ...), void
static mp_obj_t servo_obj_angle(mp_obj_t self_in, mp_obj_t angle) {
pyb_servo_obj_t *self = self_in;
#if MICROPY_ENABLE_FLOAT
machine_int_t v = 152 + 85.0 * mp_obj_get_float(angle) / 90.0;
#else
machine_int_t v = 152 + 85 * mp_obj_get_int(angle) / 90;
#endif
if (v < 65) { v = 65; }
if (v > 210) { v = 210; }
switch (self->servo_id) {