template<> int Sensor<ID_ACCELERATION>::readEvents(sensors_event_t *data, int cnt){ static float scale = read_sysfs_float((*nodes)[0]); int ret = SensorBase::readEvents(data, cnt); char cmatrix[PROPERTY_VALUE_MAX]; float matrix[9]; float vector[3]; int vector_raw[3] = {read_sysfs_int("in_accel_x_raw"), read_sysfs_int("in_accel_y_raw"), read_sysfs_int("in_accel_z_raw")}; // get build.prop property property_get("hal.sensors.iio.accel.matrix", cmatrix, "-1,0,0,0,1,0,0,0,-1" );
// read value as "float" from build.prop sscanf(cmatrix,"%f,%f,%f,%f,%f,%f,%f,%f,%f", &matrix[0], &matrix[1], &matrix[2], &matrix[3], &matrix[4], &matrix[5], &matrix[6], &matrix[7], &matrix[8]);
vector[0] = scale * (matrix[0] * vector_raw[0] + matrix[1] * vector_raw[1] + matrix[2] * vector_raw[2]); // create matrix x vector product for x-value vector[1] = scale * (matrix[3] * vector_raw[0] + matrix[4] * vector_raw[1] + matrix[5] * vector_raw[2]); // create matrix x vector product for y-value vector[2] = scale * (matrix[6] * vector_raw[0] + matrix[7] * vector_raw[1] + matrix[8] * vector_raw[2]); // create matrix x vector product for z-value
for (int i = 0; i < ret; ++i) { data[i].acceleration.x = vector[0]; data[i].acceleration.y = vector[1]; data[i].acceleration.z = vector[2];
data[i].acceleration.status = SENSOR_STATUS_ACCURACY_HIGH; }
return ret;}
template<> int Sensor<ID_ACCELERATION>::readEvents(sensors_event_t *data, int cnt){ static float scale = read_sysfs_float((*nodes)[0]); int ret = SensorBase::readEvents(data, cnt); char cmatrix[PROPERTY_VALUE_MAX]; float matrix[9];
int vector_raw[3];
// get build.prop property property_get("hal.sensors.iio.accel.matrix", cmatrix, "-1,0,0,0,1,0,0,0,-1" );
// read value as "float" from build.prop sscanf(cmatrix,"%f,%f,%f,%f,%f,%f,%f,%f,%f", &matrix[0], &matrix[1], &matrix[2], &matrix[3], &matrix[4], &matrix[5], &matrix[6], &matrix[7], &matrix[8]);
for (int i = 0; i < ret; ++i) {
vector_raw[3] = {read_sysfs_int("in_accel_x_raw"), read_sysfs_int("in_accel_y_raw"), read_sysfs_int("in_accel_z_raw")}
data[i].acceleration.x = scale * (matrix[0] * vector_raw[0] + matrix[1] * vector_raw[1] + matrix[2] * vector_raw[2]); // create matrix x vector product for x-value data[i].acceleration.y = scale * (matrix[3] * vector_raw[0] + matrix[4] * vector_raw[1] + matrix[5] * vector_raw[2]); // create matrix x vector product for y-value
data[i].acceleration.z = scale * (matrix[6] * vector_raw[0] + matrix[7] * vector_raw[1] + matrix[8] * vector_raw[2]); // create matrix x vector product for z-value
data[i].acceleration.status = SENSOR_STATUS_ACCURACY_HIGH;
} return ret;}
@Dev's would it be better to rename the property to persist.hal... so that it can be set via terminal without editting /system -- i.e. value auto-written to /data/persist
But not sure this is the right matrix for all Cube's...
Switching to [ $BOARD = "i7 Stylus" ] would be more specific
setprop hal.sensors.iio.accel.matrix=1,0,0,0,1,0,0,0,1
ro.sf.hwrotation=180
Any ideas?
1,0,0,0,1,0,0,0,1 like you have tried means
X=x Y=y Z=z
As you want the y to be reversed use -1.
with build.prop hal.sensors.iio.accel.matrix=f1x,f1y,f1z,f2x,f2y,f2z,f3x,f3y,f3z it is possible to manipulate accel sensors directions and assignment to the corresponding axes default: hal.sensors.iio.accel.matrix=-1,0,0,0,1,0,0,0,-1
that means for the default we use the the x-axis value f1x inverted (yes the sign matters)
y and z wer not used for android to be calculated as fist axis so f1y and f1z are 0
summ up use a inverted x and nothing from y and z
the next tree valuse are for the second axis
we have 0,1,0 wich means
f2x = 0 no input from the x sensor
f2y = 1 use the positive y sensor value
f2z = 0 no input from the z sensor
and at least the last 3 values
f2x = 0 no input from the x sensorf2y = 0 no input from y sensorf2z = -1 use the inverted z sensor value
As how-to I woot boot without build.prop entry and write down the behavior of your device
eg. the device rotates 90deg clockwise to the expected behavior than play with switching the sensors (1,0,0 ==> 0,1,0,....)
eg. the device has a orrientation with inverted rotation than play with the sign of the axis (1 ==> -1, -1 ==> 1)
The last sensor would be z axis that is not used for screen rotation (as far as I see), but you can test the correct value by apps that can read out the raw sensor data or maybe games
case "$PRODUCT" in
i7 Stylus)
set_property hal.sensors.iio.accel.matrix 1,0,0,0,-1,0,0,0,-1
;;
*)
;;
esac
hal.sensors.iio.accel.matrix=1,0,0,0,-1,0,0,0,1
setprop hal.sensors.iio.accel.matrix=1,0,0,0,-1,0,0,0,1
ro.sf.hwrotation=180
Any help here?
@Ossi the matrix has only been added to 6.0/MM Roms so won't work with 4.4/KK (edit. Chih-Wei just posted the same)
Also I don't know if ro.sf.hwrotation ever worked with Ax86 - I know that's a stock AOSP entry though; but don't think it does anything with Ax86.
If you want KK with correct rotation you probably need to recompiled with modified iio lib or possibly(unlikely) just replacing the kk rotation lib with one from mm would work.
For those who have an accelerometer is rotated 90 degrees:
correct file hardware/libsensors/iio-sensors.cpp the following lines:
data[i].acceleration.x = -scale * read_sysfs_int("in_accel_x_raw");
data[i].acceleration.y = scale * read_sysfs_int("in_accel_y_raw");
and change to
data[i].acceleration.x = scale * read_sysfs_int("in_accel_y_raw");
data[i].acceleration.y = scale * read_sysfs_int("in_accel_x_raw");
Then recompile Android.
Android-x86 4.4 r3 with a vertical accelerometer and working internal MicroSD cardreader - https://yadi.sk/d/OvsY2hIbiwbKk
Someone just posted a marshmallow-x86 nightly build
that you can try.
If you take the hardware/libsensors/iio-sensors.cpp file from MM and add that to KK source and compile the matrix should work.
Alternatively - if you have root you can try an already compiled iio.so file from MM and add that to your ROM. (I'll upload one if you want to try it)