#define TEMP_BUF_SIZE 255
#define MAX_VAL_LENGTH 40
-#define ACCEL_ADJUST 100000
#define ACCEL_MAX 1961330
-#define GYRO_ADJUST 17.50
-
static int parse_val(const char *buff, unsigned char data, char *parsbuf)
{
int count=0;
int accel_min_max(double value)
{
- int result = (int)(value * ACCEL_ADJUST);
+ int result = (int)value;
if (result > ACCEL_MAX)
result = ACCEL_MAX;
// x
len += get_parse_val(data + len, tmp);
- x = (int)(atoi(tmp) / GYRO_ADJUST);
+ x = (int)atoi(tmp);
// y
len += get_parse_val(data + len, tmp);
- y = (int)(atoi(tmp) / GYRO_ADJUST);
+ y = (int)atoi(tmp);
// z
len += get_parse_val(data + len, tmp);
- z = (int)(atoi(tmp) / GYRO_ADJUST);
+ z = (int)atoi(tmp);
memset(tmp, 0, TEMP_BUF_SIZE);
*
*/
-#include <pthread.h>
-
#include "hw/pci/pci.h"
#include "hw/maru_device_ids.h"
#define SENSOR_DEVICE_NAME "sensor"
#define _MAX_BUF 1024
-#define __MAX_BUF_SENSOR 32
+#define __MAX_BUF_SENSOR 128
static QemuMutex accel_mutex;
static QemuMutex geo_mutex;
static QemuMutex gyro_mutex;
static QemuMutex light_mutex;
static QemuMutex proxi_mutex;
+static QemuMutex rot_mutex;
-static char accel_xyz [__MAX_BUF_SENSOR] = {'0',',','9','8','0','6','6','5',',','0'};
+static char accel_xyz [__MAX_BUF_SENSOR] = {'1','0','0',',','9','8','0','6','6','5',',','1','0','0'};
static int accel_enable = 0;
static int accel_delay = 200000000;
static int proxi_enable = 0;
static int proxi_delay = 200000000;
+static char rot_quad [__MAX_BUF_SENSOR] = {'2','3','6','2',',','-','1','4','0',',','-','8','4','7','0',',','9','9','9','9','6','1',',','4', 0};
+static int rot_enable = 0;
+static int rot_delay = 200000000;
+
VirtIOSENSOR* vsensor;
static int sensor_capability = 0;
case sensor_type_mag:
action = ACTION_MAG;
break;
- case sensor_type_light:
+ case sensor_type_light_adc:
action = ACTION_LIGHT;
break;
case sensor_type_proxi:
action = ACTION_PROXI;
break;
+ case sensor_type_rotation_vector:
+ action = ACTION_ROTATION;
+ break;
default:
break;
}
sscanf(data, "%d", &proxi_delay);
qemu_mutex_unlock(&proxi_mutex);
break;
+ case sensor_type_rotation_vector:
+ qemu_mutex_lock(&rot_mutex);
+ strcpy(rot_quad, data);
+ qemu_mutex_unlock(&rot_mutex);
+ break;
+ case sensor_type_rotation_vector_enable:
+ qemu_mutex_lock(&rot_mutex);
+ sscanf(data, "%d", &rot_enable);
+ qemu_mutex_unlock(&rot_mutex);
+ break;
+ case sensor_type_rotation_vector_delay:
+ qemu_mutex_lock(&rot_mutex);
+ sscanf(data, "%d", &rot_delay);
+ qemu_mutex_unlock(&rot_mutex);
+ break;
case sensor_type_mag:
qemu_mutex_lock(&geo_mutex);
strcpy(geo_tesla, data);
sprintf(msg_info, "%d", proxi_delay);
qemu_mutex_unlock(&proxi_mutex);
break;
+ case sensor_type_rotation_vector:
+ qemu_mutex_lock(&rot_mutex);
+ strcpy(msg_info, rot_quad);
+ qemu_mutex_unlock(&rot_mutex);
+ break;
+ case sensor_type_rotation_vector_enable:
+ qemu_mutex_lock(&rot_mutex);
+ sprintf(msg_info, "%d", rot_enable);
+ qemu_mutex_unlock(&rot_mutex);
+ break;
+ case sensor_type_rotation_vector_delay:
+ qemu_mutex_lock(&rot_mutex);
+ sprintf(msg_info, "%d", rot_delay);
+ qemu_mutex_unlock(&rot_mutex);
+ break;
default:
return;
}
return sensor_cap_light;
} else if (!strncmp(sensor, SENSOR_NAME_PROXI, 5)) {
return sensor_cap_proxi;
+ } else if (!strncmp(sensor, SENSOR_NAME_ROT, 3)) {
+ return sensor_cap_rotation_vector;
} else if (!strncmp(sensor, SENSOR_NAME_HAPTIC, 6)) {
return sensor_cap_haptic;
} else {
qemu_mutex_init(&geo_mutex);
qemu_mutex_init(&light_mutex);
qemu_mutex_init(&proxi_mutex);
+ qemu_mutex_init(&rot_mutex);
vsensor->vq = virtio_add_queue(&vsensor->vdev, 64, virtio_sensor_vq);
qemu_mutex_destroy(&geo_mutex);
qemu_mutex_destroy(&light_mutex);
qemu_mutex_destroy(&proxi_mutex);
+ qemu_mutex_destroy(&rot_mutex);
virtio_cleanup(vdev);
}
sensor_type_proxi,
sensor_type_proxi_enable,
sensor_type_proxi_delay,
+ sensor_type_rotation_vector,
+ sensor_type_rotation_vector_enable,
+ sensor_type_rotation_vector_delay,
sensor_type_mag,
sensor_type_tilt,
sensor_type_max
};
enum sensor_capabilities {
- sensor_cap_accel = 0x01,
- sensor_cap_geo = 0x02,
- sensor_cap_gyro = 0x04,
- sensor_cap_light = 0x08,
- sensor_cap_proxi = 0x10,
- sensor_cap_haptic = 0x20
+ sensor_cap_accel = 0x01,
+ sensor_cap_geo = 0x02,
+ sensor_cap_gyro = 0x04,
+ sensor_cap_light = 0x08,
+ sensor_cap_proxi = 0x10,
+ sensor_cap_rotation_vector = 0x20,
+ sensor_cap_haptic = 0x40
};
#define MESSAGE_TYPE_SENSOR "sensor"
#define ACTION_MAG 112
#define ACTION_LIGHT 113
#define ACTION_PROXI 114
+#define ACTION_ROTATION 115
#define ATTRIBUTE_NAME_SENSORS "sensors"
#define SENSOR_NAME_GEO "geo"
#define SENSOR_NAME_LIGHT "light"
#define SENSOR_NAME_PROXI "proxi"
+#define SENSOR_NAME_ROT "rot"
#define SENSOR_NAME_HAPTIC "haptic"
#define SENSOR_CAP_TOKEN "&"
#define get_sensor_proxi() \
req_sensor_data(sensor_type_proxi, request_get, NULL, 0);
+#define get_sensor_rotation() \
+ req_sensor_data(sensor_type_rotation_vector, request_get, NULL, 0);
+
#define set_sensor_accel(data, len) \
req_sensor_data(sensor_type_accel, request_set, data, len);
#define set_sensor_mag(data, len) \
req_sensor_data(sensor_type_mag, request_set, data, len);
+#define set_sensor_rotation_vector(data, len) \
+ req_sensor_data(sensor_type_rotation_vector, request_set, data, len);
+
#ifdef __cplusplus
}
#endif
#include "hw/pci/maru_brightness.h"
#include "hw/virtio/maru_virtio_hwkey.h"
#include "hw/virtio/maru_virtio_touchscreen.h"
+#include "hw/virtio/maru_virtio_sensor.h"
#include "display/maru_display.h"
#include "emulator.h"
#include "debug_ch.h"
void do_rotation_event(int rotation_type)
{
INFO("do_rotation_event rotation_type : %d\n", rotation_type);
-
#if 1
- int x = 0, y = 0, z = 0;
+ char *rotation = NULL;
+
+ static char rot_0 [] = {'2','3','6','2',',','-','1','4','0',',','-','8','4','7','0',',','9','9','9','9','6','1',',','4', 0};
+ static char rot_90 [] = {'-','9','9','4',',','-','4','2','0','8',',','-','7','0','3','2','1','1',',','9','1','8','2','7','9',',','4', 0};
+ static char rot_180 [] = {'1','6','2','2',',','5','6','5','8',',','9','9','9','9','4','5',',','8','6','2','6',',','4', 0};
+ static char rot_270 [] = {'1','4','1','6','8',',','1','6','0','4','6',',','7','0','9','8','6','0',',','7','0','4','0','1','6',',','4', 0};
switch (rotation_type) {
case ROTATION_PORTRAIT:
- x = 0;
- y = accel_min_max(9.80665);
- z = 0;
+ rotation = rot_0;
break;
case ROTATION_LANDSCAPE:
- x = accel_min_max(9.80665);
- y = 0;
- z = 0;
+ rotation = rot_90;
break;
case ROTATION_REVERSE_PORTRAIT:
- x = 0;
- y = accel_min_max(-9.80665);
- z = 0;
+ rotation = rot_180;
break;
case ROTATION_REVERSE_LANDSCAPE:
- x = accel_min_max(-9.80665);
- y = 0;
- z = 0;
+ rotation = rot_270;
break;
default:
+ ERR("Unknown rotation type: %d \n", rotation_type);
break;
}
- req_set_sensor_accel(x, y, z);
-#else
- char send_buf[32] = { 0 };
+ if (rotation != NULL) {
+ set_sensor_rotation_vector(rotation, strlen(rotation));
+ }
+#endif
- switch ( rotation_type ) {
+ int x = 0, y = 0, z = 0;
+
+ switch (rotation_type) {
case ROTATION_PORTRAIT:
- sprintf( send_buf, "1\n3\n0\n9.80665\n0\n" );
+ x = 100;
+ y = accel_min_max(980665);
+ z = 100;
break;
case ROTATION_LANDSCAPE:
- sprintf( send_buf, "1\n3\n9.80665\n0\n0\n" );
+ x = accel_min_max(980665);
+ y = 100;
+ z = 100;
break;
case ROTATION_REVERSE_PORTRAIT:
- sprintf( send_buf, "1\n3\n0\n-9.80665\n0\n" );
+ x = 100;
+ y = accel_min_max(-980665);
+ z = 100;
break;
case ROTATION_REVERSE_LANDSCAPE:
- sprintf(send_buf, "1\n3\n-9.80665\n0\n0\n");
+ x = accel_min_max(-980665);
+ y = 100;
+ z = 100;
break;
-
default:
break;
}
- send_to_emuld( "sensor\n\n\n\n", 10, send_buf, 32 );
-#endif
+ req_set_sensor_accel(x, y, z);
}
void save_screenshot(DisplaySurface *surface)