this all sounds good to me. I’ll make the changes to generic_accel* and the sensor API, unless somebody beats me to it.

Sterling

On 13 Dec 2016, at 6:10, David G. Simmons wrote:

+1 on the more 'generic' data types. With this, *any* sensor can simply return a SENSOR_VALUE_TYPE_FLOAT_TRIPLET whereas if we use SENSOR_VALUE_TYPE_MS2_TRIPLET then a sensor that wants to return a float triplet that ISN'T M/s^2 would either have to define its own data type or would use a rather confusing data type. And even if a sensor DID want to define it's own data type, it could simple be

#define MY_SENSOR_FLOAT_TRIPLET SENSOR_VALUE_TYPE_FLOAT_TRIPLET
It's probably worth discussing a bit whether float or int32_t (with a different scale like mm/s^2) are better.

There is (unsurprisingly!) no support for %d in tinyprintf, for example: https://github.com/apache/incubator-mynewt-core/blob/develop/libc/baselibc/src/tinyprintf.c

Personally, I got over my allergic reaction to float many years ago, but I do understand the valid concerns around it both in terms of precision, code size and ease of use.

My vote is to stick to standard units like uTesla (mag), m/s^2 (accel), rad/s (gyro), which necessitate floats. I just think those are more natural data types and you can convert any sensor output to those units to have comparable, HW nuetral values from any accel/mag/gyro/whatever.

That probably means adding a compile time flag for %f support and support in tonyprintf (which will be less tiny).

But if we do want to stick to int32_t, while still using standard SI values, we'll need to adjust the scale and move away from the units you generally encounter in the real world, and perhaps lose a bit of precision return int32_t mm/s^2, or um/s^2, etc.

This won't work today though:

    if (ctx->type == SENSOR_TYPE_ACCELEROMETER) {
        sad = (struct sensor_accel_data *) data;
        if (sad->sad_x != SENSOR_ACCEL_DATA_UNUSED) {
            console_printf("x = %f, ", sad->sad_x);
        }
        if (sad->sad_y != SENSOR_ACCEL_DATA_UNUSED) {
            console_printf("y = %f, ", sad->sad_y);
        }
        if (sad->sad_z != SENSOR_ACCEL_DATA_UNUSED) {
            console_printf("z = %f", sad->sad_z);
        }
        console_printf("\n");
    }

Kevin

Reply via email to