Function2.EXPONENT value conversion throws ClassCastException when executing data.value()

I am using Function2.EXPONENT to do the "square" part of an RMS filtering sequence (my aim is to produce the RMS value of acceleration over a period of time, so I can record relatively high frequency vibration while avoiding the need for the sensor to transmit at a high frequency).

Unfortunately, I cannot extract a useful value from it. My code below:

    accelerometer.acceleration().addRouteAsync(new RouteBuilder() {
        public void configure(RouteComponent source) {
  , 2).stream(new Subscriber() {
                    public void apply(Data data, Object... env) {
                        log("Vibration " + data.value(Float.class));

Throws java.lang.ClassCastException: Invalid input class: 'class java.lang.Float'

However, if I do exactly the same code but with ADD instead of EXPONENT, then it works fine.

I am using metawear api version 3.0.0.

What am I doing wrong?


  • You'll need to manually convert the data to a float value when mapping the data with the exponent function. The Data inteface provides the scale and bytes method so you can appropriate convert from the fixed point int value to a float.

This discussion has been closed.