aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoraudahadi <wan.audahadi@gmail.com>2016-11-17 19:26:39 +0800
committeraudahadi <wan.audahadi@gmail.com>2016-11-17 19:26:39 +0800
commit8fb665348eae2ceda0b54b90a3ebf3bee1f2da37 (patch)
tree9ebed324b2076bd61d5f80e92286f91225c7d927
parent69d75033a5d25cd006d8945dd08f1697e1f0ab2c (diff)
Revert "build sensor"
This reverts commit 69d75033a5d25cd006d8945dd08f1697e1f0ab2c.
-rw-r--r--BoardConfig.mk5
-rw-r--r--device.mk11
-rwxr-xr-xrootdir/etc/init.target.rc673
-rw-r--r--sensors/AccelSensor.h60
-rw-r--r--sensors/Accelerometer.cpp376
-rw-r--r--sensors/Android.mk61
-rw-r--r--sensors/CalibrationManager.cpp248
-rw-r--r--sensors/CalibrationManager.h71
-rw-r--r--sensors/CalibrationModule.h137
-rw-r--r--sensors/CompassSensor.cpp256
-rw-r--r--sensors/CompassSensor.h66
-rw-r--r--sensors/GyroSensor.h57
-rw-r--r--sensors/Gyroscope.cpp278
-rw-r--r--sensors/InputEventReader.cpp89
-rw-r--r--sensors/InputEventReader.h47
-rw-r--r--sensors/LICENSE202
-rw-r--r--sensors/LightSensor.cpp312
-rw-r--r--sensors/LightSensor.h58
-rw-r--r--sensors/NativeSensorManager.cpp856
-rw-r--r--sensors/NativeSensorManager.h147
-rw-r--r--sensors/ProximitySensor.cpp422
-rw-r--r--sensors/ProximitySensor.h63
-rw-r--r--sensors/SensorBase.cpp153
-rw-r--r--sensors/SensorBase.h77
-rw-r--r--sensors/VirtualSensor.cpp128
-rw-r--r--sensors/VirtualSensor.h70
-rw-r--r--sensors/algo/akm/AKFS_AOC.c333
-rw-r--r--sensors/algo/akm/AKFS_AOC.h53
-rw-r--r--sensors/algo/akm/AKFS_Configure.h37
-rw-r--r--sensors/algo/akm/AKFS_Decomp.c51
-rw-r--r--sensors/algo/akm/AKFS_Decomp.h58
-rw-r--r--sensors/algo/akm/AKFS_Device.c150
-rw-r--r--sensors/algo/akm/AKFS_Device.h112
-rw-r--r--sensors/algo/akm/AKFS_Direction.c166
-rw-r--r--sensors/algo/akm/AKFS_Direction.h39
-rw-r--r--sensors/algo/akm/AKFS_Math.h47
-rw-r--r--sensors/algo/akm/AKFS_VNorm.c123
-rw-r--r--sensors/algo/akm/AKFS_VNorm.h46
-rw-r--r--sensors/algo/akm/NOTICE202
-rw-r--r--sensors/algo/akm/README.md34
-rwxr-xr-xsensors/algo/akm/akm_wrapper.c269
-rw-r--r--sensors/algo/common/common_wrapper.c458
-rw-r--r--sensors/algo/common/compass/AKFS_AOC.c333
-rw-r--r--sensors/algo/common/compass/AKFS_AOC.h53
-rw-r--r--sensors/algo/common/compass/AKFS_Configure.h37
-rw-r--r--sensors/algo/common/compass/AKFS_Decomp.c51
-rw-r--r--sensors/algo/common/compass/AKFS_Decomp.h58
-rw-r--r--sensors/algo/common/compass/AKFS_Device.c150
-rw-r--r--sensors/algo/common/compass/AKFS_Device.h112
-rw-r--r--sensors/algo/common/compass/AKFS_Direction.c166
-rw-r--r--sensors/algo/common/compass/AKFS_Direction.h39
-rw-r--r--sensors/algo/common/compass/AKFS_Math.h47
-rw-r--r--sensors/algo/common/compass/AKFS_VNorm.c123
-rw-r--r--sensors/algo/common/compass/AKFS_VNorm.h46
-rw-r--r--sensors/algo/common/compass/NOTICE202
-rw-r--r--sensors/algo/common/compass/README.md34
-rw-r--r--sensors/calmodule.cfg2
-rw-r--r--sensors/sensors.cpp390
-rw-r--r--sensors/sensors.h152
-rw-r--r--sensors/sensors_XML.cpp246
-rw-r--r--sensors/sensors_XML.h51
-rw-r--r--sensors/sensors_extension.h173
62 files changed, 660 insertions, 8906 deletions
diff --git a/BoardConfig.mk b/BoardConfig.mk
index 543ecf0..891c469 100644
--- a/BoardConfig.mk
+++ b/BoardConfig.mk
@@ -25,7 +25,7 @@ TARGET_OTA_ASSERT_DEVICE := Z010D,Z010,ASUS_Z010
TARGET_BOARD_INFO_FILE := $(DEVICE_PATH)/board-info.txt
# Kernel
-TARGET_KERNEL_CONFIG := zc550kl-custom_defconfig
+TARGET_KERNEL_CONFIG := cm-zc550kl_defconfig
TARGET_KERNEL_SOURCE := kernel/asus/Z010D
BOARD_KERNEL_CMDLINE := console=ttyHSL0,115200,n8 androidboot.console=ttyHSL0 androidboot.hardware=qcom ehci-hcd.park=3 androidboot.bootdevice=7824900.sdhci lpm_levels.sleep_disabled=1 androidboot.selinux=permissive
@@ -38,9 +38,6 @@ TARGET_RECOVERY_DEVICE_MODULES := libinit_z010d
#Enable SW based full disk encryption
TARGET_SWV8_DISK_ENCRYPTION := true
-# Tap-to-Wake
-TARGET_TAP_TO_WAKE_NODE := "/sys/bus/i2c/devices/5-0038/dclick_mode"
-
# Wifi
BOARD_HAS_QCOM_WLAN := true
BOARD_HAS_QCOM_WLAN_SDK := true
diff --git a/device.mk b/device.mk
index cc0e680..0e2e260 100644
--- a/device.mk
+++ b/device.mk
@@ -65,17 +65,6 @@ PRODUCT_PACKAGES += \
wpa_supplicant_overlay.conf \
WCNSS_qcom_wlan_nv.bin
-# Sensors
-PRODUCT_PACKAGES += \
- calmodule.cfg \
- libcalmodule_common \
- sensors.msm8916
-
-# Properties
-PRODUCT_PROPERTY_OVERRIDES += \
- ro.fusion.magfield.max=250
-
-
PRODUCT_COPY_FILES += \
device/asus/Z010D/wifi/WCNSS_cfg.dat:system/etc/firmware/wlan/prima/WCNSS_cfg.dat \
device/asus/Z010D/wifi/WCNSS_qcom_cfg.ini:system/etc/firmware/wlan/prima/WCNSS_qcom_cfg.ini \
diff --git a/rootdir/etc/init.target.rc b/rootdir/etc/init.target.rc
index 36ccced..c5a71aa 100755
--- a/rootdir/etc/init.target.rc
+++ b/rootdir/etc/init.target.rc
@@ -1,6 +1,167 @@
+service sp /bin/sp
+ user root
+ group root
+ seclabel u:r:asus_sp:s0
+ disabled
+ oneshot
+
+# for ssn tool
+service ssn /system/bin/ssn
+ class core
+ seclabel u:r:asus_ssn:s0
+ oneshot
+
+# unmount APD service
+service umount_apd /system/bin/sh /system/bin/umount_apd.sh
+ user root
+ disabled
+ oneshot
+
+#+++ASUS_BSP gauss_li
+on bank
+ start shawnA
+#---ASUS_BSP gauss_li
+#mount asdf
+ wait /dev/block/bootdevice/by-name/asdf
+ exec /system/bin/e2fsck -p /dev/block/bootdevice/by-name/asdf
+ mount ext4 /dev/block/bootdevice/by-name/asdf /asdf nosuid nodev barrier=1
+
+ write /proc/asusevtlog "Enter bank"
+
+
+on firmware_mounts_complete
+ start sp
+
+on boot
+ chmod 0444 /proc/cmdline
+
+on init
+ export PATH /sbin:/vendor/bin:/system/sbin:/system/bin:/system/xbin:/bin
+
+# mount asus partition
+ mkdir /factory 0775 system system
+ mkdir /factoryback 0775 system system
+ mkdir /asusfw 0775 system system
+ mkdir /asdf
+ mkdir /ADF 0775 system system
+ mkdir /APD 0775 system system
+
+on fs
+# +++ ASUS_BSP : add for asus boot animation partition
+# mount ADF
+ wait /dev/block/bootdevice/by-name/ADF
+ mount ext4 /dev/block/bootdevice/by-name/ADF /ADF nosuid nodev barrier=1 data=ordered
+ chmod 0775 /ADF
+ chmod 0775 /ADF/boot
+ chown system system /ADF
+ restorecon_recursive /ADF
+
+ wait /dev/block/bootdevice/by-name/APD
+ mount ext4 /dev/block/bootdevice/by-name/APD /APD nosuid nodev barrier=1 data=ordered
+ chmod 0775 /APD
+ chown system system /APD
+ restorecon_recursive /APD
+# --- ASUS_BSP : add for asus boot animation partition
+
+# Freeman add for GTS +++
+chmod 0660 /dev/block/bootdevice/by-name/persistent
+chown system system /dev/block/bootdevice/by-name/persistent
+chmod 0660 /dev/block/mmcblk0p24
+chown system system /dev/block/mmcblk0p24
+# Freeman add for GTS ---
+
+# mount asusfw
+ wait /dev/block/bootdevice/by-name/asusfw
+ exec /system/bin/e2fsck -p /dev/block/bootdevice/by-name/asusfw
+ mount ext4 /dev/block/bootdevice/by-name/asusfw /asusfw nosuid nodev barrier=1 noauto_da_alloc
+ restorecon_recursive /asusfw
+ chmod 0775 /asusfw
+ chown system system /asusfw
+
+ start FWAuto
+
+on post-fs
on post-fs-data
+# ASUS_BSP +++ Lei_Guo "storage info for ATD and AMAX"
+ symlink /sys/bus/mmc/devices/mmc0:0001/emmc_status /data/data/emmc_status
+ symlink /sys/bus/mmc/devices/mmc0:0001/emmc_size /data/data/emmc_size
+ symlink /sys/bus/mmc/devices/mmc0:0001/emmc_prv /data/data/emmc_fw
+ symlink /sys/bus/mmc/devices/mmc0:0001/emmc_fw_version /data/data/emmc_fw_version
+ symlink /sys/bus/mmc/devices/mmc0:0001/emmc_total_size /data/data/emmc_total_size
+ symlink /sys/devices/soc.0/7864900.sdhci/mmc_host/mmc1/sd_status /data/data/sd_status
+
+ chmod 0777 /data/data/emmc_status
+ chmod 0777 /data/data/emmc_size
+ chmod 0777 /data/data/emmc_fw
+ chmod 0777 /data/data/emmc_fw_version
+ chmod 0777 /data/data/emmc_total_size
+ chmod 0777 /data/data/sd_status
+# ASUS_BSP --- Lei_Guo "storage info for ATD and AMAX"
+
+# ASUS_BSP +++ Desmond "demoapp related"
+# Disable demoapp by default
+ setprop persist.sys.enableAPD 0
+# ASUS_BSP --- Desmond "demoapp related"
+
+# mount factory
+ wait /dev/block/bootdevice/by-name/factory
+ exec /system/bin/e2fsck -p /dev/block/bootdevice/by-name/factory
+ mount ext4 /dev/block/bootdevice/by-name/factory /factory ro nosuid nodev barrier=1 noauto_da_alloc
+ restorecon_recursive /factory
+ chmod 0775 /factory
+ chown root shell /factory
+
+ start CheckProp
+
+# mount asdf
+ wait /dev/block/bootdevice/by-name/asdf
+ exec /system/bin/e2fsck -p /dev/block/bootdevice/by-name/asdf
+ mount ext4 /dev/block/bootdevice/by-name/asdf /asdf nosuid nodev barrier=1
+ chmod 0777 /asdf
+ restorecon_recursive /asdf
+ start check_last
+
+#ASUS_BSP+++ [thomas]move from init.asus.debugtool.rc
+ chmod 0775 /data/log
+#ASUS_BSP--- [thomas]move from init.asus.debugtool.rc
+
+# ASUS Freeman add for BMMI test ++++
+ symlink /sys/bus/i2c/devices/5-0038/touch_status /data/data/touch_status
+ chmod 0777 /data/data/touch_status
+ symlink /sys/bus/i2c/devices/5-0038/update_progress /data/touch_update_progress
+ chmod 0777 /data/touch_update_progress
+ chown system system /sys/bus/i2c/devices/5-0038/fw_upgradeapp
+ chown system system /sys/bus/i2c/devices/5-0038/fw_version
+ chown system system /sys/bus/i2c/devices/5-0038/ftstprwreg
+ chown system system /sys/bus/i2c/devices/5-0038/fw_info
+ chown system system /sys/bus/i2c/devices/5-0038/ftresetic
+ chown system system /sys/bus/i2c/devices/5-0038/glove_mode
+ chown system system /proc/asus_touch_proximity_status
+# ASUS Freeman add for BMMI test ----
+
+# mount debugfs
+ mount debugfs debugfs /sys/kernel/debug
+
+#ASUS_BSP Deeo : add for Led test +++
+ rm /data/data/LedTest
+ symlink /system/bin/LedTest /data/data/LedTest
+ chmod 0777 /data/data/LedTest
+ chmod 0666 /sys/class/leds/red/brightness
+ chmod 0666 /sys/class/leds/green/brightness
+ chown system system /sys/class/leds/red/blink
+ chmod 0666 /sys/class/leds/red/blink
+ chown system system /sys/class/leds/green/blink
+ chmod 0666 /sys/class/leds/green/blink
+ chown system system /sys/class/leds/blue/blink
+ chmod 0666 /sys/class/leds/blue/blink
+ chown system system /sys/class/leds/mix/brightness
+ chmod 0666 /sys/class/leds/mix/brightness
+ chown system system /sys/class/leds/mix/blink
+ chmod 0666 /sys/class/leds/mix/blink
+#ASUS_BSP Deeo : add for Led test ---
+
#ASUS_BSP Jeff_Gu : add for Led blink time +++
chown system system /sys/class/leds/red/on_ms
chmod 0664 /sys/class/leds/red/on_ms
@@ -12,10 +173,55 @@ on post-fs-data
chmod 0664 /sys/class/leds/green/off_ms
#ASUS_BSP Jeff_Gu : add for Led blink time ---
- chown system camera /sys/class/leds/torch-light0/brightness
- chmod 0664 /sys/class/leds/torch-light0/brightness
- chown system camera /sys/class/leds/torch-light0/max_brightness
- chmod 0664 /sys/class/leds/torch-light0/max_brightness
+# +++ ASUS_BSP tyree_liu@asus.com symlink to AudioroutingTest
+ symlink /system/bin/AudioRoutingTest /data/data/AudioRoutingTest
+# --- ASUS_BSP tyree_liu@asus.com symlink to AudioroutingTest
+
+#ASUS_BSP David "[BAT]add BMMI interface for ATD"
+ symlink /proc/driver/charger_limit_enable /data/data/charger_limit_enable
+ symlink /proc/driver/chargerIC_status /data/data/chargerIC_status
+ symlink /proc/driver/gaugeIC_status /data/data/gaugeIC_status
+ symlink /sys/class/power_supply/battery/capacity /data/data/battery_status
+ symlink /sys/class/power_supply/battery/capacity /data/data/BatteryCapacity
+ symlink /proc/driver/bat_current /data/data/BatteryCurrent
+ symlink /proc/driver/bat_voltage /data/data/BatteryVoltage
+
+#ASUS_BSP+++ Bernard "link BLTest for ATD test"
+ chown system system /sys/class/leds/lcd-backlight/brightness
+ chmod 0664 /sys/class/leds/lcd-backlight/brightness
+ symlink /sys/class/leds/lcd-backlight/brightness /data/data/BLTest
+ chmod 777 /data/data/BLTest
+#ASUS_BSP--- Bernard "link BLTest for ATD test"
+
+#ASUS_BSP +++ Stimber_Hsueh "implement camera interface for ATD"
+ rm /data/data/camera_status
+ symlink /proc/driver/camera_status /data/data/camera_status
+ chmod 0777 /data/data/camera_status
+
+ rm /data/data/vga_status
+ symlink /proc/driver/vga_status /data/data/vga_status
+ chmod 0777 /data/data/vga_status
+
+ rm /data/data/GetRearCameraResolution
+ symlink /proc/driver/GetRearCameraResolution /data/data/GetRearCameraResolution
+ chmod 0777 /data/data/GetRearCameraResolution
+#ASUS_BSP --- Stimber_Hsueh "implement camera interface for ATD"
+
+#ASUS_BSP +++ PJ "implement CalibrationBackup interface for ATD&DIT"
+ rm /data/data/Camera_Unique_ID
+ symlink /system/bin/Camera_Unique_ID /data/data/Camera_Unique_ID
+ chmod 0777 /data/data/Camera_Unique_ID
+ chown system shell /data/data/Camera_Unique_ID
+ rm /data/data/BackupCalibrationData
+ symlink /system/bin/BackupCalibrationData /data/data/BackupCalibrationData
+ chmod 0777 /data/data/BackupCalibrationData
+ chown system shell /data/data/BackupCalibrationData
+ rm /data/data/RestoreCalibrationData
+ symlink /system/bin/RestoreCalibrationData /data/data/RestoreCalibrationData
+ chmod 0777 /data/data/RestoreCalibrationData
+ chown system shell /data/data/RestoreCalibrationData
+#ASUS_BSP --- PJ "implement CalibrationBackup interface for ATD&DIT"
+
#ASUS_BSP +++ srhuang "Hall Sensor"
symlink /sys/bus/platform/devices/soc.0/hall_sensor/hall_sensor/status /data/data/hallsensor_status
@@ -94,24 +300,463 @@ on post-fs-data
chmod 0774 /sys/bus/i2c/devices/0-000f/Gsensor_raw
chmod 0774 /sys/bus/i2c/devices/0-000f/Gsensor_status
+#ASUS BSP:Enter_Zhang+++
+ chown root system /proc/bootinfo
+#ASUS BSP:Enter_Zhang---
+
+#----------------------------------------------------------------------
+# touch fw update service
+#----------------------------------------------------------------------
+# ASUS BSP Freeman:for firmware updata+++
+service FWAuto /system/bin/fw_auto_update
+# class main
+ user root
+ group root
+ oneshot
+ disabled
+seclabel u:r:FWAuto:s0
+#ASUS BSP Freeman:for firmware update --------
+
+#----------------------------------------------------------------------
+# change touch node authority
+#----------------------------------------------------------------------
+# ASUS BSP Freeman:change touch node authority+++
+service Nodeauthority /system/bin/touch_node_authority.sh
+ class late_start
+ user root
+ group root
+ oneshot
+#ASUS BSP Freeman:change touch node authority --------
+
+#----------------------------------------------------------------------
+# set color id prop by idcode.sh
+#----------------------------------------------------------------------
+# ASUS BSP Freeman:get color id+++
+service Colorid /system/bin/idcode.sh
+ class late_start
+ user root
+ oneshot
+ seclabel u:r:Colorid:s0
+#ASUS BSP Freeman:get color id --------
+
+# ASUS_BSP +++ Desmond "demoapp related"
+# Disable demoapp by default
+ setprop persist.sys.enableAPD 0
+# ASUS_BSP --- Desmond "demoapp related"
+
# adding Ecompass service
#+++ ASUS Alian_Shen "[ZC500KL]akmd"
-service akmd /system/bin/akmd09911 -m 4
-service akmd /system/bin/akmd09911 -m 1
+#service akmd /system/bin/akmd09911 -m 4
+#service akmd /system/bin/akmd09911 -m 1
+#--- ASUS Alian_Shen "[ZC500KL]akmd"
+# class core
+# user system
+# group system misc input
+# oneshot
+
+#+++ ASUS Alian_Shen "[ZC500KL]akmd"
+#service akmd_fac /system/bin/akmd09911 -s -f -m 1
+# class late_start
+# user system
+# group system misc input
+# disabled
+# oneshot
#--- ASUS Alian_Shen "[ZC500KL]akmd"
+# ASUS_BSP --- Peter_Lu "Akm09911 compass sensor & KX022 Gsensor"
+
+#ASUS_BSP+++ Chance "add for factory check MAC Addr"
+
+service btwifimac /system/bin/sh /system/etc/btwifimac.sh
class core
- user system
- group system misc input
+ user root
+ group root
oneshot
-#+++ ASUS Alian_Shen "[ZC500KL]akmd"
-service akmd_fac /system/bin/akmd09911 -s -f -m 1
+service save-hcidump /system/bin/sh /system/etc/init.asus.hcidump.sh
class late_start
- user system
- group system misc input
+ user root
+ group root
disabled
oneshot
-#--- ASUS Alian_Shen "[ZC500KL]akmd"
-# ASUS_BSP --- Peter_Lu "Akm09911 compass sensor & KX022 Gsensor"
+on property:init.svc.save-hcidump=stopped
+ setprop debug.bluetooth.btsnoop false
+ chmod 775 /data/logcat_log
+#ASUS_BSP--- Chance "add for factory check MAC Addr"
+
+# ASUS Freeman add for glove mode switch
+service asusglove /system/bin/sh /system/etc/init.asus.glove.sh
+# class core
+ oneshot
+ disabled
+
+on property:persist.asus.glove=*
+ start asusglove
+# ASUS Freeman ---
+
+# ASUS Freeman add for double click mode switch
+on property:persist.asus.dclick=0
+ write /sys/bus/i2c/devices/5-0038/dclick_mode 0
+on property:persist.asus.dclick=1
+ write /sys/bus/i2c/devices/5-0038/dclick_mode 1
+# ASUS Freeman ---
+
+# ASUS Freenan add for flipcover mode switch
+service asuscover /system/bin/sh /system/etc/init.asus.cover.sh
+# class core
+ oneshot
+ disabled
+
+on property:persist.asus.flipcovermode=*
+ start asuscover
+# ASUS Freeman ---
+
+# ASUS Freeman add for gesture mode switch
+service asusgesture /system/bin/sh /system/etc/init.asus.gesture.sh
+# class core
+ oneshot
+ disabled
+
+on property:persist.asus.gesture.type=*
+ start asusgesture
+# ASUS Freeman ---
+
+# ASUS Freeman add for enable touch check proximity before gesture wake up
+on property:persist.asus.chkproximity=0
+ write /sys/bus/i2c/devices/5-0038/Enable_Proximyty_Check 0
+on property:persist.asus.chkproximity=1
+ write /sys/bus/i2c/devices/5-0038/Enable_Proximyty_Check 1
+# ASUS Freeman ---
+
+#ASUS_BSP +++ widevine
+service ins_key /system/bin/install_key_server
+ class late_start
+ user root
+ group root
+ seclabel u:r:install_key_server:s0
+ disabled
+
+on property:atd.start.key.install=1
+ start ins_key
+
+on property:debug.check.keybox=1
+ start widevine
+
+service widevine /system/bin/sh /system/bin/widevine.sh
+ class late_start
+ disabled
+ oneshot
+#ASUS_BSP --- widevine
+
+# ASUS jacob add for NavigationBar mode switch
+on property:persist.asus.enable_navbar=1
+ setprop qemu.hw.mainkeys 0
+on property:persist.asus.enable_navbar=0
+ setprop qemu.hw.mainkeys 1
+# ASUS jacob ---
+
+
+on property:persist.usb.diag=1
+ insmod /system/lib/modules/diagchar.ko
+ stop adbd
+ start asus-usb-diag
+ start adbd
+
+on property:persist.usb.diag=0
+ start asus-usb-diag
+
+on property:sys.usb.config=rndis,diag,adb
+ write /sys/class/android_usb/android0/enable 0
+ write /sys/class/android_usb/android0/idVendor 05C6
+ write /sys/class/android_usb/android0/idProduct 902D
+ write /sys/class/android_usb/android0/f_diag/clients diag
+ write /sys/class/android_usb/android0/functions rndis,diag,adb
+ write /sys/class/android_usb/android0/enable 1
+ start adbd
+ setprop sys.usb.state ${sys.usb.config}
+
+#ASUS_BSP+++ jeffery_hu "[ZC550KL][restart][NA][NA] setup qpst download mode properity"
+on property:persist.sys.downloadmode.enable=1
+ write /sys/module/msm_poweroff/parameters/download_mode 1
+
+on property:persist.sys.downloadmode.enable=0
+ write /sys/module/msm_poweroff/parameters/download_mode 0
+#ASUS_BSP--- jeffery_hu "[ZC550KL][restart][NA][NA] setup qpst download mode properity"
+
+#ASUS_BSP+++ Deeo "filldata stress"
+service filldata /system/bin/filldata.sh
+ user root
+ group root
+ disabled
+ oneshot
+
+on property:persist.boot.filldata=1
+ start filldata
+
+on property:persist.boot.filldata=0
+ stop filldata
+#ASUS_BSP--- Deeo "filldata stress"
+
+#ASUS_BSP+++ Deeo "add fsstress"
+service fsstress /system/bin/fsstress-run.sh
+ user root
+ group root
+ disabled
+ oneshot
+
+on property:persist.boot.runfsstress=1
+ start fsstress
+
+on property:persist.boot.runfsstress=0
+ stop fsstress
+#ASUS_BSP--- Deeo "add fsstress"
+
+#ASUS_BSP+++ [thomas] enable user version debug
+service asusdebug /system/bin/sh /system/etc/prepare_asusdebug.sh
+ class late_start
+ oneshot
+ disabled
+on property:persist.asus.debug=1
+ export PATH /sbin:/vendor/bin:/system/sbin:/system/bin:/system/xbin:/data/debug
+ start asusdebug
+#ASUS_BSP--- [thomas] enable user version debug
+
+# +++ ASUS_BSP : add for asus boot animation partition
+#mount APD
+on property:persist.sys.enableAPD=1
+ wait /dev/block/bootdevice/by-name/APD
+ mount ext4 /dev/block/bootdevice/by-name/APD /APD nosuid nodev barrier=1 data=ordered
+ chmod 0775 /APD
+ chown system system /APD
+ restorecon_recursive /APD
+
+#unmount APD
+on property:persist.sys.enableAPD=0
+ start umount_apd
+# --- ASUS_BSP : add for asus boot animation partition
+
+#+++ASUS_BSP : add for charger mode to enable uart console , adb and mount asdf folder
+on charger-zc550kl
+ setprop sys.usb.config mass_storage
+#service qseecomd for facotry to check keybox
+ start qseecomd
+ wait /dev/block/bootdevice/by-name/persist
+ mount ext4 /dev/block/bootdevice/by-name/persist /persist nosuid nodev barrier=1
+ mkdir /persist/data 0700 system system
+ restorecon_recursive /persist
+
+ wait /dev/block/bootdevice/by-name/modem
+ mount vfat /dev/block/bootdevice/by-name/modem /firmware ro context=u:object_r:firmware_file:s0,shortname=lower,uid=1000,gid=1000,dmask=227,fmask=337
+ write /sys/kernel/boot_adsp/boot 1
+
+ wait /dev/block/bootdevice/by-name/factory
+ exec /system/bin/e2fsck -p /dev/block/bootdevice/by-name/factory
+ mount ext4 /dev/block/bootdevice/by-name/factory /factory ro nosuid nodev barrier=1 noauto_da_alloc
+ restorecon_recursive /factory
+ chmod 0775 /factory
+ chown system system /factory
+
+ start rmt_storage
+
+ chown root system /sys/class/power_supply/bms/current_now
+ chown root system /sys/class/power_supply/bms/voltage_ocv
+ chmod 0664 /sys/class/power_supply/bms/current_now
+ chmod 0664 /sys/class/power_supply/bms/voltage_ocv
+ start vm_bms
+ load_all_props
+ start qcom-post-boot
+ class_start charger
+#mount asdf
+ wait /dev/block/bootdevice/by-name/asdf
+ exec /system/bin/e2fsck -p /dev/block/bootdevice/by-name/asdf
+ mount ext4 /dev/block/bootdevice/by-name/asdf /asdf nosuid nodev barrier=1
+
+ write /proc/asusevtlog "ASDF: Check LastShutdown log."
+ write /proc/asusdebug get_asdf_log
+ write /proc/asusevtlog "charger: enter charger mode"
+#---ASUS_BSP : add for charger mode to enable uart console , adb and mount asdf folder
+
+# +++ ASUS BSP : add for verify voucher
+service VerifyVouchers /system/bin/VerifyVouchers
+ user root
+ oneshot
+
+on property:sys.boot_completed=1
+ start VerifyVouchers
+# --- ASUS BSP : add for verify voucher
+
+
+# +++ ASUS_BSP : add for user unlock
+service writekey /system/bin/writekey
+ class core
+ oneshot
+ disabled
+
+on property:debug.write.asuskey=1
+ start writekey
+# --- ASUS_BSP : add for user unlock
+
+service asus-usb-diag /system/bin/sh /init.asus.usb.diag.sh
+ class main
+ user root
+ disabled
+ oneshot
+
+#+++ [ZC550KL] ASUS_BSP suri_gu@asus.com for screen off in factory mode when sys.screentimeout=1
+on property:sys.screentimeout=1
+ write /sys/class/leds/green/brightness 0
+ write /sys/class/leds/red/brightness 0
+ write /proc/driver/screenofftimeout 1
+
+on property:sys.screentimeout=0
+ write /proc/driver/screenofftimeout 0
+#--- [ZC550KL] ASUS_BSP
+
+# ASUS_BSP Guochang_Qiu add for SMMI/yepdiag factory service+++
+#SMMITool
+service openfactory /system/bin/sh /system/etc/openfactory.sh
+ class main
+ user root
+ oneshot
+
+#Yepdiag
+service yepdiag /system/bin/yepdiag
+ class main
+ user root
+ disabled
+ seclabel u:r:yepdiag:s0
+
+#excute the mmi function
+on property:sys.config.factorystart=1
+ start openfactory
+# ASUS_BSP Guochang_Qiu add for SMMI/yepdiag factory service ---
+
+#ASUS_BSP+++ ShowWang "[ZC550KL][USB][NA][Spec] Enable otg poweron switching"
+on property:persist.usb.otg.poweron=1
+ write /proc/msm_otg/otg_poweron 1
+
+on property:persist.usb.otg.poweron=0
+ write /proc/msm_otg/otg_poweron 0
+#ASUS_BSP--- ShowWang "[ZC550KL][USB][NA][Spec] Enable otg poweron switching"
+
+# +++ ASUS_BSP Lei_Guo : add for switch selinux +++
+on property:asus.logtool.sf=1
+ write /proc/rd asussetenforce:1
+
+on property:asus.logtool.sf=0
+ write /proc/rd asussetenforce:0
+# --- ASUS_BSP Lei_Guo : add for switch selinux ---
+
+# ASUS_BSP+++ ShowWang "add properties to check the otg at boot"
+on property:sys.boot_completed=1
+ write /proc/msm_otg/otg_boot_check 1
+# ASUS_BSP--- ShowWang "add properties to check the otg at boot"
+
+# ASUS_BSP---ShowWang "add configs to support HQ diag in factory mode"
+on diag
+#config diag driver
+ insmod /system/lib/modules/diagchar.ko
+ stop adbd
+ mkdir /dev/usb-ffs 0770 shell shell
+ mkdir /dev/usb-ffs/adb 0770 shell shell
+ mount functionfs adb /dev/usb-ffs/adb uid=2000,gid=2000
+ write /sys/class/android_usb/android0/f_ffs/aliases adb
+ write /sys/class/android_usb/android0/diag 1
+ write /sys/class/android_usb/android0/enable 0
+ write /sys/class/android_usb/android0/f_diag/clients diag
+ write /sys/class/android_usb/android0/f_serial/transports smd,tty
+ write /sys/class/android_usb/android0/functions diag,adb,serial
+ write /sys/class/android_usb/android0/iSerial C4ATAS000000
+ write /sys/class/android_usb/android0/enable 1
+ setprop sys.usb.diag 1
+ start adbd
+ start qcomsysd
+ start yepdiag
+
+on usb-config-none
+#config usb none
+ write /sys/class/android_usb/android0/enable 0
+ write /sys/class/android_usb/android0/functions mtp
+ write /sys/class/android_usb/android0/diag 1
+ write /sys/class/android_usb/android0/enable 1
+
+on system_mount
+#mount system partition
+ wait /dev/block/bootdevice/by-name/system
+ mount ext4 /dev/block/bootdevice/by-name/system /system ro barrier=1
+
+on property:sys.usb.charger.factory=0
+ stop adbd
+ write /sys/class/android_usb/android0/diag 0
+ write /sys/class/android_usb/android0/enable 0
+ write /sys/class/android_usb/android0/bDeviceClass 0
+ setprop sys.usb.config none
+# ASUS_BSP---ShowWang "add configs to support HQ diag in factory mode"
+
+# Enter_Zhang Add for sysconf +++
+on property:sys.config.klog=1
+ config_sys 7C89FDAB
+
+on property:sys.config.klog=0
+ config_sys 79ACB239
+
+on property:sys.config.uartlog=1
+ config_sys 7E8BDCA5
+
+on property:sys.config.uartlog=0
+ config_sys 768CF5D9
+
+# ASUS_BSP +++ johnchain_li switch factory/ship mode to modem by sys.factory.close
+service ModemFactory /system/bin/AsusCommandSpecial 51 1 01
+ user root
+ oneshot
+ disabled
+service ModemShip /system/bin/AsusCommandSpecial 51 1 00
+ user root
+ oneshot
+ disabled
+# ASUS_BSP --- johnchain_li switch factory/ship mode to modem by sys.factory.close
+on property:sys.factory.close=mmi_begin
+ start ModemFactory
+ setprop persist.sys.modem.restart 0
+ config_sys 72587539
+
+on property:sys.factory.close=mmi_end
+ start ModemShip
+ setprop persist.sys.modem.restart 12
+ config_sys 74521DC6
+
+on property:sys.factoryback.check=1
+ config_sys 75695362
+# Enter_Zhang Add for sysconf ---
+
+# ASUS_BSP +++ Peter_Lu "Copy Laser calibration data to factory partition in user device"
+on property:debug.asus.setfactorydata=1
+ mount ext4 /dev/block/bootdevice/by-name/factory /factory remount rw nosuid nodev barrier=1 noauto_da_alloc
+ copy /data/media/0/LaserFocus_Calibration10.txt /factory/LaserFocus_Calibration10.txt
+ copy /data/media/0/LaserFocus_Calibration40.txt /factory/LaserFocus_Calibration40.txt
+ copy /data/media/0/laura_cal_data.txt /factory/laura_cal_data.txt
+ chown media shell /factory/LaserFocus_Calibration10.txt
+ chown media shell /factory/LaserFocus_Calibration40.txt
+ chown media shell /factory/sdcard/laura_cal_data.txt
+ chmod 0664 /factory/LaserFocus_Calibration10.txt
+ chmod 0664 /factory/LaserFocus_Calibration40.txt
+ chmod 0664 /factory/laura_cal_data.txt
+ rm /data/media/0/LaserFocus_Calibration10.txt
+ rm /data/media/0/LaserFocus_Calibration40.txt
+ rm /data/media/0/laura_cal_data.txt
+ write /factory/LaserFocus_CSC_Calibration.txt "Calibration by CSC"
+ mount ext4 /dev/block/bootdevice/by-name/factory /factory remount ro nosuid nodev barrier=1 noauto_da_alloc
+# ASUS_BSP ---
+
+# +++ ASUS_BSP tyree_liu@asus.com for audio factory test
+service asus_audiotest /system/bin/sh /system/etc/audio.test.sh
+ user root
+ group root
+ disabled
+ oneshot
+ seclabel u:r:asus_audiotest:s0
+on property:persist.asus.audiotestenable=1
+ start asus_audiotest
+# --- ASUS_BSP tyree_liu@asus.com for audio factory test
diff --git a/sensors/AccelSensor.h b/sensors/AccelSensor.h
deleted file mode 100644
index b85a9bd..0000000
--- a/sensors/AccelSensor.h
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef ANDROID_ACCEL_SENSOR_H
-#define ANDROID_ACCEL_SENSOR_H
-
-#include <stdint.h>
-#include <errno.h>
-#include <sys/cdefs.h>
-#include <sys/types.h>
-
-#include "SensorBase.h"
-#include "InputEventReader.h"
-#include "NativeSensorManager.h"
-
-/*****************************************************************************/
-
-struct input_event;
-
-class AccelSensor : public SensorBase {
- int mEnabled;
- InputEventCircularReader mInputReader;
- sensors_event_t mPendingEvent;
- bool mHasPendingEvent;
- char input_sysfs_path[PATH_MAX];
- int input_sysfs_path_len;
- int64_t mEnabledTime;
-
- int setInitialState();
-
-public:
- AccelSensor();
- AccelSensor(char *name);
- AccelSensor(struct SensorContext *context);
- virtual ~AccelSensor();
- virtual int readEvents(sensors_event_t* data, int count);
- virtual bool hasPendingEvents() const;
- virtual int setDelay(int32_t handle, int64_t ns);
- virtual int enable(int32_t handle, int enabled);
- virtual int calibrate(int32_t handle, struct cal_cmd_t *para,
- struct cal_result_t *cal_result);
- virtual int initCalibrate(int32_t handle, struct cal_result_t *cal_result);
-};
-
-/*****************************************************************************/
-
-#endif // ANDROID_ACCEL_SENSOR_H
diff --git a/sensors/Accelerometer.cpp b/sensors/Accelerometer.cpp
deleted file mode 100644
index 78c402f..0000000
--- a/sensors/Accelerometer.cpp
+++ /dev/null
@@ -1,376 +0,0 @@
-/*
- * Copyright (c) 2014, The Linux Foundation. All rights reserved.
- * Not a Contribution.
- * Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <fcntl.h>
-#include <errno.h>
-#include <math.h>
-#include <poll.h>
-#include <unistd.h>
-#include <dirent.h>
-#include <sys/select.h>
-#include <cutils/log.h>
-#include <cutils/properties.h>
-#include <stdlib.h>
-#include "AccelSensor.h"
-#include "sensors.h"
-
-#define FETCH_FULL_EVENT_BEFORE_RETURN 1
-#define IGNORE_EVENT_TIME 10000000
-
-#define EVENT_TYPE_ACCEL_X ABS_X
-#define EVENT_TYPE_ACCEL_Y ABS_Y
-#define EVENT_TYPE_ACCEL_Z ABS_Z
-
-#define ACCEL_CONVERT ((GRAVITY_EARTH) / 16384) /* (4 * 1G / 2^16) */
-#define CONVERT_ACCEL_X ACCEL_CONVERT
-#define CONVERT_ACCEL_Y ACCEL_CONVERT
-#define CONVERT_ACCEL_Z ACCEL_CONVERT
-
-#define SYSFS_I2C_SLAVE_PATH "/device/device/"
-#define SYSFS_INPUT_DEV_PATH "/device/"
-
-/*****************************************************************************/
-
-AccelSensor::AccelSensor()
- : SensorBase(NULL, "accelerometer"),
- mEnabled(0),
- mInputReader(6),
- mHasPendingEvent(false),
- mEnabledTime(0)
-{
- mPendingEvent.version = sizeof(sensors_event_t);
- mPendingEvent.sensor = SENSORS_ACCELERATION_HANDLE;
- mPendingEvent.type = SENSOR_TYPE_ACCELEROMETER;
- memset(mPendingEvent.data, 0, sizeof(mPendingEvent.data));
-
- if (data_fd) {
- strlcpy(input_sysfs_path, "/sys/class/input/", sizeof(input_sysfs_path));
- strlcat(input_sysfs_path, input_name, sizeof(input_sysfs_path));
- strlcat(input_sysfs_path, SYSFS_I2C_SLAVE_PATH, sizeof(input_sysfs_path));
- input_sysfs_path_len = strlen(input_sysfs_path);
- enable(0, 1);
- }
-}
-
-AccelSensor::AccelSensor(char *name)
- : SensorBase(NULL, "accelerometer"),
- mEnabled(0),
- mInputReader(6),
- mHasPendingEvent(false),
- mEnabledTime(0)
-{
- mPendingEvent.version = sizeof(sensors_event_t);
- mPendingEvent.sensor = SENSORS_ACCELERATION_HANDLE;
- mPendingEvent.type = SENSOR_TYPE_ACCELEROMETER;
- memset(mPendingEvent.data, 0, sizeof(mPendingEvent.data));
-
- if (data_fd) {
- strlcpy(input_sysfs_path, SYSFS_CLASS, sizeof(input_sysfs_path));
- strlcat(input_sysfs_path, name, sizeof(input_sysfs_path));
- strlcat(input_sysfs_path, "/", sizeof(input_sysfs_path));
- input_sysfs_path_len = strlen(input_sysfs_path);
- ALOGI("The accel sensor path is %s",input_sysfs_path);
- enable(0, 1);
- }
-}
-
-AccelSensor::AccelSensor(SensorContext *context)
- : SensorBase(NULL, NULL),
- mEnabled(0),
- mInputReader(6),
- mHasPendingEvent(false),
- mEnabledTime(0)
-{
- mPendingEvent.version = sizeof(sensors_event_t);
- mPendingEvent.sensor = context->sensor->handle;
- mPendingEvent.type = SENSOR_TYPE_ACCELEROMETER;
- memset(mPendingEvent.data, 0, sizeof(mPendingEvent.data));
-
- strlcpy(input_sysfs_path, context->enable_path, sizeof(input_sysfs_path));
- input_sysfs_path_len = strlen(input_sysfs_path);
- data_fd = context->data_fd;
- ALOGI("The accel sensor path is %s",input_sysfs_path);
- mUseAbsTimeStamp = false;
- enable(0, 1);
-}
-
-AccelSensor::~AccelSensor() {
- if (mEnabled) {
- enable(0, 0);
- }
-}
-
-int AccelSensor::enable(int32_t, int en) {
- int flags = en ? 1 : 0;
- char propBuf[PROPERTY_VALUE_MAX];
- property_get("sensors.accel.loopback", propBuf, "0");
- if (strcmp(propBuf, "1") == 0) {
- ALOGE("sensors.accel.loopback is set");
- mEnabled = flags;
- return 0;
- }
-
- if (flags != mEnabled) {
- int fd;
- strlcpy(&input_sysfs_path[input_sysfs_path_len],
- SYSFS_ENABLE, SYSFS_MAXLEN);
- fd = open(input_sysfs_path, O_RDWR);
- if (fd >= 0) {
- char buf[2];
- int err;
- buf[1] = 0;
- if (flags) {
- buf[0] = '1';
- mEnabledTime = getTimestamp() + IGNORE_EVENT_TIME;
- } else {
- buf[0] = '0';
- }
- err = write(fd, buf, sizeof(buf));
- close(fd);
- mEnabled = flags;
- return 0;
- }
- ALOGE("AccelSensor: failed to open %s", input_sysfs_path);
- return -1;
- }
- return 0;
-}
-
-bool AccelSensor::hasPendingEvents() const {
- return mHasPendingEvent;
-}
-
-int AccelSensor::setDelay(int32_t, int64_t delay_ns)
-{
- int fd;
- char propBuf[PROPERTY_VALUE_MAX];
- property_get("sensors.accel.loopback", propBuf, "0");
- if (strcmp(propBuf, "1") == 0) {
- ALOGE("sensors.accel.loopback is set");
- return 0;
- }
- int delay_ms = delay_ns / 1000000;
- strlcpy(&input_sysfs_path[input_sysfs_path_len],
- SYSFS_POLL_DELAY, SYSFS_MAXLEN);
- fd = open(input_sysfs_path, O_RDWR);
- if (fd >= 0) {
- char buf[80];
- sprintf(buf, "%d", delay_ms);
- write(fd, buf, strlen(buf)+1);
- close(fd);
- return 0;
- }
- return -1;
-}
-
-int AccelSensor::readEvents(sensors_event_t* data, int count)
-{
- if (count < 1)
- return -EINVAL;
-
- if (mHasPendingEvent) {
- mHasPendingEvent = false;
- mPendingEvent.timestamp = getTimestamp();
- *data = mPendingEvent;
- return mEnabled ? 1 : 0;
- }
-
- ssize_t n = mInputReader.fill(data_fd);
- if (n < 0)
- return n;
-
- int numEventReceived = 0;
- input_event const* event;
-
-#if FETCH_FULL_EVENT_BEFORE_RETURN
-again:
-#endif
- while (count && mInputReader.readEvent(&event)) {
- int type = event->type;
- if (type == EV_ABS) {
- float value = event->value;
- if (event->code == EVENT_TYPE_ACCEL_X) {
- mPendingEvent.data[0] = value * CONVERT_ACCEL_X;
- } else if (event->code == EVENT_TYPE_ACCEL_Y) {
- mPendingEvent.data[1] = value * CONVERT_ACCEL_Y;
- } else if (event->code == EVENT_TYPE_ACCEL_Z) {
- mPendingEvent.data[2] = value * CONVERT_ACCEL_Z;
- }
- } else if (type == EV_SYN) {
- switch ( event->code ){
- case SYN_TIME_SEC:
- {
- mUseAbsTimeStamp = true;
- report_time = event->value*1000000000LL;
- }
- break;
- case SYN_TIME_NSEC:
- {
- mUseAbsTimeStamp = true;
- mPendingEvent.timestamp = report_time+event->value;
- }
- break;
- case SYN_REPORT:
- {
- if (mEnabled && mUseAbsTimeStamp) {
- if(mPendingEvent.timestamp >= mEnabledTime) {
- *data++ = mPendingEvent;
- numEventReceived++;
- }
- count--;
- mUseAbsTimeStamp = false;
- } else {
- ALOGE_IF(!mUseAbsTimeStamp, "AccelSensor:timestamp not received");
- }
- }
- break;
- }
- } else {
- ALOGE("AccelSensor: unknown event (type=%d, code=%d)",
- type, event->code);
- }
- mInputReader.next();
- }
-
-#if FETCH_FULL_EVENT_BEFORE_RETURN
- /* if we didn't read a complete event, see if we can fill and
- try again instead of returning with nothing and redoing poll. */
- if (numEventReceived == 0 && mEnabled == 1) {
- n = mInputReader.fill(data_fd);
- if (n)
- goto again;
- }
-#endif
-
- return numEventReceived;
-}
-
-int AccelSensor::calibrate(int32_t handle, struct cal_cmd_t *para,
- struct cal_result_t *cal_result)
-{
- int fd;
- char temp[3][LENGTH];
- char buf[3 * LENGTH];
- char *token, *strsaveptr, *endptr;
- int i, err;
- off_t offset;
- int para1 = 0;
- if (para == NULL || cal_result == NULL) {
- ALOGE("Null pointer calibrate parameters\n");
- return -1;
- }
- para1 = CMD_CAL(para->axis, para->apply_now);
- strlcpy(&input_sysfs_path[input_sysfs_path_len],
- SYSFS_CALIBRATE, SYSFS_MAXLEN);
- fd = open(input_sysfs_path, O_RDWR);
- if (fd >= 0) {
- snprintf(buf, sizeof(buf), "%d", para1);
- write(fd, buf, strlen(buf)+1);
- } else {
- ALOGE("open %s failed\n", input_sysfs_path);
- return -1;
- }
- if (fd >= 0) {
- offset = lseek(fd, 0, SEEK_SET);
- char *p = buf;
- memset(buf, 0, sizeof(buf));
- err = read(fd, buf, sizeof(buf)-1);
- if(err < 0) {
- ALOGE("read error\n");
- close(fd);
- return err;
- }
- for(i = 0; i < sizeof(temp) / LENGTH; i++, p = NULL) {
- token = strtok_r(p, ",", &strsaveptr);
- if(token == NULL)
- break;
- if(strlen(token) > LENGTH - 1) {
- ALOGE("token is too long\n");
- close(fd);
- return -1;
- }
- strlcpy(temp[i], token, sizeof(temp[i]));
- }
- close(fd);
- for(int i = 0; i < sizeof(temp) / LENGTH; i++) {
- cal_result->offset[i] = strtol(temp[i], &endptr, 10);
- if (cal_result->offset[i] == LONG_MAX || cal_result->offset[i] == LONG_MIN) {
- ALOGE("cal_result->offset[%d] error value\n", i);
- return -1;
- }
- if (endptr == temp[i]) {
- ALOGE("No digits were found\n");
- return -1;
- }
- }
- return 0;
- } else {
- ALOGE("open %s error\n", input_sysfs_path);
- return -1;
- }
- return 0;
-}
-
-int AccelSensor::initCalibrate(int32_t handle, struct cal_result_t *cal_result)
-{
- int fd, i, err;
- char buf[LENGTH];
- int arry[] = {CMD_W_OFFSET_X, CMD_W_OFFSET_Y, CMD_W_OFFSET_Z};
- if (cal_result == NULL) {
- ALOGE("Null pointer initcalibrate parameter\n");
- return -1;
- }
- strlcpy(&input_sysfs_path[input_sysfs_path_len],
- SYSFS_CALIBRATE, SYSFS_MAXLEN);
- fd = open(input_sysfs_path, O_RDWR);
- if (fd >= 0) {
- int para1 = 0;
- for(i = 0; i < sizeof(arry) / sizeof(int); ++i) {
- para1 = SET_CMD_H(cal_result->offset[i], arry[i]);
- snprintf(buf, sizeof(buf), "%d", para1);
- err = write(fd, buf, strlen(buf)+1);
- if(err < 0) {
- ALOGE("write error\n");
- close(fd);
- return err;
- }
-
- memset(buf, 0, sizeof(buf));
- para1 = SET_CMD_L(cal_result->offset[i], arry[i]);
- snprintf(buf, sizeof(buf), "%d", para1);
- err = write(fd, buf, strlen(buf)+1);
- if(err < 0) {
- ALOGE("write error\n");
- close(fd);
- return err;
- }
- }
- memset(buf, 0, sizeof(buf));
- snprintf(buf, sizeof(buf), "%d", CMD_COMPLETE);
- err = write(fd, buf, strlen(buf)+1);
- if(err < 0) {
- ALOGE("write error\n");
- close(fd);
- return err;
- }
- close(fd);
- return 0;
- }
- ALOGE("open %s error\n", input_sysfs_path);
- return -1;
-}
diff --git a/sensors/Android.mk b/sensors/Android.mk
deleted file mode 100644
index 8a70156..0000000
--- a/sensors/Android.mk
+++ /dev/null
@@ -1,61 +0,0 @@
-LOCAL_PATH := $(call my-dir)
-
-include $(CLEAR_VARS)
-
-LOCAL_MODULE := sensors.$(TARGET_BOARD_PLATFORM)
-LOCAL_MODULE_RELATIVE_PATH := hw
-LOCAL_MODULE_TAGS := optional
-
-LOCAL_CFLAGS += -DLOG_TAG=\"Sensors\"
-
-LOCAL_C_INCLUDES := $(TARGET_OUT_INTERMEDIATES)/KERNEL_OBJ/usr/include
-LOCAL_ADDITIONAL_DEPENDENCIES := $(TARGET_OUT_INTERMEDIATES)/KERNEL_OBJ/usr
-
-LOCAL_SRC_FILES := \
- sensors.cpp \
- SensorBase.cpp \
- LightSensor.cpp \
- ProximitySensor.cpp \
- CompassSensor.cpp \
- Accelerometer.cpp \
- Gyroscope.cpp \
- InputEventReader.cpp \
- CalibrationManager.cpp \
- NativeSensorManager.cpp \
- VirtualSensor.cpp \
- sensors_XML.cpp
-
-LOCAL_C_INCLUDES += external/libxml2/include \
- external/icu/icu4c/source/common
-
-LOCAL_SHARED_LIBRARIES := liblog libcutils libdl libxml2 libutils
-
-include $(BUILD_SHARED_LIBRARY)
-
-include $(CLEAR_VARS)
-
-LOCAL_MODULE := libcalmodule_common
-LOCAL_SRC_FILES := \
- algo/common/common_wrapper.c \
- algo/common/compass/AKFS_AOC.c \
- algo/common/compass/AKFS_Device.c \
- algo/common/compass/AKFS_Direction.c \
- algo/common/compass/AKFS_VNorm.c
-
-LOCAL_SHARED_LIBRARIES := liblog libcutils
-LOCAL_MODULE_TAGS := optional
-
-LOCAL_MODULE_PATH_32 := $(TARGET_OUT_VENDOR)/lib
-LOCAL_MODULE_PATH_64 := $(TARGET_OUT_VENDOR)/lib64
-
-include $(BUILD_SHARED_LIBRARY)
-
-include $(CLEAR_VARS)
-
-LOCAL_MODULE := calmodule.cfg
-LOCAL_MODULE_TAGS := optional
-LOCAL_MODULE_CLASS := ETC
-LOCAL_MODULE_PATH := $(TARGET_OUT_VENDOR_ETC)
-LOCAL_SRC_FILES := calmodule.cfg
-
-include $(BUILD_PREBUILT)
diff --git a/sensors/CalibrationManager.cpp b/sensors/CalibrationManager.cpp
deleted file mode 100644
index cb43097..0000000
--- a/sensors/CalibrationManager.cpp
+++ /dev/null
@@ -1,248 +0,0 @@
-/*--------------------------------------------------------------------------
-Copyright (c) 2014, The Linux Foundation. All rights reserved.
-
-Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions are
-met:
- * Redistributions of source code must retain the above copyright
- notice, this list of conditions and the following disclaimer.
- * Redistributions in binary form must reproduce the above
- copyright notice, this list of conditions and the following
- disclaimer in the documentation and/or other materials provided
- with the distribution.
- * Neither the name of The Linux Foundation nor the names of its
- contributors may be used to endorse or promote products derived
- from this software without specific prior written permission.
-
-THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
-WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
-MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
-ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
-BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
-CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
-SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
-BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
-OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
-IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
---------------------------------------------------------------------------*/
-
-#include <errno.h>
-
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <dlfcn.h>
-
-#include <utils/Log.h>
-#include <CalibrationModule.h>
-#include "sensors.h"
-#include "CalibrationManager.h"
-
-ANDROID_SINGLETON_STATIC_INSTANCE(CalibrationManager);
-
-int CalibrationManager::check_algo(const sensor_cal_algo_t *list)
-{
- if (list->tag != SENSOR_CAL_ALGO_TAG)
- return -1;
- if ((list->type < SENSOR_TYPE_ACCELEROMETER) ||
- (list->type > SENSOR_TYPE_GEOMAGNETIC_ROTATION_VECTOR))
- return -1;
- if (list->compatible == NULL)
- return -1;
- if (list->module == NULL)
- return -1;
- if (list->methods == NULL)
- return -1;
- if (list->methods->convert == NULL)
- return -1;
- return 0;
-}
-
-/* Return 0 on success */
-void CalibrationManager::loadCalLibs()
-{
- int fd;
- size_t len;
- char buf[MAX_CAL_CFG_LEN];
- char* cal_libs[MAX_CAL_LIBS];
- struct sensor_cal_module_t* modules[MAX_CAL_LIBS];
- int i = 0;
- int count;
- int tmp;
-
- algo_count = 0;
- algo_list = NULL;
-
- cal_libs[0] = strdup(DEFAULT_CAL_LIB);
- cal_libs[1] = NULL;
- count = 1;
-
- fd = open(CAL_LIB_CFG_PATH, O_RDONLY);
- if (fd < 0) {
- ALOGE("Open %s failed.(%s)\nDrop to default calibration library.",
- CAL_LIB_CFG_PATH, strerror(errno));
- } else {
- len = read(fd, buf, MAX_CAL_CFG_LEN);
- if (len > 0) {
- char *save_ptr, *str, *token;
-
- buf[len] = '\0';
- for(str = buf; ;str = NULL) {
- token = strtok_r(str, "\n", &save_ptr);
- if (token == NULL)
- break;
- cal_libs[i++] = strdup(token);
- }
- cal_libs[i] = NULL;
- count = i;
- }
- }
-
- /* Load the libraries */
- for (i = 0; i < count; i++) {
- void* dso;
- char path[PATH_MAX];
-
- ALOGI("Found calibration library:%s\n", cal_libs[i]);
- strlcpy(path, CAL_LIB_PATH, sizeof(path));
- strlcat(path, cal_libs[i], sizeof(path));
- if (access(path, F_OK) != 0) {
- ALOGE("module %s doesn't exist(%s)", cal_libs[i], strerror(errno));
- modules[i] = NULL;
- free(cal_libs[i]);
- continue;
- }
-
- free(cal_libs[i]);
-
- dso = dlopen(path, RTLD_NOW);
- if (dso == NULL) {
- char const *err_str = dlerror();
- ALOGE("load module %s failed(%s)", path, err_str?err_str:"unknown");
- modules[i] = NULL;
- continue;
- }
-
- modules[i] = (sensor_cal_module_t*)dlsym(dso, SENSOR_CAL_MODULE_INFO_AS_STR);
- if (modules[i] == NULL) {
- ALOGE("Can't find symbol %s\n", SENSOR_CAL_MODULE_INFO_AS_STR);
- continue;
- }
-
- modules[i]->dso = dso;
-
- if (modules[i]->methods->init(modules[i])) {
- ALOGE("init %s failed\n", modules[i]->id);
- modules[i] = NULL;
- continue;
- }
- algo_count += modules[i]->number;
- }
-
- if (algo_count != 0) {
- tmp = 0;
-
- algo_list = new const sensor_cal_algo_t *[algo_count];
- /* Get the algo list */
- for (i = 0; i < count; i++) {
- const sensor_cal_algo_t *list;
- /* Success */
- if ((modules[i] != NULL) && (modules[i]->methods != NULL) &&
- (modules[i]->methods->get_algo_list != NULL) &&
- (modules[i]->methods->get_algo_list(&list) == 0)) {
- for (uint32_t j = 0; j < modules[i]->number; j++)
- algo_list[tmp + j] = &list[j];
-
- tmp += modules[i]->number;
- }
- }
- }
-
- dump();
-}
-
-CalibrationManager::CalibrationManager()
- :algo_list(NULL), algo_count(0)
-{
- loadCalLibs();
-}
-
-CalibrationManager::~CalibrationManager()
-{
- void *dso = NULL;
-
- /* The following resource clean up assumes the algorithms in algo_list
- * are listed in library sequence.
- * e.g. algo_list[0~3] are point to the lib_foo, algo_list[4~5] are point
- * to lib_bar.
- */
- if ((algo_list != NULL) && algo_count) {
- dso = algo_list[0]->module->dso;
- for (uint32_t i = 0; i < algo_count; i++) {
- if ((algo_list[i]->module) && (algo_list[i]->module->dso)) {
- if (dso != algo_list[i]->module->dso) {
- dlclose(dso);
- dso = algo_list[i]->module->dso;
- }
- }
- }
- dlclose(dso);
- delete[] algo_list;
- }
-}
-
-const sensor_cal_algo_t* CalibrationManager::getCalAlgo(const sensor_t *s/* = NULL*/)
-{
- uint32_t i = 0;
- int j = 0;
- const sensor_cal_algo_t **list = algo_list;
- const sensor_cal_algo_t *tmp = NULL;
-
- if (s == NULL) {
- ALOGW("No available algo found!");
- return NULL;
- }
-
- for (i = 0; i < algo_count; i++) {
- if ((list[i]->type != s->type) || check_algo(list[i]))
- continue;
- j = 0;
- while (list[i]->compatible[j] != NULL) {
- if (strcmp(list[i]->compatible[j], s->name) == 0)
- break;
- if (strcmp(list[i]->compatible[j], type_to_name(s->type)) == 0)
- tmp = list[i];
- j++;
- }
-
- /* Exactly compatible */
- if (list[i]->compatible[j] != NULL)
- break;
- }
-
- if (i != algo_count) {
- ALOGI("found exactly compatible algo for type %d", s->type);
- return list[i];
- }
-
- if (tmp != NULL)
- ALOGI("found compatible algo for type %d", s->type);
-
- return tmp;
-}
-
-void CalibrationManager::dump()
-{
- int j;
- uint32_t i;
-
- ALOGI("algo_count:%d\n", algo_count);
- for (i = 0; i < algo_count; i++) {
- ALOGI("\ntag:%d\tversion:%d\ttype:%d\n", algo_list[i]->tag, algo_list[i]->version, algo_list[i]->type);
- j = 0;
- while (algo_list[i]->compatible[j] != NULL) {
- ALOGI("compatible:%s\n", algo_list[i]->compatible[j++]);
- }
- }
-}
diff --git a/sensors/CalibrationManager.h b/sensors/CalibrationManager.h
deleted file mode 100644
index a968cf1..0000000
--- a/sensors/CalibrationManager.h
+++ /dev/null
@@ -1,71 +0,0 @@
-/*--------------------------------------------------------------------------
-Copyright (c) 2014, The Linux Foundation. All rights reserved.
-
-Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions are
-met:
- * Redistributions of source code must retain the above copyright
- notice, this list of conditions and the following disclaimer.
- * Redistributions in binary form must reproduce the above
- copyright notice, this list of conditions and the following
- disclaimer in the documentation and/or other materials provided
- with the distribution.
- * Neither the name of The Linux Foundation nor the names of its
- contributors may be used to endorse or promote products derived
- from this software without specific prior written permission.
-
-THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
-WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
-MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
-ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
-BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
-CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
-SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
-BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
-OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
-IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
---------------------------------------------------------------------------*/
-
-#ifndef _SENSOR_CALIBRATION_MANAGER_H
-#define _SENSOR_CALIBRATION_MANAGER_H
-
-#include <utils/Singleton.h>
-#include "CalibrationModule.h"
-
-using namespace android;
-
-#define MAX_CAL_LIBS 32
-#define MAX_CAL_CFG_LEN 1024
-
-/* Calibration library config files */
-#define CAL_LIB_CFG_PATH "/system/vendor/etc/calmodule.cfg"
-#define DEFAULT_CAL_LIB "libcalmodule_common.so"
-#if defined(__LP64__)
-#define CAL_LIB_PATH "/system/vendor/lib64/"
-#else
-#define CAL_LIB_PATH "/system/vendor/lib/"
-#endif
-
-class CalibrationManager : public Singleton<CalibrationManager> {
- public:
- /* Get the whole algo list provided by the calibration library */
- const sensor_cal_algo_t** getCalAlgoList();
- /* Retrive a compatible calibration algo for sensor specified by t */
- const sensor_cal_algo_t* getCalAlgo(const sensor_t *s);
- /* Dump the calibration manager status */
- void dump();
- ~CalibrationManager();
- private:
- friend class Singleton<CalibrationManager>;
- /* Check if the algo provided by list is compatible */
- static int check_algo(const sensor_cal_algo_t *list);
- CalibrationManager();
- void loadCalLibs();
- /* Point to a whole list of all the algo provided by calibration library */
- const sensor_cal_algo_t **algo_list;
- /* Number of algo */
- uint32_t algo_count;
-};
-
-#endif
diff --git a/sensors/CalibrationModule.h b/sensors/CalibrationModule.h
deleted file mode 100644
index 1226c24..0000000
--- a/sensors/CalibrationModule.h
+++ /dev/null
@@ -1,137 +0,0 @@
-/*--------------------------------------------------------------------------
-Copyright (c) 2014, The Linux Foundation. All rights reserved.
-
-Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions are
-met:
- * Redistributions of source code must retain the above copyright
- notice, this list of conditions and the following disclaimer.
- * Redistributions in binary form must reproduce the above
- copyright notice, this list of conditions and the following
- disclaimer in the documentation and/or other materials provided
- with the distribution.
- * Neither the name of The Linux Foundation nor the names of its
- contributors may be used to endorse or promote products derived
- from this software without specific prior written permission.
-
-THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
-WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
-MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
-ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
-BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
-CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
-SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
-BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
-OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
-IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
---------------------------------------------------------------------------*/
-
-#ifndef _SENSOR_CAL_H
-#define _SENSOR_CAL_H
-
-#include <sys/cdefs.h>
-#include <hardware/hardware.h>
-#include <hardware/sensors.h>
-
-__BEGIN_DECLS
-
-#define ACCELEROMETER_NAME "accelerometer"
-#define COMPASS_NAME "compass"
-#define ORIENTATION_NAME "orientation"
-#define GYROSCOPE_NAME "gyroscope"
-#define LIGHT_NAME "light"
-#define PRESSURE_NAME "pressure"
-#define TEMPERATURE_NAME "temperature"
-#define PROXIMITY_NAME "proximity"
-#define GRAVITY_NAME "gravity"
-#define LINEAR_ACCELERATION_NAME "liner_acceleration"
-#define ROTATION_VECTOR_NAME "rotation_vector"
-#define RELATIVE_HUMIDITY_NAME "relative_humidity"
-#define AMBIENT_TEMPERATURE_NAME "ambient_temperature"
-#define MAGNETIC_FIELD_UNCALIBRATED_NAME "magnetic_field_uncalibrated"
-#define GAME_ROTATION_VECTOR_NAME "game_rotation_vector"
-#define GYROSCOPE_UNCALIBRATED_NAME "gyroscope_uncalibrated"
-#define SIGNIFICANT_MOTION_NAME "significant_motion"
-#define STEP_COUNTER_NAME "step_counter"
-#define STEP_DETECTOR_NAME "step_detector"
-#define GEOMAGNETIC_ROTATION_VECTOR_NAME "geomagnetic_field"
-
-/* TAG for the module. Should be "scmt" */
-#define SENSOR_CAL_MODULE_TAG 0x746d6373
-#define SENSOR_CAL_ALGO_TAG 0x74616373
-
-/* Super symbol of the calibration lib */
-#define SENSOR_CAL_MODULE_INFO scmi
-#define SENSOR_CAL_MODULE_INFO_AS_STR "scmi"
-
-#define SENSOR_CAL_MODULE_VERSION 1
-
-enum {
- CMD_ENABLE = 0, /* Enable status changed */
- CMD_DELAY, /* Polling rate changed */
- CMD_BATCH, /* Batching parameter changed */
-};
-
-struct sensor_cal_algo_t;
-struct sensor_cal_module_t;
-
-struct sensor_algo_args {
- int enable;
- int delay_ms;
-};
-
-struct compass_algo_args {
- struct sensor_algo_args common;
- uint32_t reserved[16];
-};
-
-struct sensor_algo_methods_t {
- int (*convert)(sensors_event_t *raw, sensors_event_t *result, struct sensor_algo_args *args);
- /* Note that the config callback is called from a different thread as convert */
- int (*config)(int cmd, struct sensor_algo_args *args);
-};
-
-struct sensor_cal_methods_t {
- int (*init)(const struct sensor_cal_module_t* module);
- void (*deinit)();
- /* Return 0 on success */
- int (*get_algo_list)(const struct sensor_cal_algo_t **algo);
-};
-
-struct sensor_cal_algo_t {
- /* Tag of the algo */
- int tag;
- /* Version of the algo */
- int version;
- /* Type of sensor this algo supported*/
- int type;
- /* The compatible sensors */
- const char **compatible;
- /* Sensor calibration module */
- struct sensor_cal_module_t *module;
- /* Sensor algo methods */
- struct sensor_algo_methods_t *methods;
-};
-
-struct sensor_cal_module_t {
- /* Tag of the module */
- uint32_t tag;
- /* Id of the module */
- char *id;
- /* Version of the calibration module */
- uint32_t version;
- /* Vendor of the calibration lib */
- char *vendor;
- /* Point to the handle of this module */
- void *dso;
- /* Number of algos */
- uint32_t number;
- /* Callbacks of the calibration lib provided */
- struct sensor_cal_methods_t *methods;
- /* The compatible sensors list for this library */
- int reserved[6];
-};
-
-__END_DECLS
-#endif
diff --git a/sensors/CompassSensor.cpp b/sensors/CompassSensor.cpp
deleted file mode 100644
index 1f9ba3a..0000000
--- a/sensors/CompassSensor.cpp
+++ /dev/null
@@ -1,256 +0,0 @@
-/*--------------------------------------------------------------------------
-Copyright (c) 2014, The Linux Foundation. All rights reserved.
-
-Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions are met:
- * Redistributions of source code must retain the above copyright
- notice, this list of conditions and the following disclaimer.
- * Redistributions in binary form must reproduce the above copyright
- notice, this list of conditions and the following disclaimer in the
- documentation and/or other materials provided with the distribution.
- * Neither the name of The Linux Foundation nor
- the names of its contributors may be used to endorse or promote
- products derived from this software without specific prior written
- permission.
-
-THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
-CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
-EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
-PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
-OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
-OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
-ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
---------------------------------------------------------------------------*/
-
-#include <fcntl.h>
-#include <errno.h>
-#include <math.h>
-#include <poll.h>
-#include <unistd.h>
-#include <dirent.h>
-#include <sys/select.h>
-#include <cutils/log.h>
-
-#include "CompassSensor.h"
-#include "sensors.h"
-
-#define FETCH_FULL_EVENT_BEFORE_RETURN 1
-#define IGNORE_EVENT_TIME 10000000
-
-#define EVENT_TYPE_MAG_X ABS_X
-#define EVENT_TYPE_MAG_Y ABS_Y
-#define EVENT_TYPE_MAG_Z ABS_Z
-#define EVENT_TYPE_MAG_STATUS ABS_MISC
-
-#define EVENT_TYPE_YAW ABS_X
-#define EVENT_TYPE_PITCH ABS_Y
-#define EVENT_TYPE_ROLL ABS_Z
-
-// conversion of magnetic data to uT units
-#define CONVERT_MAG (1.0f/16.0f)
-
-/*****************************************************************************/
-CompassSensor::CompassSensor(struct SensorContext *context)
- : SensorBase(NULL, NULL, context),
- mEnabled(0),
- mInputReader(6),
- mHasPendingEvent(false),
- mEnabledTime(0),
- res(CONVERT_MAG)
-{
- int handle = -1;
-
- res = context->sensor->resolution;
-
- memset(mPendingEvent.data, 0, sizeof(mPendingEvent.data));
- mPendingEvent.version = sizeof(sensors_event_t);
- mPendingEvent.sensor = context->sensor->handle;
- mPendingEvent.type = SENSOR_TYPE_MAGNETIC_FIELD;
- mPendingEvent.magnetic.status = SENSOR_STATUS_UNRELIABLE;
-
- data_fd = context->data_fd;
- strlcpy(input_sysfs_path, context->enable_path, sizeof(input_sysfs_path));
- input_sysfs_path_len = strlen(input_sysfs_path);
-
- enable(0, 1);
-}
-
-CompassSensor::~CompassSensor() {
- if (mEnabled) {
- enable(0, 0);
- }
-}
-
-int CompassSensor::enable(int32_t, int en) {
- int flags = en ? 1 : 0;
- compass_algo_args arg;
- arg.common.enable = flags;
-
- if (flags != mEnabled) {
- int fd;
-
- if ((algo != NULL) && (algo->methods->config != NULL)) {
- if (algo->methods->config(CMD_ENABLE, (sensor_algo_args*)&arg)) {
- ALOGW("Calling enable config failed for compass");
- }
- }
-
- strlcpy(&input_sysfs_path[input_sysfs_path_len],
- SYSFS_ENABLE, SYSFS_MAXLEN);
- fd = open(input_sysfs_path, O_RDWR);
- if (fd >= 0) {
- char buf[2];
- int err;
- buf[1] = 0;
- if (flags) {
- buf[0] = '1';
- mEnabledTime = getTimestamp() + IGNORE_EVENT_TIME;
- } else {
- buf[0] = '0';
- }
- err = write(fd, buf, sizeof(buf));
- close(fd);
- mEnabled = flags;
- return 0;
- }
- ALOGE("CompassSensor: failed to open %s", input_sysfs_path);
- return -1;
- }
- return 0;
-}
-
-bool CompassSensor::hasPendingEvents() const {
- return mHasPendingEvent;
-}
-
-int CompassSensor::setDelay(int32_t, int64_t delay_ns)
-{
- int fd;
- int delay_ms = delay_ns / 1000000;
- compass_algo_args arg;
- arg.common.delay_ms = delay_ms;
-
- if ((algo != NULL) && (algo->methods->config != NULL)) {
- if (algo->methods->config(CMD_DELAY, (sensor_algo_args*)&arg)) {
- ALOGW("Calling delay config failed for compass");
- }
- }
-
- strlcpy(&input_sysfs_path[input_sysfs_path_len],
- SYSFS_POLL_DELAY, SYSFS_MAXLEN);
- fd = open(input_sysfs_path, O_RDWR);
- if (fd >= 0) {
- char buf[80];
- sprintf(buf, "%d", delay_ms);
- write(fd, buf, strlen(buf)+1);
- close(fd);
- return 0;
- }
- return -1;
-}
-
-int CompassSensor::readEvents(sensors_event_t* data, int count)
-{
- if (count < 1)
- return -EINVAL;
-
- if (mHasPendingEvent) {
- mHasPendingEvent = false;
- mPendingEvent.timestamp = getTimestamp();
- *data = mPendingEvent;
- return mEnabled ? 1 : 0;
- }
-
- ssize_t n = mInputReader.fill(data_fd);
- if (n < 0)
- return n;
-
- int numEventReceived = 0;
- input_event const* event;
- sensors_event_t raw, result;
-
-#if FETCH_FULL_EVENT_BEFORE_RETURN
-again:
-#endif
- while (count && mInputReader.readEvent(&event)) {
- int type = event->type;
- if (type == EV_ABS) {
- float value = event->value;
- if (event->code == EVENT_TYPE_MAG_X) {
- mPendingEvent.magnetic.x = value * res;
- } else if (event->code == EVENT_TYPE_MAG_Y) {
- mPendingEvent.magnetic.y = value * res;
- } else if (event->code == EVENT_TYPE_MAG_Z) {
- mPendingEvent.magnetic.z = value * res;
- }
- } else if (type == EV_SYN) {
- if (event->code == SYN_TIME_SEC) {
- mUseAbsTimeStamp = true;
- report_time = event->value*1000000000LL;
- } else if (event->code == SYN_TIME_NSEC) {
- mUseAbsTimeStamp = true;
- mPendingEvent.timestamp = report_time+event->value;
- } else if (mEnabled) {
- if (!mUseAbsTimeStamp) {
- ALOGE("CompassSensor: timestamp not received");
- } else if (mPendingEvent.timestamp >= mEnabledTime) {
- raw = mPendingEvent;
-
- if (algo != NULL) {
- if (algo->methods->convert(&raw, &result, NULL)) {
- ALOGW("Calibration in progress...");
- result = raw;
- result.magnetic.status = SENSOR_STATUS_UNRELIABLE;
- }
- } else {
- result = raw;
- }
-
- *data = result;
- data->version = sizeof(sensors_event_t);
- data->sensor = mPendingEvent.sensor;
- data->type = SENSOR_TYPE_MAGNETIC_FIELD;
- data->timestamp = mPendingEvent.timestamp;
-
- /* The raw data is stored inside sensors_event_t.data after
- * sensors_event_t.magnetic. Notice that the raw data is
- * required to composite the virtual sensor uncalibrated
- * magnetic field sensor.
- *
- * data[0~2]: calibrated magnetic field data.
- * data[3]: magnetic field data accuracy.
- * data[4~6]: uncalibrated magnetic field data.
- */
- data->data[4] = mPendingEvent.data[0];
- data->data[5] = mPendingEvent.data[1];
- data->data[6] = mPendingEvent.data[2];
-
- data++;
- numEventReceived++;
- }
- count--;
- }
- } else {
- ALOGE("CompassSensor: unknown event (type=%d, code=%d)",
- type, event->code);
- }
- mInputReader.next();
- }
-
-#if FETCH_FULL_EVENT_BEFORE_RETURN
- /* if we didn't read a complete event, see if we can fill and
- try again instead of returning with nothing and redoing poll. */
- if (numEventReceived == 0 && mEnabled == 1) {
- n = mInputReader.fill(data_fd);
- if (n)
- goto again;
- }
-#endif
-
- return numEventReceived;
-}
-
diff --git a/sensors/CompassSensor.h b/sensors/CompassSensor.h
deleted file mode 100644
index d33fdb1..0000000
--- a/sensors/CompassSensor.h
+++ /dev/null
@@ -1,66 +0,0 @@
-/*--------------------------------------------------------------------------
-Copyright (c) 2014, The Linux Foundation. All rights reserved.
-
-Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions are met:
- * Redistributions of source code must retain the above copyright
- notice, this list of conditions and the following disclaimer.
- * Redistributions in binary form must reproduce the above copyright
- notice, this list of conditions and the following disclaimer in the
- documentation and/or other materials provided with the distribution.
- * Neither the name of The Linux Foundation nor
- the names of its contributors may be used to endorse or promote
- products derived from this software without specific prior written
- permission.
-
-THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
-CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
-EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
-PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
-OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
-OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
-ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
---------------------------------------------------------------------------*/
-
-#ifndef ANDROID_COMPASS_SENSOR_H
-#define ANDROID_COMPASS_SENSOR_H
-
-#include <stdint.h>
-#include <errno.h>
-#include <sys/cdefs.h>
-#include <sys/types.h>
-
-#include "SensorBase.h"
-#include "InputEventReader.h"
-#include "NativeSensorManager.h"
-
-/*****************************************************************************/
-
-struct input_event;
-
-class CompassSensor : public SensorBase {
- int mEnabled;
- InputEventCircularReader mInputReader;
- sensors_event_t mPendingEvent;
- bool mHasPendingEvent;
- char input_sysfs_path[PATH_MAX];
- int input_sysfs_path_len;
- int64_t mEnabledTime;
- float res;
-
-public:
- CompassSensor(struct SensorContext *context);
- virtual ~CompassSensor();
- virtual int readEvents(sensors_event_t* data, int count);
- virtual bool hasPendingEvents() const;
- virtual int setDelay(int32_t handle, int64_t ns);
- virtual int enable(int32_t handle, int enabled);
-};
-
-/*****************************************************************************/
-
-#endif // ANDROID_COMPASS_SENSOR_H
diff --git a/sensors/GyroSensor.h b/sensors/GyroSensor.h
deleted file mode 100644
index 0fa2618..0000000
--- a/sensors/GyroSensor.h
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef ANDROID_GYRO_SENSOR_H
-#define ANDROID_GYRO_SENSOR_H
-
-#include <stdint.h>
-#include <errno.h>
-#include <sys/cdefs.h>
-#include <sys/types.h>
-
-#include "SensorBase.h"
-#include "InputEventReader.h"
-#include "NativeSensorManager.h"
-
-/*****************************************************************************/
-
-struct input_event;
-
-class GyroSensor : public SensorBase {
- int mEnabled;
- InputEventCircularReader mInputReader;
- sensors_event_t mPendingEvent;
- bool mHasPendingEvent;
- char input_sysfs_path[PATH_MAX];
- int input_sysfs_path_len;
- int64_t mEnabledTime;
-
- int setInitialState();
-
-public:
- GyroSensor();
- GyroSensor(char *name);
- GyroSensor(struct SensorContext *context);
- virtual ~GyroSensor();
- virtual int readEvents(sensors_event_t* data, int count);
- virtual bool hasPendingEvents() const;
- virtual int setDelay(int32_t handle, int64_t ns);
- virtual int enable(int32_t handle, int enabled);
-};
-
-/*****************************************************************************/
-
-#endif // ANDROID_GYRO_SENSOR_H
diff --git a/sensors/Gyroscope.cpp b/sensors/Gyroscope.cpp
deleted file mode 100644
index 3ae2cb8..0000000
--- a/sensors/Gyroscope.cpp
+++ /dev/null
@@ -1,278 +0,0 @@
-/*
- * Copyright (c) 2014, The Linux Foundation. All rights reserved.
- * Not a Contribution.
- * Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <fcntl.h>
-#include <errno.h>
-#include <math.h>
-#include <poll.h>
-#include <unistd.h>
-#include <dirent.h>
-#include <sys/select.h>
-#include <cutils/log.h>
-#include <cutils/properties.h>
-
-#include "GyroSensor.h"
-#include "sensors.h"
-
-#define GYRO_INPUT_DEV_NAME "gyroscope"
-
-#define FETCH_FULL_EVENT_BEFORE_RETURN 1
-#define IGNORE_EVENT_TIME 350000000
-
-#define EVENT_TYPE_GYRO_X ABS_RX
-#define EVENT_TYPE_GYRO_Y ABS_RY
-#define EVENT_TYPE_GYRO_Z ABS_RZ
-
-#define GYROSCOPE_CONVERT (M_PI / (180 * 16.4))
-#define CONVERT_GYRO_X (-GYROSCOPE_CONVERT)
-#define CONVERT_GYRO_Y ( GYROSCOPE_CONVERT)
-#define CONVERT_GYRO_Z (-GYROSCOPE_CONVERT)
-
-/*****************************************************************************/
-
-GyroSensor::GyroSensor()
- : SensorBase(NULL, GYRO_INPUT_DEV_NAME),
- mEnabled(0),
- mInputReader(6),
- mHasPendingEvent(false),
- mEnabledTime(0)
-{
- mPendingEvent.version = sizeof(sensors_event_t);
- mPendingEvent.sensor = SENSORS_GYROSCOPE_HANDLE;
- mPendingEvent.type = SENSOR_TYPE_GYROSCOPE;
- memset(mPendingEvent.data, 0, sizeof(mPendingEvent.data));
-
- if (data_fd) {
- strlcpy(input_sysfs_path, "/sys/class/input/", sizeof(input_sysfs_path));
- strlcat(input_sysfs_path, input_name, sizeof(input_sysfs_path));
- strlcat(input_sysfs_path, "/device/device/", sizeof(input_sysfs_path));
- input_sysfs_path_len = strlen(input_sysfs_path);
- enable(0, 1);
- }
-}
-
-GyroSensor::GyroSensor(struct SensorContext *context)
- : SensorBase(NULL, NULL),
- mEnabled(0),
- mInputReader(6),
- mHasPendingEvent(false),
- mEnabledTime(0)
-{
- mPendingEvent.version = sizeof(sensors_event_t);
- mPendingEvent.sensor = context->sensor->handle;
- mPendingEvent.type = SENSOR_TYPE_GYROSCOPE;
- memset(mPendingEvent.data, 0, sizeof(mPendingEvent.data));
- data_fd = context->data_fd;
- strlcpy(input_sysfs_path, context->enable_path, sizeof(input_sysfs_path));
- input_sysfs_path_len = strlen(input_sysfs_path);
- mUseAbsTimeStamp = false;
-
- enable(0, 1);
-}
-
-GyroSensor::GyroSensor(char *name)
- : SensorBase(NULL, GYRO_INPUT_DEV_NAME),
- mEnabled(0),
- mInputReader(6),
- mHasPendingEvent(false),
- mEnabledTime(0)
-{
- mPendingEvent.version = sizeof(sensors_event_t);
- mPendingEvent.sensor = SENSORS_GYROSCOPE_HANDLE;
- mPendingEvent.type = SENSOR_TYPE_GYROSCOPE;
- memset(mPendingEvent.data, 0, sizeof(mPendingEvent.data));
-
- if (data_fd) {
- strlcpy(input_sysfs_path, SYSFS_CLASS, sizeof(input_sysfs_path));
- strlcat(input_sysfs_path, name, sizeof(input_sysfs_path));
- strlcat(input_sysfs_path, "/", sizeof(input_sysfs_path));
- input_sysfs_path_len = strlen(input_sysfs_path);
- ALOGI("The gyroscope sensor path is %s",input_sysfs_path);
- enable(0, 1);
- }
-}
-
-GyroSensor::~GyroSensor() {
- if (mEnabled) {
- enable(0, 0);
- }
-}
-
-int GyroSensor::setInitialState() {
- struct input_absinfo absinfo_x;
- struct input_absinfo absinfo_y;
- struct input_absinfo absinfo_z;
- float value;
- if (!ioctl(data_fd, EVIOCGABS(EVENT_TYPE_GYRO_X), &absinfo_x) &&
- !ioctl(data_fd, EVIOCGABS(EVENT_TYPE_GYRO_Y), &absinfo_y) &&
- !ioctl(data_fd, EVIOCGABS(EVENT_TYPE_GYRO_Z), &absinfo_z)) {
- value = absinfo_x.value;
- mPendingEvent.data[0] = value * CONVERT_GYRO_X;
- value = absinfo_y.value;
- mPendingEvent.data[1] = value * CONVERT_GYRO_Y;
- value = absinfo_z.value;
- mPendingEvent.data[2] = value * CONVERT_GYRO_Z;
- mHasPendingEvent = true;
- }
- return 0;
-}
-
-int GyroSensor::enable(int32_t, int en) {
- int flags = en ? 1 : 0;
- char propBuf[PROPERTY_VALUE_MAX];
- property_get("sensors.gyro.loopback", propBuf, "0");
- if (strcmp(propBuf, "1") == 0) {
- mEnabled = flags;
- ALOGE("sensors.gyro.loopback is set");
- return 0;
- }
- if (flags != mEnabled) {
- int fd;
- strlcpy(&input_sysfs_path[input_sysfs_path_len],
- SYSFS_ENABLE, SYSFS_MAXLEN);
- fd = open(input_sysfs_path, O_RDWR);
- if (fd >= 0) {
- char buf[2];
- int err;
- buf[1] = 0;
- if (flags) {
- buf[0] = '1';
- mEnabledTime = getTimestamp() + IGNORE_EVENT_TIME;
- } else {
- buf[0] = '0';
- }
- err = write(fd, buf, sizeof(buf));
- close(fd);
- mEnabled = flags;
- setInitialState();
- return 0;
- }
- return -1;
- }
- return 0;
-}
-
-bool GyroSensor::hasPendingEvents() const {
- return mHasPendingEvent;
-}
-
-int GyroSensor::setDelay(int32_t, int64_t delay_ns)
-{
- int fd;
- char propBuf[PROPERTY_VALUE_MAX];
- property_get("sensors.gyro.loopback", propBuf, "0");
- if (strcmp(propBuf, "1") == 0) {
- ALOGE("sensors.gyro.loopback is set");
- return 0;
- }
- int delay_ms = delay_ns / 1000000;
- strlcpy(&input_sysfs_path[input_sysfs_path_len],
- SYSFS_POLL_DELAY, SYSFS_MAXLEN);
- fd = open(input_sysfs_path, O_RDWR);
- if (fd >= 0) {
- char buf[80];
- sprintf(buf, "%d", delay_ms);
- write(fd, buf, strlen(buf)+1);
- close(fd);
- return 0;
- }
- return -1;
-}
-
-int GyroSensor::readEvents(sensors_event_t* data, int count)
-{
- if (count < 1)
- return -EINVAL;
-
- if (mHasPendingEvent) {
- mHasPendingEvent = false;
- mPendingEvent.timestamp = getTimestamp();
- *data = mPendingEvent;
- return mEnabled ? 1 : 0;
- }
-
- ssize_t n = mInputReader.fill(data_fd);
- if (n < 0)
- return n;
-
- int numEventReceived = 0;
- input_event const* event;
-
-#if FETCH_FULL_EVENT_BEFORE_RETURN
-again:
-#endif
- while (count && mInputReader.readEvent(&event)) {
- int type = event->type;
- if (type == EV_ABS) {
- float value = event->value;
- if (event->code == EVENT_TYPE_GYRO_X) {
- mPendingEvent.data[0] = value * CONVERT_GYRO_X;
- } else if (event->code == EVENT_TYPE_GYRO_Y) {
- mPendingEvent.data[1] = value * CONVERT_GYRO_Y;
- } else if (event->code == EVENT_TYPE_GYRO_Z) {
- mPendingEvent.data[2] = value * CONVERT_GYRO_Z;
- }
- } else if (type == EV_SYN) {
- switch ( event->code ){
- case SYN_TIME_SEC:
- {
- mUseAbsTimeStamp = true;
- report_time = event->value*1000000000LL;
- }
- break;
- case SYN_TIME_NSEC:
- {
- mUseAbsTimeStamp = true;
- mPendingEvent.timestamp = report_time+event->value;
- }
- break;
- case SYN_REPORT:
- {
- if (mEnabled && mUseAbsTimeStamp) {
- if(mPendingEvent.timestamp >= mEnabledTime) {
- *data++ = mPendingEvent;
- numEventReceived++;
- }
- count--;
- mUseAbsTimeStamp = false;
- } else {
- ALOGE_IF(!mUseAbsTimeStamp, "GyroSensor:timestamp not received");
- }
- }
- break;
- }
- } else {
- ALOGE("GyroSensor: unknown event (type=%d, code=%d)",
- type, event->code);
- }
- mInputReader.next();
- }
-
-#if FETCH_FULL_EVENT_BEFORE_RETURN
- /* if we didn't read a complete event, see if we can fill and
- try again instead of returning with nothing and redoing poll. */
- if (numEventReceived == 0 && mEnabled == 1) {
- n = mInputReader.fill(data_fd);
- if (n)
- goto again;
- }
-#endif
-
- return numEventReceived;
-}
-
diff --git a/sensors/InputEventReader.cpp b/sensors/InputEventReader.cpp
deleted file mode 100644
index 4d9a148..0000000
--- a/sensors/InputEventReader.cpp
+++ /dev/null
@@ -1,89 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <stdint.h>
-#include <string.h>
-#include <errno.h>
-#include <unistd.h>
-#include <poll.h>
-
-#include <sys/cdefs.h>
-#include <sys/types.h>
-
-#include <linux/input.h>
-
-#include <cutils/log.h>
-
-#include "InputEventReader.h"
-
-/*****************************************************************************/
-
-struct input_event;
-
-InputEventCircularReader::InputEventCircularReader(size_t numEvents)
- : mBuffer(new input_event[numEvents * 2]),
- mBufferEnd(mBuffer + numEvents),
- mHead(mBuffer),
- mCurr(mBuffer),
- mFreeSpace(numEvents)
-{
-}
-
-InputEventCircularReader::~InputEventCircularReader()
-{
- delete [] mBuffer;
-}
-
-ssize_t InputEventCircularReader::fill(int fd)
-{
- size_t numEventsRead = 0;
- if (mFreeSpace) {
- const ssize_t nread = read(fd, mHead, mFreeSpace * sizeof(input_event));
- if (nread<0 || nread % sizeof(input_event)) {
- // we got a partial event!!
- return nread<0 ? -errno : -EINVAL;
- }
-
- numEventsRead = nread / sizeof(input_event);
- if (numEventsRead) {
- mHead += numEventsRead;
- mFreeSpace -= numEventsRead;
- if (mHead > mBufferEnd) {
- size_t s = mHead - mBufferEnd;
- memcpy(mBuffer, mBufferEnd, s * sizeof(input_event));
- mHead = mBuffer + s;
- }
- }
- }
-
- return numEventsRead;
-}
-
-ssize_t InputEventCircularReader::readEvent(input_event const** events)
-{
- *events = mCurr;
- ssize_t available = (mBufferEnd - mBuffer) - mFreeSpace;
- return available ? 1 : 0;
-}
-
-void InputEventCircularReader::next()
-{
- mCurr++;
- mFreeSpace++;
- if (mCurr >= mBufferEnd) {
- mCurr = mBuffer;
- }
-}
diff --git a/sensors/InputEventReader.h b/sensors/InputEventReader.h
deleted file mode 100644
index 254c00e..0000000
--- a/sensors/InputEventReader.h
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef ANDROID_INPUT_EVENT_READER_H
-#define ANDROID_INPUT_EVENT_READER_H
-
-#include <stdint.h>
-#include <errno.h>
-#include <sys/cdefs.h>
-#include <sys/types.h>
-
-/*****************************************************************************/
-
-struct input_event;
-
-class InputEventCircularReader
-{
- struct input_event* const mBuffer;
- struct input_event* const mBufferEnd;
- struct input_event* mHead;
- struct input_event* mCurr;
- ssize_t mFreeSpace;
-
-public:
- InputEventCircularReader(size_t numEvents);
- ~InputEventCircularReader();
- ssize_t fill(int fd);
- ssize_t readEvent(input_event const** events);
- void next();
-};
-
-/*****************************************************************************/
-
-#endif // ANDROID_INPUT_EVENT_READER_H
diff --git a/sensors/LICENSE b/sensors/LICENSE
deleted file mode 100644
index e06d208..0000000
--- a/sensors/LICENSE
+++ /dev/null
@@ -1,202 +0,0 @@
-Apache License
- Version 2.0, January 2004
- http://www.apache.org/licenses/
-
- TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
-
- 1. Definitions.
-
- "License" shall mean the terms and conditions for use, reproduction,
- and distribution as defined by Sections 1 through 9 of this document.
-
- "Licensor" shall mean the copyright owner or entity authorized by
- the copyright owner that is granting the License.
-
- "Legal Entity" shall mean the union of the acting entity and all
- other entities that control, are controlled by, or are under common
- control with that entity. For the purposes of this definition,
- "control" means (i) the power, direct or indirect, to cause the
- direction or management of such entity, whether by contract or
- otherwise, or (ii) ownership of fifty percent (50%) or more of the
- outstanding shares, or (iii) beneficial ownership of such entity.
-
- "You" (or "Your") shall mean an individual or Legal Entity
- exercising permissions granted by this License.
-
- "Source" form shall mean the preferred form for making modifications,
- including but not limited to software source code, documentation
- source, and configuration files.
-
- "Object" form shall mean any form resulting from mechanical
- transformation or translation of a Source form, including but
- not limited to compiled object code, generated documentation,
- and conversions to other media types.
-
- "Work" shall mean the work of authorship, whether in Source or
- Object form, made available under the License, as indicated by a
- copyright notice that is included in or attached to the work
- (an example is provided in the Appendix below).
-
- "Derivative Works" shall mean any work, whether in Source or Object
- form, that is based on (or derived from) the Work and for which the
- editorial revisions, annotations, elaborations, or other modifications
- represent, as a whole, an original work of authorship. For the purposes
- of this License, Derivative Works shall not include works that remain
- separable from, or merely link (or bind by name) to the interfaces of,
- the Work and Derivative Works thereof.
-
- "Contribution" shall mean any work of authorship, including
- the original version of the Work and any modifications or additions
- to that Work or Derivative Works thereof, that is intentionally
- submitted to Licensor for inclusion in the Work by the copyright owner
- or by an individual or Legal Entity authorized to submit on behalf of
- the copyright owner. For the purposes of this definition, "submitted"
- means any form of electronic, verbal, or written communication sent
- to the Licensor or its representatives, including but not limited to
- communication on electronic mailing lists, source code control systems,
- and issue tracking systems that are managed by, or on behalf of, the
- Licensor for the purpose of discussing and improving the Work, but
- excluding communication that is conspicuously marked or otherwise
- designated in writing by the copyright owner as "Not a Contribution."
-
- "Contributor" shall mean Licensor and any individual or Legal Entity
- on behalf of whom a Contribution has been received by Licensor and
- subsequently incorporated within the Work.
-
- 2. Grant of Copyright License. Subject to the terms and conditions of
- this License, each Contributor hereby grants to You a perpetual,
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
- copyright license to reproduce, prepare Derivative Works of,
- publicly display, publicly perform, sublicense, and distribute the
- Work and such Derivative Works in Source or Object form.
-
- 3. Grant of Patent License. Subject to the terms and conditions of
- this License, each Contributor hereby grants to You a perpetual,
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
- (except as stated in this section) patent license to make, have made,
- use, offer to sell, sell, import, and otherwise transfer the Work,
- where such license applies only to those patent claims licensable
- by such Contributor that are necessarily infringed by their
- Contribution(s) alone or by combination of their Contribution(s)
- with the Work to which such Contribution(s) was submitted. If You
- institute patent litigation against any entity (including a
- cross-claim or counterclaim in a lawsuit) alleging that the Work
- or a Contribution incorporated within the Work constitutes direct
- or contributory patent infringement, then any patent licenses
- granted to You under this License for that Work shall terminate
- as of the date such litigation is filed.
-
- 4. Redistribution. You may reproduce and distribute copies of the
- Work or Derivative Works thereof in any medium, with or without
- modifications, and in Source or Object form, provided that You
- meet the following conditions:
-
- (a) You must give any other recipients of the Work or
- Derivative Works a copy of this License; and
-
- (b) You must cause any modified files to carry prominent notices
- stating that You changed the files; and
-
- (c) You must retain, in the Source form of any Derivative Works
- that You distribute, all copyright, patent, trademark, and
- attribution notices from the Source form of the Work,
- excluding those notices that do not pertain to any part of
- the Derivative Works; and
-
- (d) If the Work includes a "NOTICE" text file as part of its
- distribution, then any Derivative Works that You distribute must
- include a readable copy of the attribution notices contained
- within such NOTICE file, excluding those notices that do not
- pertain to any part of the Derivative Works, in at least one
- of the following places: within a NOTICE text file distributed
- as part of the Derivative Works; within the Source form or
- documentation, if provided along with the Derivative Works; or,
- within a display generated by the Derivative Works, if and
- wherever such third-party notices normally appear. The contents
- of the NOTICE file are for informational purposes only and
- do not modify the License. You may add Your own attribution
- notices within Derivative Works that You distribute, alongside
- or as an addendum to the NOTICE text from the Work, provided
- that such additional attribution notices cannot be construed
- as modifying the License.
-
- You may add Your own copyright statement to Your modifications and
- may provide additional or different license terms and conditions
- for use, reproduction, or distribution of Your modifications, or
- for any such Derivative Works as a whole, provided Your use,
- reproduction, and distribution of the Work otherwise complies with
- the conditions stated in this License.
-
- 5. Submission of Contributions. Unless You explicitly state otherwise,
- any Contribution intentionally submitted for inclusion in the Work
- by You to the Licensor shall be under the terms and conditions of
- this License, without any additional terms or conditions.
- Notwithstanding the above, nothing herein shall supersede or modify
- the terms of any separate license agreement you may have executed
- with Licensor regarding such Contributions.
-
- 6. Trademarks. This License does not grant permission to use the trade
- names, trademarks, service marks, or product names of the Licensor,
- except as required for reasonable and customary use in describing the
- origin of the Work and reproducing the content of the NOTICE file.
-
- 7. Disclaimer of Warranty. Unless required by applicable law or
- agreed to in writing, Licensor provides the Work (and each
- Contributor provides its Contributions) on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
- implied, including, without limitation, any warranties or conditions
- of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
- PARTICULAR PURPOSE. You are solely responsible for determining the
- appropriateness of using or redistributing the Work and assume any
- risks associated with Your exercise of permissions under this License.
-
- 8. Limitation of Liability. In no event and under no legal theory,
- whether in tort (including negligence), contract, or otherwise,
- unless required by applicable law (such as deliberate and grossly
- negligent acts) or agreed to in writing, shall any Contributor be
- liable to You for damages, including any direct, indirect, special,
- incidental, or consequential damages of any character arising as a
- result of this License or out of the use or inability to use the
- Work (including but not limited to damages for loss of goodwill,
- work stoppage, computer failure or malfunction, or any and all
- other commercial damages or losses), even if such Contributor
- has been advised of the possibility of such damages.
-
- 9. Accepting Warranty or Additional Liability. While redistributing
- the Work or Derivative Works thereof, You may choose to offer,
- and charge a fee for, acceptance of support, warranty, indemnity,
- or other liability obligations and/or rights consistent with this
- License. However, in accepting such obligations, You may act only
- on Your own behalf and on Your sole responsibility, not on behalf
- of any other Contributor, and only if You agree to indemnify,
- defend, and hold each Contributor harmless for any liability
- incurred by, or claims asserted against, such Contributor by reason
- of your accepting any such warranty or additional liability.
-
- END OF TERMS AND CONDITIONS
-
- APPENDIX: How to apply the Apache License to your work.
-
- To apply the Apache License to your work, attach the following
- boilerplate notice, with the fields enclosed by brackets "{}"
- replaced with your own identifying information. (Don't include
- the brackets!) The text should be enclosed in the appropriate
- comment syntax for the file format. We also recommend that a
- file or class name and description of purpose be included on the
- same "printed page" as the copyright notice for easier
- identification within third-party archives.
-
- Copyright {yyyy} {name of copyright owner}
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-
diff --git a/sensors/LightSensor.cpp b/sensors/LightSensor.cpp
deleted file mode 100644
index 24bbad0..0000000
--- a/sensors/LightSensor.cpp
+++ /dev/null
@@ -1,312 +0,0 @@
-/*
- * Copyright (c) 2014, The Linux Foundation. All rights reserved.
- * Not a Contribution.
- * Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <fcntl.h>
-#include <errno.h>
-#include <math.h>
-#include <poll.h>
-#include <unistd.h>
-#include <dirent.h>
-#include <sys/select.h>
-#include <cutils/log.h>
-#include <cutils/properties.h>
-
-#include "sensors.h"
-#include "LightSensor.h"
-
-#define EVENT_TYPE_LIGHT ABS_MISC
-/*****************************************************************************/
-
-enum input_device_name {
- GENERIC_LS = 0,
- LIGHTSENSOR_LEVEL,
- AP3426_LS,
- STK3x1x_LS,
- SUPPORTED_LSENSOR_COUNT,
-};
-
-enum {
- TYPE_ADC = 0,
- TYPE_LUX,
-};
-
-static const char *data_device_name[SUPPORTED_LSENSOR_COUNT] = {
- [GENERIC_LS] = "light",
- [LIGHTSENSOR_LEVEL] = "lightsensor-level",
- [AP3426_LS] = "ap3426-light",
- [STK3x1x_LS] = "stk3x1x-ls",
-};
-
-static const char *input_sysfs_path_list[SUPPORTED_LSENSOR_COUNT] = {
- /* This one is for back compatibility, we don't need it for generic HAL.*/
- [GENERIC_LS] = "/sys/class/input/%s/device",
- [LIGHTSENSOR_LEVEL] = "/sys/class/input/%s/device/",
- [AP3426_LS] = "/sys/class/input/%s/device/",
- [STK3x1x_LS] = "/sys/class/input/%s/device/",
-};
-
-static const char *input_sysfs_enable_list[SUPPORTED_LSENSOR_COUNT] = {
- [GENERIC_LS] = "enable",
- [LIGHTSENSOR_LEVEL] = "enable",
- [AP3426_LS] = "enable",
- [STK3x1x_LS] = "enable",
-};
-
-static const int input_report_type[SUPPORTED_LSENSOR_COUNT] = {
- [GENERIC_LS] = TYPE_LUX,
- [LIGHTSENSOR_LEVEL] = TYPE_ADC,
- [AP3426_LS] = TYPE_LUX,
- [STK3x1x_LS] = TYPE_LUX,
-};
-
-LightSensor::LightSensor()
-: SensorBase(NULL, NULL),
- mEnabled(0),
- mInputReader(4),
- mHasPendingEvent(false),
- sensor_index(-1)
-{
- int i;
-
- mPendingEvent.version = sizeof(sensors_event_t);
- mPendingEvent.sensor = SENSORS_LIGHT_HANDLE;
- mPendingEvent.type = SENSOR_TYPE_LIGHT;
- memset(mPendingEvent.data, 0, sizeof(mPendingEvent.data));
-
- for(i = 0; i < SUPPORTED_LSENSOR_COUNT; i++) {
- data_name = data_device_name[i];
-
- // data_fd is not initialized if data_name passed
- // to SensorBase is NULL.
- data_fd = openInput(data_name);
- if (data_fd > 0) {
- sensor_index = i;
- break;
- }
- }
-
- if (data_fd > 0) {
- snprintf(input_sysfs_path, sizeof(input_sysfs_path),
- input_sysfs_path_list[i], input_name);
- input_sysfs_path_len = strlen(input_sysfs_path);
- enable(0, 1);
- }
- ALOGI("The light sensor path is %s",input_sysfs_path);
-}
-
-LightSensor::LightSensor(char *name)
- : SensorBase(NULL, data_device_name[GENERIC_LS]),
- mEnabled(0),
- mInputReader(4),
- mHasPendingEvent(false),
- sensor_index(GENERIC_LS)
-{
- mPendingEvent.version = sizeof(sensors_event_t);
- mPendingEvent.sensor = SENSORS_LIGHT_HANDLE;
- mPendingEvent.type = SENSOR_TYPE_LIGHT;
- memset(mPendingEvent.data, 0, sizeof(mPendingEvent.data));
-
- if (data_fd > 0) {
- strlcpy(input_sysfs_path, SYSFS_CLASS, sizeof(input_sysfs_path));
- strlcat(input_sysfs_path, name, sizeof(input_sysfs_path));
- strlcat(input_sysfs_path, "/", sizeof(input_sysfs_path));
- input_sysfs_path_len = strlen(input_sysfs_path);
- ALOGI("The light sensor path is %s",input_sysfs_path);
- enable(0, 1);
- }
-}
-
-LightSensor::LightSensor(struct SensorContext *context)
- : SensorBase(NULL, NULL),
- mEnabled(0),
- mInputReader(4),
- mHasPendingEvent(false),
- sensor_index(GENERIC_LS)
-{
- mPendingEvent.version = sizeof(sensors_event_t);
- mPendingEvent.sensor = context->sensor->handle;
- mPendingEvent.type = SENSOR_TYPE_LIGHT;
- memset(mPendingEvent.data, 0, sizeof(mPendingEvent.data));
-
- data_fd = context->data_fd;
- strlcpy(input_sysfs_path, context->enable_path, sizeof(input_sysfs_path));
- input_sysfs_path_len = strlen(input_sysfs_path);
- mUseAbsTimeStamp = false;
- enable(0, 1);
-}
-
-LightSensor::~LightSensor() {
- if (mEnabled) {
- enable(0, 0);
- }
-}
-
-int LightSensor::setDelay(int32_t, int64_t ns)
-{
- int fd;
- char propBuf[PROPERTY_VALUE_MAX];
- property_get("sensors.light.loopback", propBuf, "0");
- if (strcmp(propBuf, "1") == 0) {
- ALOGE("sensors.light.loopback is set");
- return 0;
- }
- int delay_ms = ns / 1000000;
- strlcpy(&input_sysfs_path[input_sysfs_path_len],
- SYSFS_POLL_DELAY, SYSFS_MAXLEN);
- fd = open(input_sysfs_path, O_RDWR);
- if (fd >= 0) {
- char buf[80];
- snprintf(buf, sizeof(buf), "%d", delay_ms);
- write(fd, buf, strlen(buf)+1);
- close(fd);
- return 0;
- }
- return -1;
-}
-
-int LightSensor::enable(int32_t, int en)
-{
- int flags = en ? 1 : 0;
- char propBuf[PROPERTY_VALUE_MAX];
- property_get("sensors.light.loopback", propBuf, "0");
- if (strcmp(propBuf, "1") == 0) {
- mEnabled = flags;
- ALOGE("sensors.light.loopback is set");
- return 0;
- }
- if (flags != mEnabled) {
- int fd;
- if (sensor_index >= 0) {
- strlcpy(&input_sysfs_path[input_sysfs_path_len],
- input_sysfs_enable_list[sensor_index], sizeof(input_sysfs_path) - input_sysfs_path_len);
- }
- else {
- ALOGE("invalid sensor index:%d\n", sensor_index);
- return -1;
- }
- fd = open(input_sysfs_path, O_RDWR);
- if (fd >= 0) {
- char buf[2];
- int err;
- buf[1] = 0;
- if (flags) {
- buf[0] = '1';
- } else {
- buf[0] = '0';
- }
- err = write(fd, buf, sizeof(buf));
- close(fd);
- mEnabled = flags;
- return 0;
- } else {
- ALOGE("open %s failed.(%s)\n", input_sysfs_path, strerror(errno));
- return -1;
- }
- }
- return 0;
-}
-
-bool LightSensor::hasPendingEvents() const {
- return mHasPendingEvent;
-}
-
-int LightSensor::readEvents(sensors_event_t* data, int count)
-{
- if (count < 1)
- return -EINVAL;
-
- if (mHasPendingEvent) {
- mHasPendingEvent = false;
- mPendingEvent.timestamp = getTimestamp();
- *data = mPendingEvent;
- return mEnabled ? 1 : 0;
- }
-
- ssize_t n = mInputReader.fill(data_fd);
- if (n < 0)
- return n;
-
- int numEventReceived = 0;
- input_event const* event;
-
- while (count && mInputReader.readEvent(&event)) {
- int type = event->type;
- if (type == EV_ABS) {
- if (event->code == EVENT_TYPE_LIGHT) {
- mPendingEvent.light = convertEvent(event->value);
- }
- } else if (type == EV_SYN) {
- switch ( event->code ){
- case SYN_TIME_SEC:
- {
- mUseAbsTimeStamp = true;
- report_time = event->value*1000000000LL;
- }
- break;
- case SYN_TIME_NSEC:
- {
- mUseAbsTimeStamp = true;
- mPendingEvent.timestamp = report_time+event->value;
- }
- break;
- case SYN_REPORT:
- {
- if (mEnabled && mUseAbsTimeStamp) {
- *data++ = mPendingEvent;
- numEventReceived++;
- count--;
- mUseAbsTimeStamp = false;
- } else {
- ALOGE_IF(!mUseAbsTimeStamp, "LightSensor:timestamp not received");
- }
- }
- break;
- }
-
- } else {
- ALOGE("LightSensor: unknown event (type=%d, code=%d)",
- type, event->code);
- }
- mInputReader.next();
- }
-
- return numEventReceived;
-}
-
-float LightSensor::convertEvent(int value)
-{
- float lux = 0;
-
- if (sensor_index >= 0) {
- if (input_report_type[sensor_index] == TYPE_ADC) {
- // Convert adc value to lux assuming:
- // I = 10 * log(Ev) uA
- // R = 47kOhm
- // Max adc value 4095 = 3.3V
- // 1/4 of light reaches sensor
- lux = powf(10, value * (330.0f / 4095.0f / 47.0f)) * 4;
- } else if (input_report_type[sensor_index] == TYPE_LUX) {
- lux = value;
- } else {
- ALOGE("LightSensor: unknown report type\n");
- lux = 0;
- }
- }
-
- return lux;
-}
diff --git a/sensors/LightSensor.h b/sensors/LightSensor.h
deleted file mode 100644
index b1f53ee..0000000
--- a/sensors/LightSensor.h
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef ANDROID_LIGHT_SENSOR_H
-#define ANDROID_LIGHT_SENSOR_H
-
-#include <stdint.h>
-#include <errno.h>
-#include <sys/cdefs.h>
-#include <sys/types.h>
-
-#include "SensorBase.h"
-#include "InputEventReader.h"
-#include "NativeSensorManager.h"
-
-/*****************************************************************************/
-
-struct input_event;
-
-class LightSensor : public SensorBase {
- int mEnabled;
- InputEventCircularReader mInputReader;
- sensors_event_t mPendingEvent;
- bool mHasPendingEvent;
- char input_sysfs_path[PATH_MAX];
- int input_sysfs_path_len;
- int sensor_index;
-
- int setInitialState();
-
-public:
- LightSensor();
- LightSensor(char *name);
- LightSensor(struct SensorContext *context);
- virtual ~LightSensor();
- virtual int readEvents(sensors_event_t* data, int count);
- virtual bool hasPendingEvents() const;
- virtual int setDelay(int32_t handle, int64_t ns);
- virtual int enable(int32_t handle, int enabled);
- virtual float convertEvent(int value);
-};
-
-/*****************************************************************************/
-
-#endif // ANDROID_LIGHT_SENSOR_H
diff --git a/sensors/NativeSensorManager.cpp b/sensors/NativeSensorManager.cpp
deleted file mode 100644
index 358b9dc..0000000
--- a/sensors/NativeSensorManager.cpp
+++ /dev/null
@@ -1,856 +0,0 @@
-/*--------------------------------------------------------------------------
-Copyright (c) 2014, The Linux Foundation. All rights reserved.
-
-Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions are
-met:
- * Redistributions of source code must retain the above copyright
- notice, this list of conditions and the following disclaimer.
- * Redistributions in binary form must reproduce the above
- copyright notice, this list of conditions and the following
- disclaimer in the documentation and/or other materials provided
- with the distribution.
- * Neither the name of The Linux Foundation nor the names of its
- contributors may be used to endorse or promote products derived
- from this software without specific prior written permission.
-
-THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
-WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
-MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
-ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
-BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
-CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
-SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
-BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
-OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
-IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
---------------------------------------------------------------------------*/
-#include "NativeSensorManager.h"
-
-ANDROID_SINGLETON_STATIC_INSTANCE(NativeSensorManager);
-
-enum {
- ORIENTATION = 0,
- PSEUDO_GYROSCOPE,
- ROTATION_VECTOR,
- LINEAR_ACCELERATION,
- GRAVITY,
- VIRTUAL_SENSOR_COUNT,
-};
-
-const struct sensor_t NativeSensorManager::virtualSensorList [VIRTUAL_SENSOR_COUNT] = {
- [ORIENTATION] = {
- .name = "oem-orientation",
- .vendor = "oem",
- .version = 1,
- .handle = '_dmy',
- .type = SENSOR_TYPE_ORIENTATION,
- .maxRange = 360.0f,
- .resolution = 1.0f/256.0f,
- .power = 1,
- .minDelay = 10000,
- .fifoReservedEventCount = 0,
- .fifoMaxEventCount = 0,
-#if defined(SENSORS_DEVICE_API_VERSION_1_3)
- .stringType = NULL,
- .requiredPermission = NULL,
- .maxDelay = 0,
- .flags = 0,
-#endif
- .reserved = {},
- },
-
- [PSEUDO_GYROSCOPE] = {
- .name = "oem-pseudo-gyro",
- .vendor = "oem",
- .version = 1,
- .handle = '_dmy',
- .type = SENSOR_TYPE_GYROSCOPE,
- .maxRange = 50.0f,
- .resolution = 0.01f,
- .power = 1,
- .minDelay = 10000,
- .fifoReservedEventCount = 0,
- .fifoMaxEventCount = 0,
-#if defined(SENSORS_DEVICE_API_VERSION_1_3)
- .stringType = NULL,
- .requiredPermission = NULL,
- .maxDelay = 0,
- .flags = 0,
-#endif
- .reserved = {},
- },
-
- [ROTATION_VECTOR] = {
- .name = "oem-rotation-vector",
- .vendor = "oem",
- .version = 1,
- .handle = '_dmy',
- .type = SENSOR_TYPE_ROTATION_VECTOR,
- .maxRange = 1,
- .resolution = 1.0f / (1<<24),
- .power = 1,
- .minDelay = 10000,
- .fifoReservedEventCount = 0,
- .fifoMaxEventCount = 0,
-#if defined(SENSORS_DEVICE_API_VERSION_1_3)
- .stringType = NULL,
- .requiredPermission = NULL,
- .maxDelay = 0,
- .flags = 0,
-#endif
- .reserved = {},
- },
-
- [LINEAR_ACCELERATION] = {
- .name = "oem-linear-acceleration",
- .vendor = "oem",
- .version = 1,
- .handle = '_dmy',
- .type = SENSOR_TYPE_LINEAR_ACCELERATION,
- .maxRange = 40.0f,
- .resolution = 0.01f,
- .power = 1,
- .minDelay = 10000,
- .fifoReservedEventCount = 0,
- .fifoMaxEventCount = 0,
-#if defined(SENSORS_DEVICE_API_VERSION_1_3)
- .stringType = NULL,
- .requiredPermission = NULL,
- .maxDelay = 0,
- .flags = 0,
-#endif
- .reserved = {},
- },
-
- [GRAVITY] = {
- .name = "oem-gravity",
- .vendor = "oem",
- .version = 1,
- .handle = '_dmy',
- .type = SENSOR_TYPE_GRAVITY,
- .maxRange = 40.0f,
- .resolution = 0.01f,
- .power = 1,
- .minDelay = 10000,
- .fifoReservedEventCount = 0,
- .fifoMaxEventCount = 0,
-#if defined(SENSORS_DEVICE_API_VERSION_1_3)
- .stringType = NULL,
- .requiredPermission = NULL,
- .maxDelay = 0,
- .flags = 0,
-#endif
- .reserved = {},
- },
-};
-
-int NativeSensorManager::initVirtualSensor(struct SensorContext *ctx, int handle, int64_t dep,
- struct sensor_t info)
-{
- CalibrationManager& cm(CalibrationManager::getInstance());
- SensorRefMap *item;
- struct SensorContext *ref;
- unsigned int i;
-
- *(ctx->sensor) = info;
- if (cm.getCalAlgo(ctx->sensor) == NULL) {
- return -1;
- }
-
- ctx->sensor->handle = handle;
- ctx->driver = new VirtualSensor(ctx);
- ctx->data_fd = -1;
- ctx->data_path = NULL;
- ctx->enable_path = NULL;
- ctx->is_virtual = true;
-
- for (i = 0; i < sizeof(dep) * 8; i++) {
- if (dep & (1ULL << i)) {
- ref = getInfoByType(i);
- if (ref != NULL) {
- item = new SensorRefMap;
- item->ctx = ref;
- list_add_tail(&ctx->dep_list, &item->list);
- }
- }
- }
-
- type_map.add(ctx->sensor->type, ctx);
- handle_map.add(ctx->sensor->handle, ctx);
-
- return 0;
-}
-
-
-const struct SysfsMap NativeSensorManager::node_map[] = {
- {offsetof(struct sensor_t, name), SYSFS_NAME, TYPE_STRING},
- {offsetof(struct sensor_t, vendor), SYSFS_VENDOR, TYPE_STRING},
- {offsetof(struct sensor_t, version), SYSFS_VERSION, TYPE_INTEGER},
- {offsetof(struct sensor_t, type), SYSFS_TYPE, TYPE_INTEGER},
- {offsetof(struct sensor_t, maxRange), SYSFS_MAXRANGE, TYPE_FLOAT},
- {offsetof(struct sensor_t, resolution), SYSFS_RESOLUTION, TYPE_FLOAT},
- {offsetof(struct sensor_t, power), SYSFS_POWER, TYPE_FLOAT},
- {offsetof(struct sensor_t, minDelay), SYSFS_MINDELAY, TYPE_INTEGER},
-};
-
-NativeSensorManager::NativeSensorManager():
- mSensorCount(0), type_map(NULL), handle_map(NULL), fd_map(NULL)
-{
- int i;
-
- memset(sensor_list, 0, sizeof(sensor_list));
- memset(context, 0, sizeof(context));
-
- type_map.setCapacity(MAX_SENSORS);
- handle_map.setCapacity(MAX_SENSORS);
- fd_map.setCapacity(MAX_SENSORS);
-
- for (i = 0; i < MAX_SENSORS; i++) {
- context[i].sensor = &sensor_list[i];
- sensor_list[i].name = context[i].name;
- sensor_list[i].vendor = context[i].vendor;
- list_init(&context[i].listener);
- list_init(&context[i].dep_list);
- }
-
- if(getDataInfo()) {
- ALOGE("Get data info failed\n");
- }
-
- dump();
-}
-
-NativeSensorManager::~NativeSensorManager()
-{
- int i;
- int number = getSensorCount();
- struct listnode *node;
- struct listnode *n;
- struct SensorContext *ctx;
- struct SensorRefMap *item;
-
- for (i = 0; i < number; i++) {
- if (context[i].driver != NULL) {
- delete context[i].driver;
- }
-
- list_for_each_safe(node, n, &context[i].listener) {
- item = node_to_item(node, struct SensorRefMap, list);
- if (item != NULL) {
- list_remove(&item->list);
- delete item;
- }
- }
-
- list_for_each_safe(node, n, &context[i].dep_list) {
- item = node_to_item(node, struct SensorRefMap, list);
- if (item != NULL) {
- list_remove(&item->list);
- delete item;
- }
- }
- }
-}
-
-void NativeSensorManager::dump()
-{
- int i;
- struct listnode *node;
- struct SensorRefMap* ref;
-
- for (i = 0; i < mSensorCount; i++) {
- ALOGI("\nname:%s\ntype:%d\nhandle:%d\ndata_fd=%d\nis_virtual=%d",
- context[i].sensor->name,
- context[i].sensor->type,
- context[i].sensor->handle,
- context[i].data_fd,
- context[i].is_virtual);
-
- ALOGI("data_path=%s\nenable_path=%s\ndelay_ns:%lld\nenable=%d\n",
- context[i].data_path,
- context[i].enable_path,
- context[i].delay_ns,
- context[i].enable);
-
- ALOGI("Listener:");
- list_for_each(node, &context[i].listener) {
- ref = node_to_item(node, struct SensorRefMap, list);
- ALOGI("name:%s handle:%d\n", ref->ctx->sensor->name, ref->ctx->sensor->handle);
- }
-
- ALOGI("Dependency:");
- list_for_each(node, &context[i].dep_list) {
- ref = node_to_item(node, struct SensorRefMap, list);
- ALOGI("name:%s handle:%d", ref->ctx->sensor->name, ref->ctx->sensor->handle);
- }
- }
-
- ALOGI("\n");
-}
-
-int NativeSensorManager::getDataInfo() {
- struct dirent **namelist;
- char *file;
- char path[PATH_MAX];
- char name[80];
- int nNodes;
- int i, j;
- int fd = -1;
- struct SensorContext *list;
- int has_acc = 0;
- int has_compass = 0;
- int has_gyro = 0;
- int event_count = 0;
- struct sensor_t sensor_mag;
-
- strlcpy(path, EVENT_PATH, sizeof(path));
- file = path + strlen(EVENT_PATH);
- nNodes = scandir(path, &namelist, 0, alphasort);
- if (nNodes < 0) {
- ALOGE("scan %s failed.(%s)\n", EVENT_PATH, strerror(errno));
- return -1;
- }
-
- for (event_count = 0, j = 0; (j < nNodes) && (j < MAX_SENSORS); j++) {
- if (namelist[j]->d_type != DT_CHR) {
- continue;
- }
-
- strlcpy(file, namelist[j]->d_name, sizeof(path) - strlen(EVENT_PATH));
-
- fd = open(path, O_RDONLY);
- if (fd < 0) {
- ALOGE("open %s failed(%s)", path, strerror(errno));
- continue;
- }
-
- if (ioctl(fd, EVIOCGNAME(sizeof(name) - 1), &name) < 1) {
- name[0] = '\0';
- }
-
- strlcpy(event_list[event_count].data_name, name, sizeof(event_list[0].data_name));
- strlcpy(event_list[event_count].data_path, path, sizeof(event_list[0].data_path));
- close(fd);
- event_count++;
- }
-
- for (j = 0; j <nNodes; j++ ) {
- free(namelist[j]);
- }
-
- free(namelist);
-
- mSensorCount = getSensorListInner();
- for (i = 0; i < mSensorCount; i++) {
- struct SensorRefMap *item;
- list = &context[i];
- list->is_virtual = false;
-
- item = new struct SensorRefMap;
- item->ctx = list;
- list_add_tail(&list->dep_list, &item->list);
-
- /* Initialize data_path and data_fd */
- for (j = 0; (j < event_count) && (j < MAX_SENSORS); j++) {
- if (strcmp(list->sensor->name, event_list[j].data_name) == 0) {
- list->data_path = strdup(event_list[j].data_path);
- break;
- }
-
- if (strcmp(event_list[j].data_name, type_to_name(list->sensor->type)) == 0) {
- list->data_path = strdup(event_list[j].data_path);
- }
- }
-
- if (list->data_path != NULL)
- list->data_fd = open(list->data_path,O_RDONLY | O_CLOEXEC | O_NONBLOCK);
- else
- list->data_fd = -1;
-
- if (list->data_fd > 0) {
- fd_map.add(list->data_fd, list);
- } else {
- ALOGE("open %s failed, continue anyway.(%s)\n", list->data_path, strerror(errno));
- }
-
- type_map.add(list->sensor->type, list);
- handle_map.add(list->sensor->handle, list);
-
- switch (list->sensor->type) {
- case SENSOR_TYPE_ACCELEROMETER:
- has_acc = 1;
- list->driver = new AccelSensor(list);
- break;
- case SENSOR_TYPE_MAGNETIC_FIELD:
- has_compass = 1;
- list->driver = new CompassSensor(list);
- sensor_mag = *(list->sensor);
- break;
- case SENSOR_TYPE_PROXIMITY:
- list->driver = new ProximitySensor(list);
- break;
- case SENSOR_TYPE_LIGHT:
- list->driver = new LightSensor(list);
- break;
- case SENSOR_TYPE_GYROSCOPE:
- has_gyro = 1;
- list->driver = new GyroSensor(list);
- break;
- default:
- list->driver = NULL;
- ALOGE("No handle %d for this type sensor!", i);
- break;
- }
- initCalibrate(list);
- }
-
-
- /* Some vendor or the reference design implements some virtual sensors
- * or pseudo sensors. These sensors are required by some of the applications.
- * Here we check the CalibratoinManager to decide whether to enable them.
- */
- CalibrationManager &cm(CalibrationManager::getInstance());
- struct SensorRefMap *ref;
-
- if (has_compass) {
- /* The uncalibrated magnetic field sensor shares the same vendor/name as the
- * calibrated one. */
- sensor_mag.type = SENSOR_TYPE_MAGNETIC_FIELD_UNCALIBRATED;
- if (!initVirtualSensor(&context[mSensorCount], SENSORS_HANDLE(mSensorCount),
- 1ULL << SENSOR_TYPE_MAGNETIC_FIELD, sensor_mag)) {
- mSensorCount++;
- }
- }
-
- if (has_acc && has_compass) {
- int dep = (1ULL << SENSOR_TYPE_ACCELEROMETER) | (1ULL << SENSOR_TYPE_MAGNETIC_FIELD);
-
- /* HAL implemented orientation. Android will replace it for
- * platform with Gyro with SensorFusion.
- * The calibration manager will first match "oem-orientation" and
- * then match "orientation" to select the algorithms. */
- if (!initVirtualSensor(&context[mSensorCount], SENSORS_HANDLE(mSensorCount), dep,
- virtualSensorList[ORIENTATION])) {
- mSensorCount++;
- }
-
- if (!has_gyro) {
- /* Pseudo gyroscope is a pseudo sensor which implements by accelerometer and
- * magnetometer. Some sensor vendors provide such implementations. The pseudo
- * gyroscope sensor is low cost but the performance is worse than the actual
- * gyroscope. So disable it for the system with actual gyroscope. */
- if (!initVirtualSensor(&context[mSensorCount], SENSORS_HANDLE(mSensorCount), dep,
- virtualSensorList[PSEUDO_GYROSCOPE])) {
- mSensorCount++;
- }
-
- /* For linear acceleration */
- if (!initVirtualSensor(&context[mSensorCount], SENSORS_HANDLE(mSensorCount), dep,
- virtualSensorList[LINEAR_ACCELERATION])) {
- mSensorCount++;
- }
-
- /* For rotation vector */
- if (!initVirtualSensor(&context[mSensorCount], SENSORS_HANDLE(mSensorCount), dep,
- virtualSensorList[ROTATION_VECTOR])) {
- mSensorCount++;
- }
-
- /* For gravity */
- if (!initVirtualSensor(&context[mSensorCount], SENSORS_HANDLE(mSensorCount), dep,
- virtualSensorList[GRAVITY])) {
- mSensorCount++;
- }
- }
- }
-
- return 0;
-}
-
-/* Register a listener on "hw" for "virt".
- * The "hw" specify the actual background sensor type, and "virt" is one kind of virtual sensor.
- * Generally the virtual sensor specified by "virt" can only work when the hardware sensor specified
- * by "hw" is activiated.
- */
-int NativeSensorManager::registerListener(struct SensorContext *hw, struct SensorContext *virt)
-{
- struct listnode *node;
- struct SensorContext *ctx;
- struct SensorRefMap *item;
-
- list_for_each(node, &hw->listener) {
- item = node_to_item(node, struct SensorRefMap, list);
- if (item->ctx->sensor->handle == virt->sensor->handle) {
- ALOGE("Already registered as listener for %s:%s\n", hw->sensor->name, virt->sensor->name);
- return -1;
- }
- }
-
- item = new SensorRefMap;
- item->ctx = virt;
-
- list_add_tail(&hw->listener, &item->list);
-
- return 0;
-}
-
-/* Remove the virtual sensor listener from the list specified by "hw" */
-int NativeSensorManager::unregisterListener(struct SensorContext *hw, struct SensorContext *virt)
-{
- struct listnode *node;
- struct listnode *n;
- struct SensorContext *ctx;
- struct SensorRefMap *item;
-
- list_for_each_safe(node, n, &hw->listener) {
- item = node_to_item(node, struct SensorRefMap, list);
- if (item->ctx == virt) {
- list_remove(&item->list);
- delete item;
- return 0;
- }
- }
-
- ALOGE("%s is not a listener of %s\n", virt->sensor->name, hw->sensor->name);
- return -1;
-}
-
-int NativeSensorManager::getSensorList(const sensor_t **list) {
- *list = mSensorCount ? sensor_list:NULL;
-
- return mSensorCount;
-}
-
-int NativeSensorManager::getNode(char *buf, char *path, const struct SysfsMap *map) {
- char * fret;
- ssize_t len = 0;
- int fd;
- char tmp[SYSFS_MAXLEN];
-
- if (NULL == buf || NULL == path)
- return -1;
-
- memset(tmp, 0, sizeof(tmp));
-
- fd = open(path, O_RDONLY);
- if (fd < 0) {
- ALOGE("open %s failed.(%s)\n", path, strerror(errno));
- return -1;
- }
-
- len = read(fd, tmp, sizeof(tmp) - 1);
- if ((len <= 0) || (strlen(tmp) == 0)) {
- ALOGE("read %s failed.(%s)\n", path, strerror(errno));
- close(fd);
- return -1;
- }
-
- tmp[len - 1] = '\0';
-
- if (tmp[strlen(tmp) - 1] == '\n')
- tmp[strlen(tmp) - 1] = '\0';
-
- if (map->type == TYPE_INTEGER) {
- int *p = (int *)(buf + map->offset);
- *p = atoi(tmp);
- } else if (map->type == TYPE_STRING) {
- char **p = (char **)(buf + map->offset);
- strlcpy(*p, tmp, SYSFS_MAXLEN);
- } else if (map->type == TYPE_FLOAT) {
- float *p = (float*)(buf + map->offset);
- *p = atof(tmp);
- }
-
- close(fd);
- return 0;
-}
-
-int NativeSensorManager::getSensorListInner()
-{
- int number = 0;
- int err = -1;
- const char *dirname = SYSFS_CLASS;
- char devname[PATH_MAX];
- char *filename;
- char *nodename;
- DIR *dir;
- struct dirent *de;
- struct SensorContext *list;
- unsigned int i;
-
- dir = opendir(dirname);
- if(dir == NULL) {
- return 0;
- }
- strlcpy(devname, dirname, PATH_MAX);
- filename = devname + strlen(devname);
-
- while ((de = readdir(dir))) {
- if(de->d_name[0] == '.' &&
- (de->d_name[1] == '\0' ||
- (de->d_name[1] == '.' && de->d_name[2] == '\0')))
- continue;
-
- list = &context[number];
-
- strlcpy(filename, de->d_name, PATH_MAX - strlen(SYSFS_CLASS));
- nodename = filename + strlen(de->d_name);
- *nodename++ = '/';
-
- for (i = 0; i < ARRAY_SIZE(node_map); i++) {
- strlcpy(nodename, node_map[i].node, PATH_MAX - strlen(SYSFS_CLASS) - strlen(de->d_name));
- err = getNode((char*)(list->sensor), devname, &node_map[i]);
- if (err)
- break;
- }
-
- if (i < ARRAY_SIZE(node_map))
- continue;
-
- if (!((1ULL << list->sensor->type) & SUPPORTED_SENSORS_TYPE))
- continue;
-
- /* Setup other information */
- list->sensor->handle = SENSORS_HANDLE(number);
- list->data_path = NULL;
-
- strlcpy(nodename, "", SYSFS_MAXLEN);
- list->enable_path = strdup(devname);
-
- number++;
- }
- closedir(dir);
- return number;
-}
-
-int NativeSensorManager::activate(int handle, int enable)
-{
- SensorContext *list;
- int i;
- int number = getSensorCount();
- int err = 0;
- struct listnode *node;
- struct SensorContext *ctx;
- struct SensorRefMap *item;
-
- list = getInfoByHandle(handle);
- if (list == NULL) {
- ALOGE("Invalid handle(%d)", handle);
- return -EINVAL;
- }
-
- /* Search for the background sensor for the sensor specified by handle. */
- list_for_each(node, &list->dep_list) {
- item = node_to_item(node, struct SensorRefMap, list);
- if (enable) {
- /* Enable the background sensor and register a listener on it. */
- err = item->ctx->driver->enable(item->ctx->sensor->handle, 1);
- if (!err) {
- registerListener(item->ctx, list);
- }
- } else {
- /* The background sensor has other listeners, we need
- * to unregister the current sensor from it and sync the
- * poll delay settings.
- */
- if (!list_empty(&item->ctx->listener)) {
- unregisterListener(item->ctx, list);
- /* We're activiating the hardware sensor itself */
- if ((item->ctx == list) && (item->ctx->enable))
- item->ctx->enable = 0;
- syncDelay(item->ctx->sensor->handle);
- }
-
- /* Disable the background sensor if it doesn't have any listeners. */
- if (list_empty(&item->ctx->listener)) {
- item->ctx->driver->enable(item->ctx->sensor->handle, 0);
- }
- }
- }
-
- list->enable = enable;
-
- return err;
-}
-
-int NativeSensorManager::syncDelay(int handle)
-{
- const SensorRefMap *item;
- SensorContext *ctx;
- const SensorContext *list;
- struct listnode *node;
- int64_t min_ns;
-
- list = getInfoByHandle(handle);
- if (list == NULL) {
- ALOGE("Invalid handle(%d)", handle);
- return -EINVAL;
- }
-
- if (list_empty(&list->listener)) {
- min_ns = list->delay_ns;
- } else {
- node = list_head(&list->listener);
- item = node_to_item(node, struct SensorRefMap, list);
- min_ns = item->ctx->delay_ns;
-
- list_for_each(node, &list->listener) {
- item = node_to_item(node, struct SensorRefMap, list);
- ctx = item->ctx;
- /* To handle some special case that the polling delay is 0. This
- * may happen if the background sensor is not enabled but the virtual
- * sensor is enabled case.
- */
- if (ctx->delay_ns == 0) {
- ALOGW("Listener delay is 0. Fix it to minDelay");
- ctx->delay_ns = ctx->sensor->minDelay;
- }
-
- if (min_ns > ctx->delay_ns)
- min_ns = ctx->delay_ns;
- }
- }
-
- if ((list->delay_ns != 0) && (list->delay_ns < min_ns) &&
- (list->enable))
- min_ns = list->delay_ns;
-
- return list->driver->setDelay(list->sensor->handle, min_ns);
-}
-
-int NativeSensorManager::setDelay(int handle, int64_t ns)
-{
- SensorContext *list;
- int i;
- int number = getSensorCount();
- int64_t delay = ns;
- struct SensorRefMap *item;
- struct listnode *node;
-
-
- list = getInfoByHandle(handle);
- if (list == NULL) {
- ALOGE("Invalid handle(%d)", handle);
- return -EINVAL;
- }
-
- list->delay_ns = delay;
-
- // min_delay sysfs entry is in microseconds
- if (ns < list->sensor->minDelay * 1000) {
- list->delay_ns = list->sensor->minDelay * 1000;
- }
-
- if (list->delay_ns == 0)
- list->delay_ns = 1000000; // clamped to 1ms
-
- list_for_each(node, &list->dep_list) {
- item = node_to_item(node, struct SensorRefMap, list);
- syncDelay(item->ctx->sensor->handle);
- }
-
- return 0;
-}
-
-int NativeSensorManager::readEvents(int handle, sensors_event_t* data, int count)
-{
- const SensorContext *list;
- int i, j;
- int number = getSensorCount();
- int nb;
- struct listnode *node;
- struct SensorRefMap *item;
-
- list = getInfoByHandle(handle);
- if (list == NULL) {
- ALOGE("Invalid handle(%d)", handle);
- return -EINVAL;
- }
- do {
- nb = list->driver->readEvents(data, count);
- } while ((nb == -EAGAIN) || (nb == -EINTR));
-
- for (j = 0; j < nb; j++) {
- list_for_each(node, &list->listener) {
- item = node_to_item(node, struct SensorRefMap, list);
- if (item->ctx->enable) {
- item->ctx->driver->injectEvents(&data[j], 1);
- }
- }
- }
-
- if (list->enable)
- return nb;
-
- /* No need to report the events if the sensor is not enabled */
- return 0;
-}
-
-int NativeSensorManager::hasPendingEvents(int handle)
-{
- const SensorContext *list;
-
- list = getInfoByHandle(handle);
- if (list == NULL) {
- ALOGE("Invalid handle(%d)", handle);
- return -EINVAL;
- }
-
- return list->driver->hasPendingEvents();
-}
-
-int NativeSensorManager::calibrate(int handle, struct cal_cmd_t *para)
-{
- const SensorContext *list;
- struct cal_result_t cal_result;
- sensors_XML& sensor_XML(sensors_XML :: getInstance());
- int err;
-
- list = getInfoByHandle(handle);
- if(list == NULL) {
- ALOGE("Invalid handle(%d)", handle);
- return -EINVAL;
- }
- sensor_XML.sensors_rm_file();
- memset(&cal_result, 0, sizeof(cal_result));
- err = list->driver->calibrate(handle, para, &cal_result);
- if (err < 0) {
- ALOGE("calibrate %s sensor error\n", list->sensor->name);
- return err;
- }
- if (!para->save) {
- return err;
- }
- err = sensor_XML.write_sensors_params(list->sensor, &cal_result);
- if (err < 0) {
- ALOGE("write calibrate %s sensor error\n", list->sensor->name);
- return err;
- }
- return err;
-}
-
-int NativeSensorManager::initCalibrate(const SensorContext *list)
-{
- struct cal_result_t cal_result;
- sensors_XML& sensor_XML(sensors_XML :: getInstance());
- int err = 0;
-
- if(list == NULL) {
- ALOGE("Invalid sensor\n");
- return -EINVAL;
- }
- memset(&cal_result, 0, sizeof(cal_result));
- err = sensor_XML.read_sensors_params(list->sensor, &cal_result);
- if (err < 0) {
- ALOGE("read calibrate params error\n");
- return err;
- }
-
- err = list->driver->initCalibrate(list->sensor->handle, &cal_result);
- if (err < 0) {
- ALOGE("init sensor %s calibrate params error\n", list->sensor->name);
- }
- return err;
-}
diff --git a/sensors/NativeSensorManager.h b/sensors/NativeSensorManager.h
deleted file mode 100644
index 8272162..0000000
--- a/sensors/NativeSensorManager.h
+++ /dev/null
@@ -1,147 +0,0 @@
-/*--------------------------------------------------------------------------
-Copyright (c) 2014, The Linux Foundation. All rights reserved.
-
-Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions are
-met:
- * Redistributions of source code must retain the above copyright
- notice, this list of conditions and the following disclaimer.
- * Redistributions in binary form must reproduce the above
- copyright notice, this list of conditions and the following
- disclaimer in the documentation and/or other materials provided
- with the distribution.
- * Neither the name of The Linux Foundation nor the names of its
- contributors may be used to endorse or promote products derived
- from this software without specific prior written permission.
-
-THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
-WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
-MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
-ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
-BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
-CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
-SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
-BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
-OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
-IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
---------------------------------------------------------------------------*/
-
-#ifndef SENSOR_INFO_MANAGER_H
-#define SENSOR_INFO_MANAGER_H
-
-#include <string.h>
-#include <dirent.h>
-#include <utils/Log.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <SensorBase.h>
-
-#include <utils/Singleton.h>
-#include <cutils/list.h>
-#include <sensors.h>
-#include <utils/KeyedVector.h>
-
-#include "AccelSensor.h"
-#include "LightSensor.h"
-#include "ProximitySensor.h"
-#include "CompassSensor.h"
-#include "GyroSensor.h"
-#include "VirtualSensor.h"
-
-#include "sensors_extension.h"
-#include "sensors_XML.h"
-using namespace android;
-
-#define EVENT_PATH "/dev/input/"
-#define DEPEND_ON(m, t) (m & (1ULL << t))
-#define SENSORS_HANDLE(x) (SENSORS_HANDLE_BASE + x + 1)
-
-#ifndef list_for_each_safe
-#define list_for_each_safe(node, n, list) \
- for (node = (list)->next, n = node->next; \
- node != (list); \
- node = n, n = node->next)
-#endif
-
-enum {
- TYPE_STRING = 0,
- TYPE_INTEGER,
- TYPE_FLOAT,
-};
-
-struct SensorContext {
- char name[SYSFS_MAXLEN]; // name of the sensor
- char vendor[SYSFS_MAXLEN]; // vendor of the sensor
- char *enable_path; // the control path to enable this sensor
- char *data_path; // the data path to get sensor events
-
- struct sensor_t *sensor; // point to the sensor_t structure in the sensor list
- SensorBase *driver; // point to the sensor driver instance
-
- int data_fd; // the file descriptor of the data device node
- int enable; // indicate if the sensor is enabled
- bool is_virtual; // indicate if this is a virtual sensor
- int64_t delay_ns; // the poll delay setting of this sensor
- struct listnode dep_list; // the background sensor type needed for this sensor
-
- struct listnode listener; // the head of listeners of this sensor
-};
-
-struct SensorEventMap {
- char data_name[80];
- char data_path[PATH_MAX];
-};
-
-struct SysfsMap {
- int offset;
- const char *node;
- int type;
-};
-
-/* To contain the listener list and denpend list */
-struct SensorRefMap {
- struct listnode list;
- struct SensorContext *ctx;
-};
-
-class NativeSensorManager : public Singleton<NativeSensorManager> {
- friend class Singleton<NativeSensorManager>;
- NativeSensorManager();
- ~NativeSensorManager();
- struct sensor_t sensor_list[MAX_SENSORS];
- struct SensorContext context[MAX_SENSORS];
- struct SensorEventMap event_list[MAX_SENSORS];
- static const struct SysfsMap node_map[];
- static const struct sensor_t virtualSensorList[];
-
- int mSensorCount;
-
- DefaultKeyedVector<int32_t, struct SensorContext*> type_map;
- DefaultKeyedVector<int32_t, struct SensorContext*> handle_map;
- DefaultKeyedVector<int, struct SensorContext*> fd_map;
-
- int getNode(char *buf, char *path, const struct SysfsMap *map);
- int getSensorListInner();
- int getDataInfo();
- int registerListener(struct SensorContext *hw, struct SensorContext *virt);
- int unregisterListener(struct SensorContext *hw, struct SensorContext *virt);
- int syncDelay(int handle);
- int initVirtualSensor(struct SensorContext *ctx, int handle, int64_t dep, struct sensor_t info);
- int initCalibrate(const SensorContext *list);
-public:
- int getSensorList(const sensor_t **list);
- inline SensorContext* getInfoByFd(int fd) { return fd_map.valueFor(fd); };
- inline SensorContext* getInfoByHandle(int handle) { return handle_map.valueFor(handle); };
- inline SensorContext* getInfoByType(int type) { return type_map.valueFor(type); };
- int getSensorCount() {return mSensorCount;}
- void dump();
- int hasPendingEvents(int handle);
- int activate(int handle, int enable);
- int setDelay(int handle, int64_t ns);
- int readEvents(int handle, sensors_event_t *data, int count);
- int calibrate(int handle, struct cal_cmd_t *para);
-};
-
-#endif
-
diff --git a/sensors/ProximitySensor.cpp b/sensors/ProximitySensor.cpp
deleted file mode 100644
index 0016ef3..0000000
--- a/sensors/ProximitySensor.cpp
+++ /dev/null
@@ -1,422 +0,0 @@
-/*
- * Copyright (c) 2014, The Linux Foundation. All rights reserved.
- * Not a Contribution.
- * Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <fcntl.h>
-#include <errno.h>
-#include <math.h>
-#include <poll.h>
-#include <unistd.h>
-#include <dirent.h>
-#include <sys/select.h>
-#include <cutils/log.h>
-#include <cutils/properties.h>
-
-#include "ProximitySensor.h"
-#include "sensors.h"
-
-#define EVENT_TYPE_PROXIMITY ABS_DISTANCE
-
-#define PROXIMITY_THRESHOLD 5.0f
-/*****************************************************************************/
-
-enum input_device_name {
- GENERIC_PSENSOR = 0,
- LEGACY_PSENSOR,
- AP3426_PS,
- SUPPORTED_PSENSOR_COUNT,
-};
-
-static const char *data_device_name[SUPPORTED_PSENSOR_COUNT] = {
- [GENERIC_PSENSOR] = "proximity",
- [LEGACY_PSENSOR] = "proximity",
- [AP3426_PS] = "ap3426-proximity",
-};
-
-static const char *input_sysfs_path_list[SUPPORTED_PSENSOR_COUNT] = {
- /* This is not used by generic HAL. Just for back compatibility */
- [GENERIC_PSENSOR] = "/sys/class/input/%s/device/",
- [LEGACY_PSENSOR] = "/sys/class/input/%s/device/",
- [AP3426_PS] = "/sys/class/input/%s/device/",
-};
-
-static const char *input_sysfs_enable_list[SUPPORTED_PSENSOR_COUNT] = {
- [GENERIC_PSENSOR] = "enable",
- [LEGACY_PSENSOR] = "enable",
- [AP3426_PS] = "enable",
-};
-
-
-ProximitySensor::ProximitySensor()
- : SensorBase(NULL, NULL),
- mEnabled(0),
- mInputReader(4),
- mHasPendingEvent(false),
- sensor_index(-1),
- mThreshold_h(0),
- mThreshold_l(0),
- mBias(0)
-{
- int i;
- mPendingEvent.version = sizeof(sensors_event_t);
- mPendingEvent.sensor = SENSORS_PROXIMITY_HANDLE;
- mPendingEvent.type = SENSOR_TYPE_PROXIMITY;
- memset(mPendingEvent.data, 0, sizeof(mPendingEvent.data));
-
- for(i = 0; i < SUPPORTED_PSENSOR_COUNT; i++) {
- data_name = data_device_name[i];
-
- // data_fd is not initialized if data_name passed
- // to SensorBase is NULL.
- data_fd = openInput(data_name);
- if (data_fd > 0) {
- sensor_index = i;
- break;
- }
- }
-
- if (data_fd > 0) {
- snprintf(input_sysfs_path, sizeof(input_sysfs_path),
- input_sysfs_path_list[i], input_name);
- input_sysfs_path_len = strlen(input_sysfs_path);
- enable(0, 1);
- }
-
- ALOGI("The proximity sensor path is %s",input_sysfs_path);
-}
-
-ProximitySensor::ProximitySensor(struct SensorContext *context)
- : SensorBase(NULL, NULL),
- mEnabled(0),
- mInputReader(4),
- mHasPendingEvent(false),
- sensor_index(GENERIC_PSENSOR),
- mThreshold_h(0),
- mThreshold_l(0),
- mBias(0)
-{
- mPendingEvent.version = sizeof(sensors_event_t);
- mPendingEvent.sensor = context->sensor->handle;
- mPendingEvent.type = SENSOR_TYPE_PROXIMITY;
- memset(mPendingEvent.data, 0, sizeof(mPendingEvent.data));
-
- data_fd = context->data_fd;
- strlcpy(input_sysfs_path, context->enable_path, sizeof(input_sysfs_path));
- input_sysfs_path_len = strlen(input_sysfs_path);
-}
-
-ProximitySensor::ProximitySensor(char *name)
- : SensorBase(NULL, data_device_name[GENERIC_PSENSOR]),
- mEnabled(0),
- mInputReader(4),
- mHasPendingEvent(false),
- sensor_index(GENERIC_PSENSOR),
- mThreshold_h(0),
- mThreshold_l(0),
- mBias(0)
-{
- mPendingEvent.version = sizeof(sensors_event_t);
- mPendingEvent.sensor = SENSORS_PROXIMITY_HANDLE;
- mPendingEvent.type = SENSOR_TYPE_PROXIMITY;
- memset(mPendingEvent.data, 0, sizeof(mPendingEvent.data));
-
- if (data_fd) {
- strlcpy(input_sysfs_path, SYSFS_CLASS, sizeof(input_sysfs_path));
- strlcat(input_sysfs_path, name, sizeof(input_sysfs_path));
- strlcat(input_sysfs_path, "/", sizeof(input_sysfs_path));
- input_sysfs_path_len = strlen(input_sysfs_path);
- ALOGI("The proximity sensor path is %s",input_sysfs_path);
- enable(0, 1);
- }
-}
-ProximitySensor::~ProximitySensor() {
- if (mEnabled) {
- enable(0, 0);
- }
-}
-
-int ProximitySensor::enable(int32_t, int en) {
- int flags = en ? 1 : 0;
- char propBuf[PROPERTY_VALUE_MAX];
- property_get("sensors.proxymity.loopback", propBuf, "0");
- if (strcmp(propBuf, "1") == 0) {
- mEnabled = flags;
- ALOGE("sensors.proxymity.loopback is set");
- return 0;
- }
-
- if (flags != mEnabled) {
- int fd;
- if (sensor_index >= 0) {
- strlcpy(&input_sysfs_path[input_sysfs_path_len], input_sysfs_enable_list[sensor_index],
- sizeof(input_sysfs_path) - input_sysfs_path_len);
- } else {
- ALOGE("invalid sensor index:%d\n", sensor_index);
- return -1;
- }
-
- mEnabled = flags;
- /**
- * this is an on-change sensor. it might not get a reading for a while
- * and Android requires a reading as soon as it is turned on.
- * re-send the last reading.
- */
- mHasPendingEvent = flags;
- fd = open(input_sysfs_path, O_RDWR);
- if (fd >= 0) {
- char buf[2];
- buf[1] = 0;
- if (flags) {
- buf[0] = '1';
- } else {
- buf[0] = '0';
- }
- write(fd, buf, sizeof(buf));
- close(fd);
- } else {
- ALOGE("open %s failed.(%s)\n", input_sysfs_path, strerror(errno));
- return -1;
- }
-
- if (mEnabled) {
- struct input_absinfo absinfo;
- int rc = ioctl(data_fd, EVIOCGABS(EVENT_TYPE_PROXIMITY), &absinfo);
- if (rc < 0) {
- ALOGE("ProximitySensor: EVIOCGABS error: %d", errno);
- return -errno;
- }
-
- mPendingEvent.distance = indexToValue(absinfo.value);
- return 0;
- }
- }
- return 0;
-}
-
-bool ProximitySensor::hasPendingEvents() const {
- return mHasPendingEvent;
-}
-
-int ProximitySensor::readEvents(sensors_event_t* data, int count)
-{
- if (count < 1)
- return -EINVAL;
-
- if (mHasPendingEvent) {
- mHasPendingEvent = false;
- mPendingEvent.timestamp = getTimestamp();
- *data = mPendingEvent;
- return mEnabled ? 1 : 0;
- }
-
- ssize_t n = mInputReader.fill(data_fd);
- if (n < 0)
- return n;
-
- int numEventReceived = 0;
- input_event const* event;
-
- while (count && mInputReader.readEvent(&event)) {
- int type = event->type;
- if (type == EV_ABS) {
- if (event->code == EVENT_TYPE_PROXIMITY) {
- if (event->value != -1) {
- // FIXME: not sure why we're getting -1 sometimes
- mPendingEvent.distance = indexToValue(event->value);
- }
- }
- } else if (type == EV_SYN) {
- switch ( event->code ){
- case SYN_TIME_SEC:
- {
- mUseAbsTimeStamp = true;
- report_time = event->value*1000000000LL;
- }
- break;
- case SYN_TIME_NSEC:
- {
- mUseAbsTimeStamp = true;
- mPendingEvent.timestamp = report_time+event->value;
- }
- break;
- case SYN_REPORT:
- {
- if (mEnabled && mUseAbsTimeStamp) {
- *data++ = mPendingEvent;
- numEventReceived++;
- count--;
- mUseAbsTimeStamp = false;
- } else {
- ALOGE_IF(!mUseAbsTimeStamp, "ProximitySensor: timestamp not received");
- }
- }
- break;
- }
- } else {
- ALOGE("ProximitySensor: unknown event (type=%d, code=%d)",
- type, event->code);
- }
- mInputReader.next();
- }
-
- return numEventReceived;
-}
-
-float ProximitySensor::indexToValue(size_t index) const
-{
- return index * PROXIMITY_THRESHOLD;
-}
-
-int ProximitySensor::calibrate(int32_t handle, struct cal_cmd_t *para,
- struct cal_result_t *cal_result)
-{
- int fd;
- char temp[3][LENGTH];
- char buf[3 * LENGTH];
- char *token, *strsaveptr, *endptr;
- int i, err;
- off_t offset;
- int para1 = 0;
- if (para == NULL || cal_result == NULL) {
- ALOGE("Null pointer calibrate parameters\n");
- return -1;
- }
- para1 = CMD_CAL(para->axis, para->apply_now);
- strlcpy(&input_sysfs_path[input_sysfs_path_len],
- SYSFS_CALIBRATE, SYSFS_MAXLEN);
- fd = open(input_sysfs_path, O_RDWR);
- if (fd >= 0) {
- snprintf(buf, sizeof(buf), "%d", para1);
- err = write(fd, buf, strlen(buf)+1);
- if(err < 0) {
- ALOGE("write error\n");
- close(fd);
- return err;
- }
- } else {
- return -1;
- }
- if (fd >= 0) {
- offset = lseek(fd, 0, SEEK_SET);
- char *p = buf;
- memset(buf, 0, sizeof(buf));
- err = read(fd, buf, sizeof(buf)-1);
- if(err < 0) {
- ALOGE("proximity read error\n");
- close(fd);
- return err;
- }
- for(i = 0; sizeof(temp) / LENGTH; i++, p = NULL) {
- token = strtok_r(p, ",", &strsaveptr);
- if(token == NULL)
- break;
- if(strlen(token) > LENGTH - 1) {
- ALOGE("token is too long\n");
- close(fd);
- return -1;
- }
- strlcpy(temp[i], token, sizeof(temp[i]));
- }
- close(fd);
- if (para->axis == 0) {
- mThreshold_h = strtol(temp[0], &endptr, 10);
- if (mThreshold_h == LONG_MAX || mThreshold_h == LONG_MIN) {
- ALOGE("mThreshold_h error value\n");
- return -1;
- }
- if (endptr == temp[0]) {
- ALOGE("No digits were found\n");
- return -1;
- }
- } else if (para->axis == 1) {
- mThreshold_l = strtol(temp[1], &endptr, 10);
- if (mThreshold_l == LONG_MAX || mThreshold_l == LONG_MIN) {
- ALOGE("mThreshold_l error value\n");
- return -1;
- }
- if (endptr == temp[1]) {
- ALOGE("No digits were found\n");
- return -1;
- }
- } else if (para->axis == 2) {
- mBias = strtol(temp[2], &endptr, 10);
- if (mBias == LONG_MAX || mBias == LONG_MIN) {
- ALOGE("mBias error value\n");
- return -1;
- }
- if (endptr == temp[2]) {
- ALOGE("No digits were found\n");
- return -1;
- }
- }
- cal_result->threshold_h = mThreshold_h;
- cal_result->threshold_l = mThreshold_l;
- cal_result->bias = mBias;
- return 0;
- } else {
- ALOGE("open %s error\n", input_sysfs_path);
- return -1;
- }
- return 0;
-}
-
-int ProximitySensor::initCalibrate(int32_t handle, struct cal_result_t *cal_result)
-{
- int fd , i, err;
- char buf[33];
- int arry[] = {CMD_W_THRESHOLD_H, CMD_W_THRESHOLD_L, CMD_W_BIAS};
- if (cal_result == NULL) {
- ALOGE("Null pointer initcalibrate parameter\n");
- return -1;
- }
- strlcpy(&input_sysfs_path[input_sysfs_path_len],
- SYSFS_CALIBRATE, SYSFS_MAXLEN);
- fd = open(input_sysfs_path, O_RDWR);
- if (fd >= 0) {
- int temp, para1 = 0;
- for(i = 0; i < sizeof(arry) / sizeof(int); ++i) {
- para1 = SET_CMD_H(cal_result->offset[i], arry[i]);
- snprintf(buf, sizeof(buf), "%d",
- para1);
- err = write(fd, buf, strlen(buf)+1);
- if(err < 0) {
- ALOGE("write error\n");
- close(fd);
- return err;
- }
-
- memset(buf, 0, sizeof(buf));
- para1 = SET_CMD_L(cal_result->offset[i], arry[i]);
- snprintf(buf, sizeof(buf), "%d",
- para1);
- write(fd, buf, strlen(buf)+1);
- if(err < 0) {
- ALOGE("write error\n");
- close(fd);
- return err;
- }
-
- }
- memset(buf, 0, sizeof(buf));
- snprintf(buf, sizeof(buf), "%d", CMD_COMPLETE);
- write(fd, buf, strlen(buf)+1);
- close(fd);
- return 0;
- }
- ALOGE("open %s error\n", input_sysfs_path);
- return -1;
-}
diff --git a/sensors/ProximitySensor.h b/sensors/ProximitySensor.h
deleted file mode 100644
index 89b107f..0000000
--- a/sensors/ProximitySensor.h
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef ANDROID_PROXIMITY_SENSOR_H
-#define ANDROID_PROXIMITY_SENSOR_H
-
-#include <stdint.h>
-#include <errno.h>
-#include <sys/cdefs.h>
-#include <sys/types.h>
-
-#include "SensorBase.h"
-#include "InputEventReader.h"
-#include "NativeSensorManager.h"
-
-/*****************************************************************************/
-
-struct input_event;
-
-class ProximitySensor : public SensorBase {
- int mEnabled;
- InputEventCircularReader mInputReader;
- sensors_event_t mPendingEvent;
- bool mHasPendingEvent;
- char input_sysfs_path[PATH_MAX];
- int input_sysfs_path_len;
- int sensor_index;
- int mThreshold_h;
- int mThreshold_l;
- int mBias;
-
- int setInitialState();
- float indexToValue(size_t index) const;
-
-public:
- ProximitySensor();
- ProximitySensor(char *name);
- ProximitySensor(struct SensorContext *context);
- virtual ~ProximitySensor();
- virtual int readEvents(sensors_event_t* data, int count);
- virtual bool hasPendingEvents() const;
- virtual int enable(int32_t handle, int enabled);
- virtual int calibrate(int32_t handle, struct cal_cmd_t *para,
- struct cal_result_t *cal_result);
- virtual int initCalibrate(int32_t handle, struct cal_result_t *cal_result);
-};
-
-/*****************************************************************************/
-
-#endif // ANDROID_PROXIMITY_SENSOR_H
diff --git a/sensors/SensorBase.cpp b/sensors/SensorBase.cpp
deleted file mode 100644
index 72e360d..0000000
--- a/sensors/SensorBase.cpp
+++ /dev/null
@@ -1,153 +0,0 @@
-/*
- * Copyright (c) 2014, The Linux Foundation. All rights reserved.
- * Not a Contribution.
- * Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <fcntl.h>
-#include <errno.h>
-#include <math.h>
-#include <poll.h>
-#include <unistd.h>
-#include <dirent.h>
-#include <sys/select.h>
-
-#include <cutils/log.h>
-
-#include <linux/input.h>
-
-#include "NativeSensorManager.h"
-#include "SensorBase.h"
-
-/*****************************************************************************/
-
-SensorBase::SensorBase(
- const char* dev_name,
- const char* data_name,
- const struct SensorContext* context /* = NULL */)
- : dev_name(dev_name), data_name(data_name),
- algo(NULL), dev_fd(-1), data_fd(-1)
-{
- if (context != NULL) {
- CalibrationManager& cm(CalibrationManager::getInstance());
- algo = cm.getCalAlgo(context->sensor);
- }
-
- if (data_name) {
- data_fd = openInput(data_name);
- }
-}
-
-SensorBase::~SensorBase() {
- if (data_fd >= 0) {
- close(data_fd);
- }
- if (dev_fd >= 0) {
- close(dev_fd);
- }
-}
-
-int SensorBase::open_device() {
- if (dev_fd<0 && dev_name) {
- dev_fd = open(dev_name, O_RDONLY);
- ALOGE_IF(dev_fd<0, "Couldn't open %s (%s)", dev_name, strerror(errno));
- }
- return 0;
-}
-
-int SensorBase::close_device() {
- if (dev_fd >= 0) {
- close(dev_fd);
- dev_fd = -1;
- }
- return 0;
-}
-
-int SensorBase::getFd() const {
- if (!data_name) {
- return dev_fd;
- }
- return data_fd;
-}
-
-int SensorBase::setDelay(int32_t, int64_t) {
- return 0;
-}
-
-bool SensorBase::hasPendingEvents() const {
- return false;
-}
-
-int64_t SensorBase::getTimestamp() {
- struct timespec t;
- t.tv_sec = t.tv_nsec = 0;
- clock_gettime(CLOCK_BOOTTIME, &t);
- return int64_t(t.tv_sec)*1000000000LL + t.tv_nsec;
-}
-
-int SensorBase::openInput(const char* inputName) {
- int fd = -1;
- const char *dirname = "/dev/input";
- char devname[PATH_MAX];
- char *filename;
- DIR *dir;
- struct dirent *de;
- dir = opendir(dirname);
- if(dir == NULL)
- return -1;
- strcpy(devname, dirname);
- filename = devname + strlen(devname);
- *filename++ = '/';
- while((de = readdir(dir))) {
- if(de->d_name[0] == '.' &&
- (de->d_name[1] == '\0' ||
- (de->d_name[1] == '.' && de->d_name[2] == '\0')))
- continue;
- strcpy(filename, de->d_name);
- fd = open(devname, O_RDONLY);
- if (fd>=0) {
- char name[80];
- if (ioctl(fd, EVIOCGNAME(sizeof(name) - 1), &name) < 1) {
- name[0] = '\0';
- }
- if (!strcmp(name, inputName)) {
- strcpy(input_name, filename);
- break;
- } else {
- close(fd);
- fd = -1;
- }
- }
- }
- closedir(dir);
- ALOGE_IF(fd<0, "couldn't find '%s' input device", inputName);
- return fd;
-}
-
-int SensorBase::injectEvents(sensors_event_t*, int)
-{
- return 0;
-}
-
-int SensorBase::calibrate(int32_t handle, struct cal_cmd_t *para,
- struct cal_result_t *outpara)
-{
- return -1;
-}
-
-int SensorBase::initCalibrate(int32_t handle, struct cal_result_t *prar)
-{
- return -1;
-}
diff --git a/sensors/SensorBase.h b/sensors/SensorBase.h
deleted file mode 100644
index 90ea1f7..0000000
--- a/sensors/SensorBase.h
+++ /dev/null
@@ -1,77 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef ANDROID_SENSOR_BASE_H
-#define ANDROID_SENSOR_BASE_H
-
-#include <stdint.h>
-#include <errno.h>
-#include <sys/cdefs.h>
-#include <sys/types.h>
-#include <linux/input.h>
-
-#include <hardware/hardware.h>
-#include <hardware/sensors.h>
-#include <CalibrationManager.h>
-#include <sensors_extension.h>
-
-/*****************************************************************************/
-
-struct sensors_event_t;
-struct SensorContext;
-
-class SensorBase {
-protected:
- const char* dev_name;
- const char* data_name;
- const sensor_cal_algo_t* algo;
- char input_name[PATH_MAX];
- int dev_fd;
- int data_fd;
- int64_t report_time;
- bool mUseAbsTimeStamp;
-
- int openInput(const char* inputName);
- static int64_t getTimestamp();
-
-
- static int64_t timevalToNano(timeval const& t) {
- return t.tv_sec*1000000000LL + t.tv_usec*1000;
- }
-
- int open_device();
- int close_device();
-
-public:
- SensorBase(const char* dev_name, const char* data_name,
- const struct SensorContext* context = NULL);
-
- virtual ~SensorBase();
-
- virtual int readEvents(sensors_event_t* data, int count) = 0;
- virtual int injectEvents(sensors_event_t* data, int count);
- virtual bool hasPendingEvents() const;
- virtual int getFd() const;
- virtual int setDelay(int32_t handle, int64_t ns);
- virtual int enable(int32_t handle, int enabled) = 0;
- virtual int calibrate(int32_t handle, struct cal_cmd_t *para,
- struct cal_result_t *outpara);
- virtual int initCalibrate(int32_t handle, struct cal_result_t *prar);
-};
-
-/*****************************************************************************/
-
-#endif // ANDROID_SENSOR_BASE_H
diff --git a/sensors/VirtualSensor.cpp b/sensors/VirtualSensor.cpp
deleted file mode 100644
index 0bfe0a0..0000000
--- a/sensors/VirtualSensor.cpp
+++ /dev/null
@@ -1,128 +0,0 @@
-/*--------------------------------------------------------------------------
-Copyright (c) 2014, The Linux Foundation. All rights reserved.
-
-Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions are
-met:
- * Redistributions of source code must retain the above copyright
- notice, this list of conditions and the following disclaimer.
- * Redistributions in binary form must reproduce the above
- copyright notice, this list of conditions and the following
- disclaimer in the documentation and/or other materials provided
- with the distribution.
- * Neither the name of The Linux Foundation nor the names of its
- contributors may be used to endorse or promote products derived
- from this software without specific prior written permission.
-
-THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
-WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
-MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
-ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
-BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
-CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
-SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
-BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
-OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
-IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
---------------------------------------------------------------------------*/
-
-#include <fcntl.h>
-#include <errno.h>
-#include <math.h>
-#include <poll.h>
-#include <unistd.h>
-#include <dirent.h>
-#include <float.h>
-#include <sys/select.h>
-#include <cutils/log.h>
-
-#include "VirtualSensor.h"
-#include "sensors.h"
-
-/*****************************************************************************/
-
-VirtualSensor::VirtualSensor(const struct SensorContext *ctx)
- : SensorBase(NULL, NULL, ctx),
- mEnabled(0),
- mHasPendingEvent(false),
- mEnabledTime(0),
- context(ctx),
- mRead(mBuffer),
- mWrite(mBuffer),
- mBufferEnd(mBuffer + MAX_EVENTS),
- mFreeSpace(MAX_EVENTS)
-
-{
- enable(0, 1);
-}
-
-VirtualSensor::~VirtualSensor() {
- if (mEnabled) {
- enable(0, 0);
- }
-}
-
-int VirtualSensor::enable(int32_t, int en) {
- mEnabled = en? 1 : 0;
- return 0;
-}
-
-bool VirtualSensor::hasPendingEvents() const {
- return mBufferEnd - mBuffer - mFreeSpace;
-}
-
-int VirtualSensor::readEvents(sensors_event_t* data, int count)
-{
- int number = 0;
-
- if (count < 1)
- return -EINVAL;
-
- while (count && (mBufferEnd - mBuffer - mFreeSpace)) {
- *data++ = *mRead++;
- if (mRead >= mBufferEnd)
- mRead = mBuffer;
- number++;
- mFreeSpace++;
- count--;
- }
-
- return number;
-}
-
-int VirtualSensor::injectEvents(sensors_event_t* data, int count)
-{
- int i;
- sensors_event_t event;
-
- if (algo == NULL)
- return 0;
-
- for (i = 0; i < count; i++) {
- event = data[i];
-
- if (mFreeSpace) {
- sensors_event_t out;
- if (algo->methods->convert(&event, &out, NULL))
- continue;
-
- out.version = sizeof(sensors_event_t);
- out.sensor = context->sensor->handle;
- out.type = context->sensor->type;
- out.timestamp = event.timestamp;
-
- *mWrite++ = out;
- mFreeSpace--;
- if (mWrite >= mBufferEnd) {
- mWrite = mBuffer;
- }
-
- } else {
- ALOGW("Circular buffer is full\n");
- }
- }
-
- return 0;
-}
-
diff --git a/sensors/VirtualSensor.h b/sensors/VirtualSensor.h
deleted file mode 100644
index 17c5161..0000000
--- a/sensors/VirtualSensor.h
+++ /dev/null
@@ -1,70 +0,0 @@
-/*--------------------------------------------------------------------------
-Copyright (c) 2014, The Linux Foundation. All rights reserved.
-
-Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions are
-met:
- * Redistributions of source code must retain the above copyright
- notice, this list of conditions and the following disclaimer.
- * Redistributions in binary form must reproduce the above
- copyright notice, this list of conditions and the following
- disclaimer in the documentation and/or other materials provided
- with the distribution.
- * Neither the name of The Linux Foundation nor the names of its
- contributors may be used to endorse or promote products derived
- from this software without specific prior written permission.
-
-THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
-WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
-MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
-ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
-BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
-CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
-SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
-BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
-OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
-IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
---------------------------------------------------------------------------*/
-#ifndef ANDROID_VIRTUAL_SENSOR_H
-#define ANDROID_VIRTUAL_SENSOR_H
-
-#include <stdint.h>
-#include <errno.h>
-#include <sys/cdefs.h>
-#include <sys/types.h>
-
-#include "SensorBase.h"
-#include "InputEventReader.h"
-#include "NativeSensorManager.h"
-
-/*****************************************************************************/
-
-#define MAX_EVENTS 250
-
-struct input_event;
-
-class VirtualSensor : public SensorBase {
- int mEnabled;
- sensors_vec_t dm;
- sensors_vec_t da;
- bool mHasPendingEvent;
- int64_t mEnabledTime;
- const SensorContext *context;
- sensors_event_t mBuffer[MAX_EVENTS];
- sensors_event_t* mRead;
- sensors_event_t* mWrite;
- sensors_event_t* mBufferEnd;
- ssize_t mFreeSpace;
-public:
- VirtualSensor(const struct SensorContext *i);
- virtual ~VirtualSensor();
- virtual int readEvents(sensors_event_t* data, int count);
- virtual bool hasPendingEvents() const;
- virtual int enable(int32_t handle, int enabled);
- virtual int injectEvents(sensors_event_t* data, int count);
-};
-
-/*****************************************************************************/
-
-#endif // ANDROID_VIRTUAL_SENSOR_H
diff --git a/sensors/algo/akm/AKFS_AOC.c b/sensors/algo/akm/AKFS_AOC.c
deleted file mode 100644
index 41c115f..0000000
--- a/sensors/algo/akm/AKFS_AOC.c
+++ /dev/null
@@ -1,333 +0,0 @@
-/******************************************************************************
- *
- * Copyright (C) 2012 Asahi Kasei Microdevices Corporation, Japan
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- ******************************************************************************/
-#include "AKFS_AOC.h"
-#include "AKFS_Math.h"
-
-/*
- * CalcR
- */
-static AKFLOAT CalcR(
- const AKFVEC *x,
- const AKFVEC *y
-){
- int16 i;
- AKFLOAT r;
-
- r = 0.0;
- for (i = 0; i < 3; i++) {
- r += (x->v[i]-y->v[i]) * (x->v[i]-y->v[i]);
- }
- r = sqrt(r);
-
- return r;
-}
-
-/*
- * From4Points2Sphere()
- */
-static int16 From4Points2Sphere(
- const AKFVEC points[], /*!< (i/o) : input vectors */
- AKFVEC *center, /*!< (o) : center of sphere */
- AKFLOAT *r /*!< (i) : add/subtract value */
-){
- AKFLOAT dif[3][3];
- AKFLOAT r2[3];
-
- AKFLOAT A;
- AKFLOAT B;
- AKFLOAT C;
- AKFLOAT D;
- AKFLOAT E;
- AKFLOAT F;
- AKFLOAT G;
-
- AKFLOAT OU;
- AKFLOAT OD;
-
- int16 i, j;
-
- for (i = 0; i < 3; i++) {
- r2[i] = 0.0;
- for (j = 0; j < 3; j++) {
- dif[i][j] = points[i].v[j] - points[3].v[j];
- r2[i] += (points[i].v[j]*points[i].v[j]
- - points[3].v[j]*points[3].v[j]);
- }
- r2[i] *= 0.5;
- }
-
- A = dif[0][0]*dif[2][2] - dif[0][2]*dif[2][0];
- B = dif[0][1]*dif[2][0] - dif[0][0]*dif[2][1];
- C = dif[0][0]*dif[2][1] - dif[0][1]*dif[2][0];
- D = dif[0][0]*r2[2] - dif[2][0]*r2[0];
- E = dif[0][0]*dif[1][1] - dif[0][1]*dif[1][0];
- F = dif[1][0]*dif[0][2] - dif[0][0]*dif[1][2];
- G = dif[0][0]*r2[1] - dif[1][0]*r2[0];
-
- OU = D*E + B*G;
- OD = C*F + A*E;
-
- if (fabs(OD) < AKFS_EPSILON) {
- return -1;
- }
-
- center->v[2] = OU / OD;
-
- OU = F*center->v[2] + G;
- OD = E;
-
- if (fabs(OD) < AKFS_EPSILON) {
- return -1;
- }
-
- center->v[1] = OU / OD;
-
- OU = r2[0] - dif[0][1]*center->v[1] - dif[0][2]*center->v[2];
- OD = dif[0][0];
-
- if (fabs(OD) < AKFS_EPSILON) {
- return -1;
- }
-
- center->v[0] = OU / OD;
-
- *r = CalcR(&points[0], center);
-
- return 0;
-
-}
-
-/*
- * MeanVar
- */
-static void MeanVar(
- const AKFVEC v[], /*!< (i) : input vectors */
- const int16 n, /*!< (i) : number of vectors */
- AKFVEC *mean, /*!< (o) : (max+min)/2 */
- AKFVEC *var /*!< (o) : variation in vectors */
-){
- int16 i;
- int16 j;
- AKFVEC max;
- AKFVEC min;
-
- for (j = 0; j < 3; j++) {
- min.v[j] = v[0].v[j];
- max.v[j] = v[0].v[j];
- for (i = 1; i < n; i++) {
- if (v[i].v[j] < min.v[j]) {
- min.v[j] = v[i].v[j];
- }
- if (v[i].v[j] > max.v[j]) {
- max.v[j] = v[i].v[j];
- }
- }
- mean->v[j] = (max.v[j] + min.v[j]) / 2.0; /*mean */
- var->v[j] = max.v[j] - min.v[j]; /*var */
- }
-}
-
-/*
- * Get4points
- */
-static void Get4points(
- const AKFVEC v[], /*!< (i) : input vectors */
- const int16 n, /*!< (i) : number of vectors */
- AKFVEC out[] /*!< (o) : */
-){
- int16 i, j;
- AKFLOAT temp;
- AKFLOAT d;
-
- AKFVEC dv[AKFS_HBUF_SIZE];
- AKFVEC cross = {{0, 0, 0}};
- AKFVEC tempv = {{0, 0, 0}};
-
- /* out 0 */
- out[0] = v[0];
-
- /* out 1 */
- d = 0.0;
- for (i = 1; i < n; i++) {
- temp = CalcR(&v[i], &out[0]);
- if (d < temp) {
- d = temp;
- out[1] = v[i];
- }
- }
-
- /* out 2 */
- d = 0.0;
- for (j = 0; j < 3; j++) {
- dv[0].v[j] = out[1].v[j] - out[0].v[j];
- }
- for (i = 1; i < n; i++) {
- for (j = 0; j < 3; j++) {
- dv[i].v[j] = v[i].v[j] - out[0].v[j];
- }
- tempv.v[0] = dv[0].v[1]*dv[i].v[2] - dv[0].v[2]*dv[i].v[1];
- tempv.v[1] = dv[0].v[2]*dv[i].v[0] - dv[0].v[0]*dv[i].v[2];
- tempv.v[2] = dv[0].v[0]*dv[i].v[1] - dv[0].v[1]*dv[i].v[0];
- temp = tempv.u.x * tempv.u.x
- + tempv.u.y * tempv.u.y
- + tempv.u.z * tempv.u.z;
- if (d < temp) {
- d = temp;
- out[2] = v[i];
- cross = tempv;
- }
- }
-
- /* out 3 */
- d = 0.0;
- for (i = 1; i < n; i++) {
- temp = dv[i].u.x * cross.u.x
- + dv[i].u.y * cross.u.y
- + dv[i].u.z * cross.u.z;
- temp = fabs(temp);
- if (d < temp) {
- d = temp;
- out[3] = v[i];
- }
- }
-}
-
-/*
- * CheckInitFvec
- */
-static int16 CheckInitFvec(
- const AKFVEC *v /*!< [in] vector */
-){
- int16 i;
-
- for (i = 0; i < 3; i++) {
- if (AKFS_FMAX <= v->v[i]) {
- return 1; /* initvalue */
- }
- }
-
- return 0; /* not initvalue */
-}
-
-/*
- * AKFS_AOC
- */
-int16 AKFS_AOC( /*!< (o) : calibration success(AKFS_SUCCESS), failure(AKFS_ERROR) */
- AKFS_AOC_VAR *haocv, /*!< (i/o) : a set of variables */
- const AKFVEC *hdata, /*!< (i) : vectors of data */
- AKFVEC *ho /*!< (i/o) : offset */
-){
- int16 i, j;
- int16 num;
- AKFLOAT tempf;
- AKFVEC tempho;
-
- AKFVEC fourpoints[4];
-
- AKFVEC var;
- AKFVEC mean;
-
- /* buffer new data */
- for (i = 1; i < AKFS_HBUF_SIZE; i++) {
- haocv->hbuf[AKFS_HBUF_SIZE-i] = haocv->hbuf[AKFS_HBUF_SIZE-i-1];
- }
- haocv->hbuf[0] = *hdata;
-
- /* Check Init */
- num = 0;
- for (i = AKFS_HBUF_SIZE; 3 < i; i--) {
- if (CheckInitFvec(&haocv->hbuf[i-1]) == 0) {
- num = i;
- break;
- }
- }
- if (num < 4) {
- return AKFS_ERROR;
- }
-
- /* get 4 points */
- Get4points(haocv->hbuf, num, fourpoints);
-
- /* estimate offset */
- if (0 != From4Points2Sphere(fourpoints, &tempho, &haocv->hraoc)) {
- return AKFS_ERROR;
- }
-
- /* check distance */
- for (i = 0; i < 4; i++) {
- for (j = (i+1); j < 4; j++) {
- tempf = CalcR(&fourpoints[i], &fourpoints[j]);
- if ((tempf < haocv->hraoc) || (tempf < AKFS_HR_TH)) {
- return AKFS_ERROR;
- }
- }
- }
-
- /* update offset buffer */
- for (i = 1; i < AKFS_HOBUF_SIZE; i++) {
- haocv->hobuf[AKFS_HOBUF_SIZE-i] = haocv->hobuf[AKFS_HOBUF_SIZE-i-1];
- }
- haocv->hobuf[0] = tempho;
-
- /* clear hbuf */
- for (i = (AKFS_HBUF_SIZE>>1); i < AKFS_HBUF_SIZE; i++) {
- for (j = 0; j < 3; j++) {
- haocv->hbuf[i].v[j] = AKFS_FMAX;
- }
- }
-
- /* Check Init */
- if (CheckInitFvec(&haocv->hobuf[AKFS_HOBUF_SIZE-1]) == 1) {
- return AKFS_ERROR;
- }
-
- /* Check ovar */
- tempf = haocv->hraoc * AKFS_HO_TH;
- MeanVar(haocv->hobuf, AKFS_HOBUF_SIZE, &mean, &var);
- if ((var.u.x >= tempf) || (var.u.y >= tempf) || (var.u.z >= tempf)) {
- return AKFS_ERROR;
- }
-
- *ho = mean;
-
- return AKFS_SUCCESS;
-}
-
-/*
- * AKFS_InitAOC
- */
-void AKFS_InitAOC(
- AKFS_AOC_VAR *haocv
-){
- int16 i, j;
-
- /* Initialize buffer */
- for (i = 0; i < AKFS_HBUF_SIZE; i++) {
- for (j = 0; j < 3; j++) {
- haocv->hbuf[i].v[j] = AKFS_FMAX;
- }
- }
- for (i = 0; i < AKFS_HOBUF_SIZE; i++) {
- for (j = 0; j < 3; j++) {
- haocv->hobuf[i].v[j] = AKFS_FMAX;
- }
- }
-
- haocv->hraoc = 0.0;
-}
-
diff --git a/sensors/algo/akm/AKFS_AOC.h b/sensors/algo/akm/AKFS_AOC.h
deleted file mode 100644
index 7fff6c4..0000000
--- a/sensors/algo/akm/AKFS_AOC.h
+++ /dev/null
@@ -1,53 +0,0 @@
-/******************************************************************************
- *
- * Copyright (C) 2012 Asahi Kasei Microdevices Corporation, Japan
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- ******************************************************************************/
-#ifndef AKFS_INC_AOC_H
-#define AKFS_INC_AOC_H
-
-#include "AKFS_Device.h"
-
-/***** Constant definition ****************************************************/
-#define AKFS_HBUF_SIZE 20
-#define AKFS_HOBUF_SIZE 4
-#define AKFS_HR_TH 10
-#define AKFS_HO_TH 0.15
-
-/***** Macro definition *******************************************************/
-
-/***** Type declaration *******************************************************/
-typedef struct _AKFS_AOC_VAR{
- AKFVEC hbuf[AKFS_HBUF_SIZE];
- AKFVEC hobuf[AKFS_HOBUF_SIZE];
- AKFLOAT hraoc;
-} AKFS_AOC_VAR;
-
-/***** Prototype of function **************************************************/
-AKLIB_C_API_START
-int16 AKFS_AOC(
- AKFS_AOC_VAR *haocv,
- const AKFVEC *hdata,
- AKFVEC *ho
-);
-
-void AKFS_InitAOC(
- AKFS_AOC_VAR *haocv
-);
-
-AKLIB_C_API_END
-
-#endif
-
diff --git a/sensors/algo/akm/AKFS_Configure.h b/sensors/algo/akm/AKFS_Configure.h
deleted file mode 100644
index 1f80f48..0000000
--- a/sensors/algo/akm/AKFS_Configure.h
+++ /dev/null
@@ -1,37 +0,0 @@
-/******************************************************************************
- *
- * Copyright (C) 2012 Asahi Kasei Microdevices Corporation, Japan
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- ******************************************************************************/
-#ifndef AKFS_INC_CONFIG_H
-#define AKFS_INC_CONFIG_H
-
-/***** Language configuration *************************************************/
-#if defined(__cplusplus)
-#define AKLIB_C_API_START extern "C" {
-#define AKLIB_C_API_END }
-#else
-#define AKLIB_C_API_START
-#define AKLIB_C_API_END
-#endif
-
-/*! If following line is commented in, double type is used for floating point
- calculation */
-/*
-#define AKFS_PRECISION_DOUBLE
-*/
-
-#endif
-
diff --git a/sensors/algo/akm/AKFS_Decomp.c b/sensors/algo/akm/AKFS_Decomp.c
deleted file mode 100644
index da1d3ba..0000000
--- a/sensors/algo/akm/AKFS_Decomp.c
+++ /dev/null
@@ -1,51 +0,0 @@
-/******************************************************************************
- *
- * Copyright (C) 2012 Asahi Kasei Microdevices Corporation, Japan
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- ******************************************************************************/
-#include "AKFS_Decomp.h"
-#include "AKFS_Device.h"
-
-/******************************************************************************/
-/*! Convert from sensor local data unit to micro tesla, then buffer the data.
- @return #AKFS_SUCCESS on success. Otherwise the return value is #AKFS_ERROR.
- @param[in] mag
- @param[in] status
- @param[in] asa
- @param[in] nhdata
- @param[out] hdata
- */
-int16 AKFS_Decomp(
- const int16 mag[3],
- const int16 status,
- const uint8vec *asa,
- const int16 nhdata,
- AKFVEC hdata[]
-)
-{
- /* put st1 and st2 value */
- if (AKM_ST_ERROR(status)) {
- return AKFS_ERROR;
- }
-
- /* magnetic */
- AKFS_BufShift(nhdata, 1, hdata);
- hdata[0].u.x = AKM_HDATA_CONVERTER(mag[0], asa->u.x) * AKM_SENSITIVITY;
- hdata[0].u.y = AKM_HDATA_CONVERTER(mag[1], asa->u.y) * AKM_SENSITIVITY;
- hdata[0].u.z = AKM_HDATA_CONVERTER(mag[2], asa->u.z) * AKM_SENSITIVITY;
-
- return AKFS_SUCCESS;
-}
-
diff --git a/sensors/algo/akm/AKFS_Decomp.h b/sensors/algo/akm/AKFS_Decomp.h
deleted file mode 100644
index ef43fba..0000000
--- a/sensors/algo/akm/AKFS_Decomp.h
+++ /dev/null
@@ -1,58 +0,0 @@
-/******************************************************************************
- *
- * Copyright (C) 2012 Asahi Kasei Microdevices Corporation, Japan
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- ******************************************************************************/
-#ifndef AKFS_INC_DECOMP_H
-#define AKFS_INC_DECOMP_H
-
-#include "AKFS_Device.h"
-
-/***** Constant definition ****************************************************/
-#if defined(AKM_DEVICE_AK8963)
-#define AKM_SENSITIVITY 0.15f
-#define AKM_ST_ERROR(st) (((st)&0x19) != 0x11)
-#define AKM_HDATA_CONVERTER(data, asa) \
- (AKFLOAT)(((data)*(((asa)/256.0f) + 0.5f)))
-
-#elif defined(AKM_DEVICE_AK8975)
-#define AKM_SENSITIVITY 0.3f
-#define AKM_ST_ERROR(st) (((st)&0x09) != 0x01)
-#define AKM_HDATA_CONVERTER(data, asa) \
- (AKFLOAT)(((data)*(((asa)/256.0f) + 0.5f)))
-
-#elif defined(AKM_DEVICE_AK09911)
-#define AKM_SENSITIVITY 0.6f
-#define AKM_ST_ERROR(st) (((st)&0x09) != 0x01)
-#define AKM_HDATA_CONVERTER(data, asa) \
- (AKFLOAT)(((data)*(((asa)/128.0f) + 1.0f)))
-
-#endif
-
-
-/***** Type declaration *******************************************************/
-
-/***** Prototype of function **************************************************/
-AKLIB_C_API_START
-int16 AKFS_Decomp(
- const int16 mag[3],
- const int16 status,
- const uint8vec *asa,
- const int16 nhdata,
- AKFVEC hdata[]
-);
-AKLIB_C_API_END
-
-#endif
diff --git a/sensors/algo/akm/AKFS_Device.c b/sensors/algo/akm/AKFS_Device.c
deleted file mode 100644
index 75c36c3..0000000
--- a/sensors/algo/akm/AKFS_Device.c
+++ /dev/null
@@ -1,150 +0,0 @@
-/******************************************************************************
- *
- * Copyright (C) 2012 Asahi Kasei Microdevices Corporation, Japan
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- ******************************************************************************/
-#include "AKFS_Device.h"
-
-/******************************************************************************/
-/*! Initialize #AKFVEC array.
- @return #AKFS_SUCCESS on success. Otherwise the return value is #AKFS_ERROR.
- @param[in] ndata
- @param[out] vdata
- */
-int16 AKFS_InitBuffer(
- const int16 ndata, /*!< Size of vector buffer */
- AKFVEC vdata[] /*!< Vector buffer */
-)
-{
- int i;
-
- /* size check */
- if (ndata <= 0) {
- return AKFS_ERROR;
- }
-
- for (i = 0; i < ndata; i++) {
- vdata[i].u.x = AKFS_INIT_VALUE_F;
- vdata[i].u.y = AKFS_INIT_VALUE_F;
- vdata[i].u.z = AKFS_INIT_VALUE_F;
- }
-
- return AKFS_SUCCESS;
-}
-
-/******************************************************************************/
-/*! Shift #AKFVEC array.
- @return #AKFS_SUCCESS on success. Otherwise the return value is #AKFS_ERROR.
- @param[in] len
- @param[in] shift
- @param[in/out] v
- */
-int16 AKFS_BufShift(
- const int16 len, /*!< size of buffer */
- const int16 shift, /*!< shift size */
- AKFVEC v[] /*!< buffer */
-)
-{
- int16 i;
-
- if ((shift < 1) || (len < shift)) {
- return AKFS_ERROR;
- }
- for (i = len-1; i >= shift; i--) {
- v[i] = v[i-shift];
- }
- return AKFS_SUCCESS;
-}
-
-/******************************************************************************/
-/*! Rotate vector according to the specified layout pattern number.
- @return #AKFS_SUCCESS on success. Otherwise the return value is #AKFS_ERROR.
- @param[in] pat
- @param[in/out] vec
- */
-int16 AKFS_Rotate(
- const AKFS_PATNO pat,
- AKFVEC *vec
-)
-{
- AKFLOAT tmp;
- switch (pat) {
- /* Obverse */
- case PAT1:
- /* This is Android default */
- break;
- case PAT2:
- tmp = vec->u.x;
- vec->u.x = vec->u.y;
- vec->u.y = -tmp;
- break;
- case PAT3:
- vec->u.x = -(vec->u.x);
- vec->u.y = -(vec->u.y);
- break;
- case PAT4:
- tmp = vec->u.x;
- vec->u.x = -(vec->u.y);
- vec->u.y = tmp;
- break;
- /* Reverse */
- case PAT5:
- vec->u.x = -(vec->u.x);
- vec->u.z = -(vec->u.z);
- break;
- case PAT6:
- tmp = vec->u.x;
- vec->u.x = vec->u.y;
- vec->u.y = tmp;
- vec->u.z = -(vec->u.z);
- break;
- case PAT7:
- vec->u.y = -(vec->u.y);
- vec->u.z = -(vec->u.z);
- break;
- case PAT8:
- tmp = vec->u.x;
- vec->u.x = -(vec->u.y);
- vec->u.y = -tmp;
- vec->u.z = -(vec->u.z);
- break;
- default:
- return AKFS_ERROR;
- }
-
- return AKFS_SUCCESS;
-}
-
-/******************************************************************************/
-/*! Rotate vector according to the specified layout matrix.
- @return #AKFS_SUCCESS on success. Otherwise the return value is #AKFS_ERROR.
- @param[in] pat
- @param[in/out] vec
- */
-int16 AKFS_RotateMat(
- const int16 layout[3][3],
- AKFVEC *vec
-)
-{
- AKFVEC tmp;
-
- tmp.u.x = layout[0][0]*vec->u.x + layout[0][1]*vec->u.y + layout[0][2]*vec->u.z;
- tmp.u.y = layout[1][0]*vec->u.x + layout[1][1]*vec->u.y + layout[1][2]*vec->u.z;
- tmp.u.z = layout[2][0]*vec->u.x + layout[2][1]*vec->u.y + layout[2][2]*vec->u.z;
-
- *vec = tmp;
-
- return AKFS_SUCCESS;
-}
diff --git a/sensors/algo/akm/AKFS_Device.h b/sensors/algo/akm/AKFS_Device.h
deleted file mode 100644
index e1893e8..0000000
--- a/sensors/algo/akm/AKFS_Device.h
+++ /dev/null
@@ -1,112 +0,0 @@
-/******************************************************************************
- *
- * Copyright (C) 2012 Asahi Kasei Microdevices Corporation, Japan
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- ******************************************************************************/
-#ifndef AKFS_INC_DEVICE_H
-#define AKFS_INC_DEVICE_H
-
-#include <float.h>
-#include "AKFS_Configure.h"
-
-/***** Constant definition ****************************************************/
-#define AKFS_ERROR 0
-#define AKFS_SUCCESS 1
-
-#define AKFS_HDATA_SIZE 32
-#define AKFS_ADATA_SIZE 32
-
-/***** Type declaration *******************************************************/
-typedef signed char int8;
-typedef signed short int16;
-typedef unsigned char uint8;
-typedef unsigned short uint16;
-
-
-#ifdef AKFS_PRECISION_DOUBLE
-typedef double AKFLOAT;
-#define AKFS_EPSILON DBL_EPSILON
-#define AKFS_FMAX DBL_MAX
-#define AKFS_FMIN DBL_MIN
-
-#else
-typedef float AKFLOAT;
-#define AKFS_EPSILON FLT_EPSILON
-#define AKFS_FMAX FLT_MAX
-#define AKFS_FMIN FLT_MIN
-
-#endif
-
-/* Treat maximum value as initial value */
-#define AKFS_INIT_VALUE_F AKFS_FMAX
-
-/***** Vector ****************************************************************/
-typedef union _uint8vec {
- struct {
- uint8 x;
- uint8 y;
- uint8 z;
- } u;
- uint8 v[3];
-} uint8vec;
-
-typedef union _AKFVEC {
- struct {
- AKFLOAT x;
- AKFLOAT y;
- AKFLOAT z;
- } u;
- AKFLOAT v[3];
-} AKFVEC;
-
-/***** Layout pattern ********************************************************/
-typedef enum _AKFS_PATNO {
- PAT_INVALID = 0,
- PAT1, /* obverse: 1st pin is right down */
- PAT2, /* obverse: 1st pin is left down */
- PAT3, /* obverse: 1st pin is left top */
- PAT4, /* obverse: 1st pin is right top */
- PAT5, /* reverse: 1st pin is left down (from top view) */
- PAT6, /* reverse: 1st pin is left top (from top view) */
- PAT7, /* reverse: 1st pin is right top (from top view) */
- PAT8 /* reverse: 1st pin is right down (from top view) */
-} AKFS_PATNO;
-
-/***** Prototype of function **************************************************/
-AKLIB_C_API_START
-int16 AKFS_InitBuffer(
- const int16 ndata, /*!< Size of raw vector buffer */
- AKFVEC vdata[] /*!< Raw vector buffer */
-);
-
-int16 AKFS_BufShift(
- const int16 len,
- const int16 shift,
- AKFVEC v[]
-);
-
-int16 AKFS_Rotate(
- const AKFS_PATNO pat,
- AKFVEC *vec
-);
-
-int16 AKFS_RotateMat(
- const int16 layout[3][3],
- AKFVEC *vec
-);
-AKLIB_C_API_END
-
-#endif
-
diff --git a/sensors/algo/akm/AKFS_Direction.c b/sensors/algo/akm/AKFS_Direction.c
deleted file mode 100644
index 2107e7e..0000000
--- a/sensors/algo/akm/AKFS_Direction.c
+++ /dev/null
@@ -1,166 +0,0 @@
-/******************************************************************************
- *
- * Copyright (C) 2012 Asahi Kasei Microdevices Corporation, Japan
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- ******************************************************************************/
-#include "AKFS_Device.h"
-#include "AKFS_Direction.h"
-#include "AKFS_VNorm.h"
-#include "AKFS_Math.h"
-
-/******************************************************************************/
-/* About definition of coordinate system and calculated value.
- Coordinate system is right-handed.
- X-Axis: from left to right.
- Y-Axis: from bottom to top.
- Z-Axis: from reverse to obverse.
-
- azimuth: Rotation around Z axis, with positive values
- when y-axis moves toward the x-axis.
- pitch: Rotation around X axis, with positive values
- when z-axis moves toward the y-axis.
- roll: Rotation around Y axis, with positive values
- when x-axis moves toward the z-axis.
-*/
-
-
-/******************************************************************************/
-/*! This function is used internally, so output is RADIAN!
- @return #AKFS_SUCCESS on success. Otherwise the return value is #AKFS_ERROR.
- @param[in] avec
- @param[out] pitch
- @param[out] roll
- */
-static int16 AKFS_Angle(
- const AKFVEC *avec,
- AKFLOAT *pitch, /* radian */
- AKFLOAT *roll /* radian */
-)
-{
- AKFLOAT av; /* Size of vector */
-
- av = AKFS_SQRT((avec->u.x)*(avec->u.x) + (avec->u.y)*(avec->u.y) + (avec->u.z)*(avec->u.z));
-
- if (av < AKFS_EPSILON) {
- return AKFS_ERROR;
- }
-
- *pitch = AKFS_ASIN(-(avec->u.y) / av);
- *roll = AKFS_ASIN((avec->u.x) / av);
-
- return AKFS_SUCCESS;
-}
-
-/******************************************************************************/
-/*! This function is used internally, so output is RADIAN!
- @return None
- @param[in] hvec
- @param[in] pitch
- @param[in] roll
- @param[out] azimuth
- */
-static void AKFS_Azimuth(
- const AKFVEC *hvec,
- const AKFLOAT pitch, /* radian */
- const AKFLOAT roll, /* radian */
- AKFLOAT *azimuth /* radian */
-)
-{
- AKFLOAT sinP; /* sin value of pitch angle */
- AKFLOAT cosP; /* cos value of pitch angle */
- AKFLOAT sinR; /* sin value of roll angle */
- AKFLOAT cosR; /* cos value of roll angle */
- AKFLOAT Xh; /* X axis element of vector which is projected to horizontal plane */
- AKFLOAT Yh; /* Y axis element of vector which is projected to horizontal plane */
-
- sinP = AKFS_SIN(pitch);
- cosP = AKFS_COS(pitch);
- sinR = AKFS_SIN(roll);
- cosR = AKFS_COS(roll);
-
- Yh = -(hvec->u.x)*cosR + (hvec->u.z)*sinR;
- Xh = (hvec->u.x)*sinP*sinR + (hvec->u.y)*cosP + (hvec->u.z)*sinP*cosR;
-
- /* atan2(y, x) -> divisor and dividend is opposite from mathematical equation. */
- *azimuth = AKFS_ATAN2(Yh, Xh);
-}
-
-/******************************************************************************/
-/*! Output is DEGREE!
- @return #AKFS_SUCCESS on success. Otherwise the return value is #AKFS_ERROR.
- @param[in] nhvec
- @param[in] hvec
- @param[in] hnave
- @param[in] navec
- @param[in] avec
- @param[in] anave
- @param[out] azimuth
- @param[out] pitch
- @param[out] roll
- */
-int16 AKFS_Direction(
- const int16 nhvec,
- const AKFVEC hvec[],
- const int16 hnave,
- const int16 navec,
- const AKFVEC avec[],
- const int16 anave,
- AKFLOAT *azimuth,
- AKFLOAT *pitch,
- AKFLOAT *roll
-)
-{
- AKFVEC have, aave;
- AKFLOAT azimuthRad;
- AKFLOAT pitchRad;
- AKFLOAT rollRad;
-
- /* arguments check */
- if ((nhvec <= 0) || (navec <= 0) || (hnave <= 0) || (anave <= 0)) {
- return AKFS_ERROR;
- }
- if ((nhvec < hnave) || (navec < anave)) {
- return AKFS_ERROR;
- }
-
- /* average */
- if (AKFS_VbAve(nhvec, hvec, hnave, &have) != AKFS_SUCCESS) {
- return AKFS_ERROR;
- }
- if (AKFS_VbAve(navec, avec, anave, &aave) != AKFS_SUCCESS) {
- return AKFS_ERROR;
- }
-
- /* calculate pitch and roll */
- if (AKFS_Angle(&aave, &pitchRad, &rollRad) != AKFS_SUCCESS) {
- return AKFS_ERROR;
- }
-
- /* calculate azimuth */
- AKFS_Azimuth(&have, pitchRad, rollRad, &azimuthRad);
-
- *azimuth = RAD2DEG(azimuthRad);
- *pitch = RAD2DEG(pitchRad);
- *roll = RAD2DEG(rollRad);
-
- /* Adjust range of azimuth */
- if (*azimuth < 0) {
- *azimuth += 360.0f;
- }
-
- return AKFS_SUCCESS;
-}
-
-
diff --git a/sensors/algo/akm/AKFS_Direction.h b/sensors/algo/akm/AKFS_Direction.h
deleted file mode 100644
index fe1dc13..0000000
--- a/sensors/algo/akm/AKFS_Direction.h
+++ /dev/null
@@ -1,39 +0,0 @@
-/******************************************************************************
- *
- * Copyright (C) 2012 Asahi Kasei Microdevices Corporation, Japan
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- ******************************************************************************/
-#ifndef AKFS_INC_DIRECTION_H
-#define AKFS_INC_DIRECTION_H
-
-#include "AKFS_Device.h"
-
-/***** Prototype of function **************************************************/
-AKLIB_C_API_START
-int16 AKFS_Direction(
- const int16 nhvec,
- const AKFVEC hvec[],
- const int16 hnave,
- const int16 navec,
- const AKFVEC avec[],
- const int16 anave,
- AKFLOAT *azimuth,
- AKFLOAT *pitch,
- AKFLOAT *roll
-);
-AKLIB_C_API_END
-
-#endif
-
diff --git a/sensors/algo/akm/AKFS_Math.h b/sensors/algo/akm/AKFS_Math.h
deleted file mode 100644
index dfe48b3..0000000
--- a/sensors/algo/akm/AKFS_Math.h
+++ /dev/null
@@ -1,47 +0,0 @@
-/******************************************************************************
- *
- * Copyright (C) 2012 Asahi Kasei Microdevices Corporation, Japan
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- ******************************************************************************/
-#ifndef AKFS_INC_MATH_H
-#define AKFS_INC_MATH_H
-
-#include <math.h>
-#include "AKFS_Configure.h"
-
-/***** Constant definition ****************************************************/
-#define AKFS_PI 3.141592654f
-#define RAD2DEG(rad) ((rad)*180.0f/AKFS_PI)
-
-/***** Macro definition *******************************************************/
-
-#ifdef AKFS_PRECISION_DOUBLE
-#define AKFS_SIN(x) sin(x)
-#define AKFS_COS(x) cos(x)
-#define AKFS_ASIN(x) asin(x)
-#define AKFS_ACOS(x) acos(x)
-#define AKFS_ATAN2(y, x) atan2((y), (x))
-#define AKFS_SQRT(x) sqrt(x)
-#else
-#define AKFS_SIN(x) sinf(x)
-#define AKFS_COS(x) cosf(x)
-#define AKFS_ASIN(x) asinf(x)
-#define AKFS_ACOS(x) acosf(x)
-#define AKFS_ATAN2(y, x) atan2f((y), (x))
-#define AKFS_SQRT(x) sqrtf(x)
-#endif
-
-#endif
-
diff --git a/sensors/algo/akm/AKFS_VNorm.c b/sensors/algo/akm/AKFS_VNorm.c
deleted file mode 100644
index 5372a36..0000000
--- a/sensors/algo/akm/AKFS_VNorm.c
+++ /dev/null
@@ -1,123 +0,0 @@
-/******************************************************************************
- *
- * Copyright (C) 2012 Asahi Kasei Microdevices Corporation, Japan
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- ******************************************************************************/
-#include "AKFS_Device.h"
-#include "AKFS_VNorm.h"
-
-/******************************************************************************/
-/*! Normalize vector.
- @return #AKFS_SUCCESS on success. Otherwise the return value is #AKFS_ERROR.
- @param[in] ndata Size of raw vector buffer
- @param[in] vdata Raw vector buffer
- @param[in] nbuf Size of data to be buffered
- @param[in] o Offset
- @param[in] s Sensitivity
- @param[in] tgt Target sensitivity
- @param[in] nvec Size of normalized vector buffer
- @param[out] vvec Normalized vector buffer
- */
-int16 AKFS_VbNorm(
- const int16 ndata,
- const AKFVEC vdata[],
- const int16 nbuf,
- const AKFVEC *o,
- const AKFVEC *s,
- const AKFLOAT tgt,
- const int16 nvec,
- AKFVEC vvec[]
-)
-{
- int i;
-
- /* size check */
- if ((ndata <= 0) || (nvec <= 0) || (nbuf <= 0)) {
- return AKFS_ERROR;
- }
- /* dependency check */
- if ((nbuf < 1) || (ndata < nbuf) || (nvec < nbuf)) {
- return AKFS_ERROR;
- }
- /* sensitivity check */
- if ((s->u.x <= AKFS_EPSILON) ||
- (s->u.y <= AKFS_EPSILON) ||
- (s->u.z <= AKFS_EPSILON) ||
- (tgt <= 0)) {
- return AKFS_ERROR;
- }
-
- /* calculate and store data to buffer */
- if (AKFS_BufShift(nvec, nbuf, vvec) != AKFS_SUCCESS) {
- return AKFS_ERROR;
- }
- for (i = 0; i < nbuf; i++) {
- vvec[i].u.x = ((vdata[i].u.x - o->u.x) / (s->u.x) * (AKFLOAT)tgt);
- vvec[i].u.y = ((vdata[i].u.y - o->u.y) / (s->u.y) * (AKFLOAT)tgt);
- vvec[i].u.z = ((vdata[i].u.z - o->u.z) / (s->u.z) * (AKFLOAT)tgt);
- }
-
- return AKFS_SUCCESS;
-}
-
-/******************************************************************************/
-/*! Calculate an averaged vector form a given buffer.
- @return #AKFS_SUCCESS on success. Otherwise the return value is #AKFS_ERROR.
- @param[in] nvec Size of normalized vector buffer
- @param[in] vvec Normalized vector buffer
- @param[in] nave Number of average
- @param[out] vave Averaged vector
- */
-int16 AKFS_VbAve(
- const int16 nvec,
- const AKFVEC vvec[],
- const int16 nave,
- AKFVEC *vave
-)
-{
- int i;
-
- /* arguments check */
- if ((nave <= 0) || (nvec <= 0) || (nvec < nave)) {
- return AKFS_ERROR;
- }
-
- /* calculate average */
- vave->u.x = 0;
- vave->u.y = 0;
- vave->u.z = 0;
- for (i = 0; i < nave; i++) {
- if ((vvec[i].u.x == AKFS_INIT_VALUE_F) ||
- (vvec[i].u.y == AKFS_INIT_VALUE_F) ||
- (vvec[i].u.z == AKFS_INIT_VALUE_F)) {
- break;
- }
- vave->u.x += vvec[i].u.x;
- vave->u.y += vvec[i].u.y;
- vave->u.z += vvec[i].u.z;
- }
- if (i == 0) {
- vave->u.x = 0;
- vave->u.y = 0;
- vave->u.z = 0;
- } else {
- vave->u.x /= i;
- vave->u.y /= i;
- vave->u.z /= i;
- }
- return AKFS_SUCCESS;
-}
-
-
diff --git a/sensors/algo/akm/AKFS_VNorm.h b/sensors/algo/akm/AKFS_VNorm.h
deleted file mode 100644
index 92dd949..0000000
--- a/sensors/algo/akm/AKFS_VNorm.h
+++ /dev/null
@@ -1,46 +0,0 @@
-/******************************************************************************
- *
- * Copyright (C) 2012 Asahi Kasei Microdevices Corporation, Japan
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- ******************************************************************************/
-#ifndef AKFS_INC_VNORM_H
-#define AKFS_INC_VNORM_H
-
-#include "AKFS_Device.h"
-
-/***** Prototype of function **************************************************/
-AKLIB_C_API_START
-int16 AKFS_VbNorm(
- const int16 ndata,
- const AKFVEC vdata[],
- const int16 nbuf,
- const AKFVEC *o,
- const AKFVEC *s,
- const AKFLOAT tgt,
- const int16 nvec,
- AKFVEC vvec[]
-);
-
-int16 AKFS_VbAve(
- const int16 nvec,
- const AKFVEC vvec[],
- const int16 nave,
- AKFVEC *vave
-);
-
-AKLIB_C_API_END
-
-#endif
-
diff --git a/sensors/algo/akm/NOTICE b/sensors/algo/akm/NOTICE
deleted file mode 100644
index d645695..0000000
--- a/sensors/algo/akm/NOTICE
+++ /dev/null
@@ -1,202 +0,0 @@
-
- Apache License
- Version 2.0, January 2004
- http://www.apache.org/licenses/
-
- TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
-
- 1. Definitions.
-
- "License" shall mean the terms and conditions for use, reproduction,
- and distribution as defined by Sections 1 through 9 of this document.
-
- "Licensor" shall mean the copyright owner or entity authorized by
- the copyright owner that is granting the License.
-
- "Legal Entity" shall mean the union of the acting entity and all
- other entities that control, are controlled by, or are under common
- control with that entity. For the purposes of this definition,
- "control" means (i) the power, direct or indirect, to cause the
- direction or management of such entity, whether by contract or
- otherwise, or (ii) ownership of fifty percent (50%) or more of the
- outstanding shares, or (iii) beneficial ownership of such entity.
-
- "You" (or "Your") shall mean an individual or Legal Entity
- exercising permissions granted by this License.
-
- "Source" form shall mean the preferred form for making modifications,
- including but not limited to software source code, documentation
- source, and configuration files.
-
- "Object" form shall mean any form resulting from mechanical
- transformation or translation of a Source form, including but
- not limited to compiled object code, generated documentation,
- and conversions to other media types.
-
- "Work" shall mean the work of authorship, whether in Source or
- Object form, made available under the License, as indicated by a
- copyright notice that is included in or attached to the work
- (an example is provided in the Appendix below).
-
- "Derivative Works" shall mean any work, whether in Source or Object
- form, that is based on (or derived from) the Work and for which the
- editorial revisions, annotations, elaborations, or other modifications
- represent, as a whole, an original work of authorship. For the purposes
- of this License, Derivative Works shall not include works that remain
- separable from, or merely link (or bind by name) to the interfaces of,
- the Work and Derivative Works thereof.
-
- "Contribution" shall mean any work of authorship, including
- the original version of the Work and any modifications or additions
- to that Work or Derivative Works thereof, that is intentionally
- submitted to Licensor for inclusion in the Work by the copyright owner
- or by an individual or Legal Entity authorized to submit on behalf of
- the copyright owner. For the purposes of this definition, "submitted"
- means any form of electronic, verbal, or written communication sent
- to the Licensor or its representatives, including but not limited to
- communication on electronic mailing lists, source code control systems,
- and issue tracking systems that are managed by, or on behalf of, the
- Licensor for the purpose of discussing and improving the Work, but
- excluding communication that is conspicuously marked or otherwise
- designated in writing by the copyright owner as "Not a Contribution."
-
- "Contributor" shall mean Licensor and any individual or Legal Entity
- on behalf of whom a Contribution has been received by Licensor and
- subsequently incorporated within the Work.
-
- 2. Grant of Copyright License. Subject to the terms and conditions of
- this License, each Contributor hereby grants to You a perpetual,
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
- copyright license to reproduce, prepare Derivative Works of,
- publicly display, publicly perform, sublicense, and distribute the
- Work and such Derivative Works in Source or Object form.
-
- 3. Grant of Patent License. Subject to the terms and conditions of
- this License, each Contributor hereby grants to You a perpetual,
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
- (except as stated in this section) patent license to make, have made,
- use, offer to sell, sell, import, and otherwise transfer the Work,
- where such license applies only to those patent claims licensable
- by such Contributor that are necessarily infringed by their
- Contribution(s) alone or by combination of their Contribution(s)
- with the Work to which such Contribution(s) was submitted. If You
- institute patent litigation against any entity (including a
- cross-claim or counterclaim in a lawsuit) alleging that the Work
- or a Contribution incorporated within the Work constitutes direct
- or contributory patent infringement, then any patent licenses
- granted to You under this License for that Work shall terminate
- as of the date such litigation is filed.
-
- 4. Redistribution. You may reproduce and distribute copies of the
- Work or Derivative Works thereof in any medium, with or without
- modifications, and in Source or Object form, provided that You
- meet the following conditions:
-
- (a) You must give any other recipients of the Work or
- Derivative Works a copy of this License; and
-
- (b) You must cause any modified files to carry prominent notices
- stating that You changed the files; and
-
- (c) You must retain, in the Source form of any Derivative Works
- that You distribute, all copyright, patent, trademark, and
- attribution notices from the Source form of the Work,
- excluding those notices that do not pertain to any part of
- the Derivative Works; and
-
- (d) If the Work includes a "NOTICE" text file as part of its
- distribution, then any Derivative Works that You distribute must
- include a readable copy of the attribution notices contained
- within such NOTICE file, excluding those notices that do not
- pertain to any part of the Derivative Works, in at least one
- of the following places: within a NOTICE text file distributed
- as part of the Derivative Works; within the Source form or
- documentation, if provided along with the Derivative Works; or,
- within a display generated by the Derivative Works, if and
- wherever such third-party notices normally appear. The contents
- of the NOTICE file are for informational purposes only and
- do not modify the License. You may add Your own attribution
- notices within Derivative Works that You distribute, alongside
- or as an addendum to the NOTICE text from the Work, provided
- that such additional attribution notices cannot be construed
- as modifying the License.
-
- You may add Your own copyright statement to Your modifications and
- may provide additional or different license terms and conditions
- for use, reproduction, or distribution of Your modifications, or
- for any such Derivative Works as a whole, provided Your use,
- reproduction, and distribution of the Work otherwise complies with
- the conditions stated in this License.
-
- 5. Submission of Contributions. Unless You explicitly state otherwise,
- any Contribution intentionally submitted for inclusion in the Work
- by You to the Licensor shall be under the terms and conditions of
- this License, without any additional terms or conditions.
- Notwithstanding the above, nothing herein shall supersede or modify
- the terms of any separate license agreement you may have executed
- with Licensor regarding such Contributions.
-
- 6. Trademarks. This License does not grant permission to use the trade
- names, trademarks, service marks, or product names of the Licensor,
- except as required for reasonable and customary use in describing the
- origin of the Work and reproducing the content of the NOTICE file.
-
- 7. Disclaimer of Warranty. Unless required by applicable law or
- agreed to in writing, Licensor provides the Work (and each
- Contributor provides its Contributions) on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
- implied, including, without limitation, any warranties or conditions
- of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
- PARTICULAR PURPOSE. You are solely responsible for determining the
- appropriateness of using or redistributing the Work and assume any
- risks associated with Your exercise of permissions under this License.
-
- 8. Limitation of Liability. In no event and under no legal theory,
- whether in tort (including negligence), contract, or otherwise,
- unless required by applicable law (such as deliberate and grossly
- negligent acts) or agreed to in writing, shall any Contributor be
- liable to You for damages, including any direct, indirect, special,
- incidental, or consequential damages of any character arising as a
- result of this License or out of the use or inability to use the
- Work (including but not limited to damages for loss of goodwill,
- work stoppage, computer failure or malfunction, or any and all
- other commercial damages or losses), even if such Contributor
- has been advised of the possibility of such damages.
-
- 9. Accepting Warranty or Additional Liability. While redistributing
- the Work or Derivative Works thereof, You may choose to offer,
- and charge a fee for, acceptance of support, warranty, indemnity,
- or other liability obligations and/or rights consistent with this
- License. However, in accepting such obligations, You may act only
- on Your own behalf and on Your sole responsibility, not on behalf
- of any other Contributor, and only if You agree to indemnify,
- defend, and hold each Contributor harmless for any liability
- incurred by, or claims asserted against, such Contributor by reason
- of your accepting any such warranty or additional liability.
-
- END OF TERMS AND CONDITIONS
-
- APPENDIX: How to apply the Apache License to your work.
-
- To apply the Apache License to your work, attach the following
- boilerplate notice, with the fields enclosed by brackets "[]"
- replaced with your own identifying information. (Don't include
- the brackets!) The text should be enclosed in the appropriate
- comment syntax for the file format. We also recommend that a
- file or class name and description of purpose be included on the
- same "printed page" as the copyright notice for easier
- identification within third-party archives.
-
- Copyright [yyyy] [name of copyright owner]
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
diff --git a/sensors/algo/akm/README.md b/sensors/algo/akm/README.md
deleted file mode 100644
index a3e3803..0000000
--- a/sensors/algo/akm/README.md
+++ /dev/null
@@ -1,34 +0,0 @@
-AK8975/AK8963/AK09911 Sensor Daemon for Android.
-=========
-Compass Control Program for Android Open Source Project
-
-## NOTICE
- 1. Asahi Kasei Microdevices Corporation ("AKM") is pleased to make available to you the source codes of the Electronic Compass Control Program ("Software") for download from this website at no charge. By downloading the Software, you expressly assume all risk and liability associated with downloading and using the Software.
-
- 2. AKM PROVIDES THE SOFTWARE AND THIS DOWNLOADING SERVICE "AS IS" WITHOUT WARRANTY OF ANY KIND AND ALL SUCH WARRANTIES, EXPRESS OR IMPLIED, ARE HEREBY DISCLAIMED, INCLUDING, WITHOUT LIMITATION, WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE ACCURACY, AVAILABILITY, OR NON-INFRINGEMENT. YOU ACKNOWLEDGE THAT AKM IS NOT OBLIGATED TO PROVIDE AND DOES NOT PROVIDE ANY SUPPORT OR ASSISTANCE WITH RESPECT TO THE SOFTWARE.
-
- 3. This downloading service shall not affect nor extend any warranty or disclaimer which AKM makes in each of AKM's products in which the Software works with.
-
- 4. This NOTICE shall be governed by and interpreted under the laws of Japan. All disputes arising out of or under this NOTICE shall be subject to under the exclusive and agreed jurisdiction of the Tokyo District Court as the court of first instance.
-
-## About
-This software is developed by Asahi Kasei Microdevices Corporation ("AKM") to provide compatible daemon program, it is known as akmd2 in many production Android phones.
-
-This software consists from two parts, one is Sensor Control Program (i.e. akmd2) and Sensor HAL (sensors.*.so). Sensor Control Program gets magnetic sensor data form the AKM's compass IC, then estimate offset and calculate azimuth, pitch and roll angle. This behavior is quite similar to the original one. We aimed to develop a compatible daemon software.
-
-This software may help people who wants to study how to control AKM's magnetic sensor on Android.
-
-## License
-The license for all code in this source code is specified in the NOTICE file. Please, refer to this file for further details.
-
-## Build
-To build this project, uncomment your desired device from the top of Android.mk file.
-
- vi $(YOUR_ENV)/AK8975_FS/Android.mk
-
-For example, if you wish to have a software for AK8975, please uncomment the following line.
-
- export AKMD_DEVICE_TYPE=8975
-
-Type 'mm -B', then you will get two binary files, **akmdfs** and **sensors.default.so**.
-
diff --git a/sensors/algo/akm/akm_wrapper.c b/sensors/algo/akm/akm_wrapper.c
deleted file mode 100755
index e790b33..0000000
--- a/sensors/algo/akm/akm_wrapper.c
+++ /dev/null
@@ -1,269 +0,0 @@
-/*--------------------------------------------------------------------------
-Copyright (c) 2014, The Linux Foundation. All rights reserved.
-
-Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions are
-met:
- * Redistributions of source code must retain the above copyright
- notice, this list of conditions and the following disclaimer.
- * Redistributions in binary form must reproduce the above
- copyright notice, this list of conditions and the following
- disclaimer in the documentation and/or other materials provided
- with the distribution.
- * Neither the name of The Linux Foundation nor the names of its
- contributors may be used to endorse or promote products derived
- from this software without specific prior written permission.
-
-THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
-WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
-MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
-ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
-BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
-CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
-SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
-BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
-OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
-IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
---------------------------------------------------------------------------*/
-
-#include <stdio.h>
-#include <CalibrationModule.h>
-
-#define LOG_TAG "sensor_cal.akm"
-#include <utils/Log.h>
-
-#include "AKFS_Device.h"
-#include "AKFS_Decomp.h"
-#include "AKFS_AOC.h"
-#include "AKFS_Math.h"
-#include "AKFS_VNorm.h"
-
-#define SENSOR_CAL_ALGO_VERSION 1
-#define AKM_MAG_SENSE (1.0)
-#define CSPEC_HNAVE_V 8
-#define AKFS_GEOMAG_MAX 70
-
-struct sensor_cal_module_t SENSOR_CAL_MODULE_INFO;
-static struct sensor_cal_algo_t algo_list[];
-
-/*! A parameter structure. */
-/* ix*_ : x-bit integer */
-/* f**_ : floating value */
-/* p**_ : pointer */
-/* e**_ : enum */
-/* *s*_ : struct */
-/* *v*_ : vector (special type of struct) */
-/* **a_ : array */
-typedef struct _AKMPRMS{
-
- /* Variables for Decomp. */
- AKFVEC fva_hdata[AKFS_HDATA_SIZE];
- uint8vec i8v_asa;
-
- /* Variables forAOC. */
- AKFS_AOC_VAR s_aocv;
-
- /* Variables for Magnetometer buffer. */
- AKFVEC fva_hvbuf[AKFS_HDATA_SIZE];
- AKFVEC fv_ho;
- AKFVEC fv_hs;
- AKFS_PATNO e_hpat;
-
- /* Variables for Accelerometer buffer. */
- AKFVEC fva_avbuf[AKFS_ADATA_SIZE];
- AKFVEC fv_ao;
- AKFVEC fv_as;
-
- /* Variables for Direction. */
- AKFLOAT f_azimuth;
- AKFLOAT f_pitch;
- AKFLOAT f_roll;
-
- /* Variables for vector output */
- AKFVEC fv_hvec;
- AKFVEC fv_avec;
- int16 i16_hstatus;
-
-} AKMPRMS;
-
-static AKMPRMS g_prms;
-
-static int convert_magnetic(sensors_vec_t *raw, sensors_vec_t *result,
- struct sensor_algo_args *args)
-{
- int16 akret;
- int16 aocret;
- AKFLOAT radius;
- AKMPRMS *prms = &g_prms;
- int i;
-
- /* Shift out old data from the buffer for better calibration */
- for (i = AKFS_HDATA_SIZE - 1; i >= 1; i--) {
- prms->fva_hdata[i] = prms->fva_hdata[i - 1];
- }
-
- prms->fva_hdata[0].u.x = raw->x;
- prms->fva_hdata[0].u.y = raw->y;
- prms->fva_hdata[0].u.z = raw->z;
-
- /* Offset calculation is done in this function */
- /* hdata[in] : Android coordinate, sensitivity adjusted. */
- /* ho [out]: Android coordinate, sensitivity adjusted. */
- aocret = AKFS_AOC(
- &prms->s_aocv,
- prms->fva_hdata,
- &prms->fv_ho
- );
-
- /* Subtract offset */
- /* hdata[in] : Android coordinate, sensitivity adjusted. */
- /* ho [in] : Android coordinate, sensitivity adjusted. */
- /* hvbuf[out]: Android coordinate, sensitivity adjusted, */
- /* offset subtracted. */
- akret = AKFS_VbNorm(
- AKFS_HDATA_SIZE,
- prms->fva_hdata,
- 1,
- &prms->fv_ho,
- &prms->fv_hs,
- AKM_MAG_SENSE,
- AKFS_HDATA_SIZE,
- prms->fva_hvbuf
- );
- if (akret == AKFS_ERROR) {
- ALOGE("error here!");
- return -1;
- }
-
- /* Averaging */
- /* hvbuf[in] : Android coordinate, sensitivity adjusted, */
- /* offset subtracted. */
- /* hvec [out]: Android coordinate, sensitivity adjusted, */
- /* offset subtracted, averaged. */
- akret = AKFS_VbAve(
- AKFS_HDATA_SIZE,
- prms->fva_hvbuf,
- CSPEC_HNAVE_V,
- &prms->fv_hvec
- );
- if (akret == AKFS_ERROR) {
- ALOGE("error here!");
- return -1;
- }
-
- /* Check the size of magnetic vector */
- radius = AKFS_SQRT(
- (prms->fv_hvec.u.x * prms->fv_hvec.u.x) +
- (prms->fv_hvec.u.y * prms->fv_hvec.u.y) +
- (prms->fv_hvec.u.z * prms->fv_hvec.u.z));
-
- if (radius > AKFS_GEOMAG_MAX) {
- prms->i16_hstatus = 0;
- } else {
- if (aocret == AKFS_SUCCESS) {
- prms->i16_hstatus = 3;
- }
- }
-
- result->x = prms->fv_hvec.u.x;
- result->y = prms->fv_hvec.u.y;
- result->z = prms->fv_hvec.u.z;
- result->status = prms->i16_hstatus;
-
- return 0;
-}
-
-static int config_magnetic(int cmd, struct sensor_algo_args *args)
-{
- struct compass_algo_args *param = (struct compass_algo_args*)args;
-
- switch (cmd) {
- case CMD_ENABLE:
- ALOGD("Enable status changed to %d\n", param->common.enable);
- break;
- case CMD_DELAY:
- ALOGD("Polling rate changed to %d\n", param->common.delay_ms);
- break;
- case CMD_BATCH:
- break;
- }
-
- return 0;
-}
-
-static int cal_init(const struct sensor_cal_module_t *module)
-{
- AKMPRMS *prms = &g_prms;
-
- /* Clear all data. */
- memset(prms, 0, sizeof(AKMPRMS));
-
- /* Sensitivity */
- prms->fv_hs.u.x = AKM_MAG_SENSE;
- prms->fv_hs.u.y = AKM_MAG_SENSE;
- prms->fv_hs.u.z = AKM_MAG_SENSE;
-
- /* Initialize buffer */
- AKFS_InitBuffer(AKFS_HDATA_SIZE, prms->fva_hdata);
- AKFS_InitBuffer(AKFS_HDATA_SIZE, prms->fva_hvbuf);
- AKFS_InitBuffer(AKFS_ADATA_SIZE, prms->fva_avbuf);
-
- /* Initialize for AOC */
- AKFS_InitAOC(&prms->s_aocv);
- /* Initialize magnetic status */
- prms->i16_hstatus = 0;
-
- return 0;
-}
-
-static void cal_deinit()
-{
- ALOGI("%s called\n", __func__);
-}
-
-static int cal_get_algo_list(const struct sensor_cal_algo_t **algo)
-{
- *algo = algo_list;
- return 0;
-}
-
-static struct sensor_algo_methods_t algo_methods = {
- .convert = convert_magnetic,
- .config = config_magnetic,
-};
-
-static const char* sensor_match_table[] = {
- "akm09911-mag",
- "akm8963-mag",
- "compass",
- NULL
-};
-
-static struct sensor_cal_algo_t algo_list[] = {
- {
- .tag = SENSOR_CAL_ALGO_TAG,
- .version = SENSOR_CAL_ALGO_VERSION,
- .type = SENSOR_TYPE_MAGNETIC_FIELD,
- .compatible = sensor_match_table,
- .module = &SENSOR_CAL_MODULE_INFO,
- .methods = &algo_methods,
- },
-};
-
-static struct sensor_cal_methods_t cal_methods = {
- .init = cal_init,
- .deinit = cal_deinit,
- .get_algo_list = cal_get_algo_list,
-};
-
-struct sensor_cal_module_t SENSOR_CAL_MODULE_INFO = {
- .tag = SENSOR_CAL_MODULE_TAG,
- .id = "cal_module_akm",
- .version = SENSOR_CAL_MODULE_VERSION,
- .vendor = "akm",
- .dso = NULL,
- .number = 1,
- .methods = &cal_methods,
- .reserved = {0},
-};
diff --git a/sensors/algo/common/common_wrapper.c b/sensors/algo/common/common_wrapper.c
deleted file mode 100644
index 9419947..0000000
--- a/sensors/algo/common/common_wrapper.c
+++ /dev/null
@@ -1,458 +0,0 @@
-/*--------------------------------------------------------------------------
-Copyright (c) 2014, The Linux Foundation. All rights reserved.
-
-Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions are
-met:
- * Redistributions of source code must retain the above copyright
- notice, this list of conditions and the following disclaimer.
- * Redistributions in binary form must reproduce the above
- copyright notice, this list of conditions and the following
- disclaimer in the documentation and/or other materials provided
- with the distribution.
- * Neither the name of The Linux Foundation nor the names of its
- contributors may be used to endorse or promote products derived
- from this software without specific prior written permission.
-
-THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
-WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
-MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
-ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
-BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
-CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
-SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
-BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
-OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
-IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
---------------------------------------------------------------------------*/
-
-#include <stdio.h>
-#include <string.h>
-#include <CalibrationModule.h>
-#include <sensors.h>
-
-#define LOG_TAG "sensor_cal.common"
-#include <utils/Log.h>
-
-#include "compass/AKFS_Device.h"
-#include "compass/AKFS_Decomp.h"
-#include "compass/AKFS_AOC.h"
-#include "compass/AKFS_Math.h"
-#include "compass/AKFS_VNorm.h"
-
-#define SENSOR_CAL_ALGO_VERSION 1
-#define AKM_MAG_SENSE (1.0)
-#define CSPEC_HNAVE_V 8
-#define AKFS_GEOMAG_MAX 70
-
-#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
-
-struct sensor_vec {
- union {
- struct {
- float data[4];
- };
- struct {
- float x;
- float y;
- float z;
- };
- };
-};
-
-struct sensor_cal_module_t SENSOR_CAL_MODULE_INFO;
-static struct sensor_cal_algo_t algo_list[];
-
-/*! A parameter structure. */
-/* ix*_ : x-bit integer */
-/* f**_ : floating value */
-/* p**_ : pointer */
-/* e**_ : enum */
-/* *s*_ : struct */
-/* *v*_ : vector (special type of struct) */
-/* **a_ : array */
-typedef struct _AKMPRMS{
-
- /* Variables for Decomp. */
- AKFVEC fva_hdata[AKFS_HDATA_SIZE];
- uint8vec i8v_asa;
-
- /* Variables forAOC. */
- AKFS_AOC_VAR s_aocv;
-
- /* Variables for Magnetometer buffer. */
- AKFVEC fva_hvbuf[AKFS_HDATA_SIZE];
- AKFVEC fv_ho;
- AKFVEC fv_hs;
- AKFS_PATNO e_hpat;
-
- /* Variables for Accelerometer buffer. */
- AKFVEC fva_avbuf[AKFS_ADATA_SIZE];
- AKFVEC fv_ao;
- AKFVEC fv_as;
-
- /* Variables for Direction. */
- AKFLOAT f_azimuth;
- AKFLOAT f_pitch;
- AKFLOAT f_roll;
-
- /* Variables for vector output */
- AKFVEC fv_hvec;
- AKFVEC fv_avec;
- int16 i16_hstatus;
-
-} AKMPRMS;
-
-static AKMPRMS g_prms;
-
-static int convert_magnetic(sensors_event_t *raw, sensors_event_t *result,
- struct sensor_algo_args *args __attribute__((unused)))
-{
- int16 akret;
- int16 aocret;
- AKFLOAT radius;
- AKMPRMS *prms = &g_prms;
- int i;
-
- /* Shift out old data from the buffer for better calibration */
- for (i = AKFS_HDATA_SIZE - 1; i >= 1; i--) {
- prms->fva_hdata[i] = prms->fva_hdata[i - 1];
- }
-
- prms->fva_hdata[0].u.x = raw->magnetic.x;
- prms->fva_hdata[0].u.y = raw->magnetic.y;
- prms->fva_hdata[0].u.z = raw->magnetic.z;
-
- /* Offset calculation is done in this function */
- /* hdata[in] : Android coordinate, sensitivity adjusted. */
- /* ho [out]: Android coordinate, sensitivity adjusted. */
- aocret = AKFS_AOC(
- &prms->s_aocv,
- prms->fva_hdata,
- &prms->fv_ho
- );
-
- /* Subtract offset */
- /* hdata[in] : Android coordinate, sensitivity adjusted. */
- /* ho [in] : Android coordinate, sensitivity adjusted. */
- /* hvbuf[out]: Android coordinate, sensitivity adjusted, */
- /* offset subtracted. */
- akret = AKFS_VbNorm(
- AKFS_HDATA_SIZE,
- prms->fva_hdata,
- 1,
- &prms->fv_ho,
- &prms->fv_hs,
- AKM_MAG_SENSE,
- AKFS_HDATA_SIZE,
- prms->fva_hvbuf
- );
- if (akret == AKFS_ERROR) {
- ALOGE("error here!");
- return -1;
- }
-
- /* Averaging */
- /* hvbuf[in] : Android coordinate, sensitivity adjusted, */
- /* offset subtracted. */
- /* hvec [out]: Android coordinate, sensitivity adjusted, */
- /* offset subtracted, averaged. */
- akret = AKFS_VbAve(
- AKFS_HDATA_SIZE,
- prms->fva_hvbuf,
- CSPEC_HNAVE_V,
- &prms->fv_hvec
- );
- if (akret == AKFS_ERROR) {
- ALOGE("error here!");
- return -1;
- }
-
- /* Check the size of magnetic vector */
- radius = AKFS_SQRT(
- (prms->fv_hvec.u.x * prms->fv_hvec.u.x) +
- (prms->fv_hvec.u.y * prms->fv_hvec.u.y) +
- (prms->fv_hvec.u.z * prms->fv_hvec.u.z));
-
- if (radius > AKFS_GEOMAG_MAX) {
- prms->i16_hstatus = 0;
- } else {
- if (aocret == AKFS_SUCCESS) {
- prms->i16_hstatus = 3;
- }
- }
-
- result->magnetic.x = prms->fv_hvec.u.x;
- result->magnetic.y = prms->fv_hvec.u.y;
- result->magnetic.z = prms->fv_hvec.u.z;
- result->magnetic.status = prms->i16_hstatus;
-
- return 0;
-}
-
-static int convert_orientation(sensors_event_t *raw, sensors_event_t *result,
- struct sensor_algo_args *args __attribute__((unused)))
-{
- float av;
- float pitch, roll, azimuth;
- const float rad2deg = 180 / M_PI;
-
- static struct sensor_vec mag, acc;
-
- if (raw->type == SENSOR_TYPE_MAGNETIC_FIELD) {
- mag.x = raw->magnetic.x;
- mag.y = raw->magnetic.y;
- mag.z = raw->magnetic.z;
- }
-
- if (raw->type == SENSOR_TYPE_ACCELEROMETER) {
- acc.x = raw->acceleration.x;
- acc.y = raw->acceleration.y;
- acc.z = raw->acceleration.z;
- }
-
- av = sqrtf(acc.x*acc.x + acc.y*acc.y + acc.z*acc.z);
- if (av >= DBL_EPSILON) {
- pitch = asinf(-acc.y / av);
- roll = asinf(acc.x / av);
- result->orientation.pitch = pitch * rad2deg;
- result->orientation.roll = roll * rad2deg;
- azimuth = atan2(-(mag.x) * cosf(roll) + mag.z * sinf(roll),
- mag.x*sinf(pitch)*sinf(roll) + mag.y*cosf(pitch) + mag.z*sinf(pitch)*cosf(roll));
- result->orientation.azimuth = azimuth * rad2deg;
- result->orientation.status = 3;
- }
-
- if (raw->type != SENSOR_TYPE_MAGNETIC_FIELD)
- return -EAGAIN;
-
- return 0;
-
-}
-
-static int convert_rotation_vector(sensors_event_t *raw, sensors_event_t *result,
- struct sensor_algo_args *args __attribute__((unused)))
-{
- float av;
- float pitch, roll, azimuth;
- int i;
-
- static struct sensor_vec mag, acc;
-
- if (raw->type == SENSOR_TYPE_MAGNETIC_FIELD) {
- mag.x = raw->magnetic.x;
- mag.y = raw->magnetic.y;
- mag.z = raw->magnetic.z;
- }
-
- if (raw->type == SENSOR_TYPE_ACCELEROMETER) {
- acc.x = raw->acceleration.x;
- acc.y = raw->acceleration.y;
- acc.z = raw->acceleration.z;
- }
-
-
- av = sqrtf(acc.x*acc.x + acc.y*acc.y + acc.z*acc.z);
- pitch = asinf(-acc.y / av);
- roll = asinf(acc.x / av);
- azimuth = atan2(-(mag.x) * cosf(roll) + mag.z * sinf(roll),
- mag.x*sinf(pitch)*sinf(roll) + mag.y*cosf(pitch) + mag.z*sinf(pitch)*cosf(roll));
-
- float halfAzi = azimuth / 2;
- float halfPitch = pitch / 2;
- float halfRoll = -roll / 2;
-
- float c1 = cosf(halfAzi);
- float s1 = sinf(halfAzi);
- float c2 = cosf(halfPitch);
- float s2 = sinf(halfPitch);
- float c3 = cosf(halfRoll);
- float s3 = sinf(halfRoll);
-
- result->data[0] = c1*c2*c3 - s1*s2*s3;
- result->data[1] = c1*s2*c3 - s1*c2*s3;
- result->data[2] = c1*c2*s3 + s1*s2*c3;
- result->data[3] = s1*c2*c3 + c1*s2*s3;
-
- if (halfAzi < M_PI / 2) {
- result->data[1] = -result->data[1];
- result->data[3] = -result->data[3];
- } else {
- result->data[2] = -result->data[2];
- }
-
- if (raw->type != SENSOR_TYPE_MAGNETIC_FIELD)
- return -1;
-
- return 0;
-}
-
-static int config_magnetic(int cmd, struct sensor_algo_args *args __attribute__((unused)))
-{
- struct compass_algo_args *param = (struct compass_algo_args*)args;
-
- switch (cmd) {
- case CMD_ENABLE:
- ALOGD("Enable status changed to %d\n", param->common.enable);
- break;
- case CMD_DELAY:
- ALOGD("Polling rate changed to %d\n", param->common.delay_ms);
- break;
- case CMD_BATCH:
- break;
- }
-
- return 0;
-}
-
-/* The magnetic field raw data is supposed to store at the sensors_event_t:data[4~6]*/
-static int convert_uncalibrated_magnetic(sensors_event_t *raw, sensors_event_t *result,
- struct sensor_algo_args *args __attribute__((unused)))
-{
- if (raw->type == SENSOR_TYPE_MAGNETIC_FIELD) {
- result->uncalibrated_magnetic.x_uncalib = raw->data[4];
- result->uncalibrated_magnetic.y_uncalib = raw->data[5];
- result->uncalibrated_magnetic.z_uncalib = raw->data[6];
-
- result->uncalibrated_magnetic.x_bias = raw->data[4] - raw->data[0];
- result->uncalibrated_magnetic.y_bias = raw->data[5] - raw->data[1];
- result->uncalibrated_magnetic.z_bias = raw->data[6] - raw->data[2];
-
- return 0;
- }
-
- return -1;
-}
-
-static int cal_init(const struct sensor_cal_module_t *module __attribute__((unused)))
-{
- AKMPRMS *prms = &g_prms;
-
- /* Clear all data. */
- memset(prms, 0, sizeof(AKMPRMS));
-
- /* Sensitivity */
- prms->fv_hs.u.x = AKM_MAG_SENSE;
- prms->fv_hs.u.y = AKM_MAG_SENSE;
- prms->fv_hs.u.z = AKM_MAG_SENSE;
-
- /* Initialize buffer */
- AKFS_InitBuffer(AKFS_HDATA_SIZE, prms->fva_hdata);
- AKFS_InitBuffer(AKFS_HDATA_SIZE, prms->fva_hvbuf);
- AKFS_InitBuffer(AKFS_ADATA_SIZE, prms->fva_avbuf);
-
- /* Initialize for AOC */
- AKFS_InitAOC(&prms->s_aocv);
- /* Initialize magnetic status */
- prms->i16_hstatus = 0;
-
- return 0;
-}
-
-static void cal_deinit()
-{
- ALOGI("%s called\n", __func__);
-}
-
-static int cal_get_algo_list(const struct sensor_cal_algo_t **algo)
-{
- *algo = algo_list;
- return 0;
-}
-
-static struct sensor_algo_methods_t compass_methods = {
- .convert = convert_magnetic,
- .config = config_magnetic,
-};
-
-static const char* compass_match_table[] = {
- COMPASS_NAME,
- NULL
-};
-
-static struct sensor_algo_methods_t orientation_methods = {
- .convert = convert_orientation,
- .config = NULL,
-};
-
-static const char* orientation_match_table[] = {
- ORIENTATION_NAME,
- NULL
-};
-
-static struct sensor_algo_methods_t rotation_vector_methods = {
- .convert = convert_rotation_vector,
- .config = NULL,
-};
-
-static const char* rotation_vector_match_table[] = {
- ROTATION_VECTOR_NAME,
- NULL
-};
-
-static struct sensor_algo_methods_t mag_uncalib_methods = {
- .convert = convert_uncalibrated_magnetic,
- .config = NULL,
-};
-
-static const char* mag_uncalib_match_table[] = {
- MAGNETIC_FIELD_UNCALIBRATED_NAME,
- NULL
-};
-
-static struct sensor_cal_algo_t algo_list[] = {
- {
- .tag = SENSOR_CAL_ALGO_TAG,
- .version = SENSOR_CAL_ALGO_VERSION,
- .type = SENSOR_TYPE_MAGNETIC_FIELD,
- .compatible = compass_match_table,
- .module = &SENSOR_CAL_MODULE_INFO,
- .methods = &compass_methods,
- },
-
- {
- .tag = SENSOR_CAL_ALGO_TAG,
- .version = SENSOR_CAL_ALGO_VERSION,
- .type = SENSOR_TYPE_ORIENTATION,
- .compatible = orientation_match_table,
- .module = &SENSOR_CAL_MODULE_INFO,
- .methods = &orientation_methods,
- },
-
- {
- .tag = SENSOR_CAL_ALGO_TAG,
- .version = SENSOR_CAL_ALGO_VERSION,
- .type = SENSOR_TYPE_ROTATION_VECTOR,
- .compatible = rotation_vector_match_table,
- .module = &SENSOR_CAL_MODULE_INFO,
- .methods = &rotation_vector_methods,
- },
-
- {
- .tag = SENSOR_CAL_ALGO_TAG,
- .version = SENSOR_CAL_ALGO_VERSION,
- .type = SENSOR_TYPE_MAGNETIC_FIELD_UNCALIBRATED,
- .compatible = mag_uncalib_match_table,
- .module = &SENSOR_CAL_MODULE_INFO,
- .methods = &mag_uncalib_methods,
- },
-
-};
-
-static struct sensor_cal_methods_t cal_methods = {
- .init = cal_init,
- .deinit = cal_deinit,
- .get_algo_list = cal_get_algo_list,
-};
-
-struct sensor_cal_module_t SENSOR_CAL_MODULE_INFO = {
- .tag = SENSOR_CAL_MODULE_TAG,
- .id = "cal_module_common",
- .version = SENSOR_CAL_MODULE_VERSION,
- .vendor = "common",
- .dso = NULL,
- .number = ARRAY_SIZE(algo_list),
- .methods = &cal_methods,
- .reserved = {0},
-};
diff --git a/sensors/algo/common/compass/AKFS_AOC.c b/sensors/algo/common/compass/AKFS_AOC.c
deleted file mode 100644
index 41c115f..0000000
--- a/sensors/algo/common/compass/AKFS_AOC.c
+++ /dev/null
@@ -1,333 +0,0 @@
-/******************************************************************************
- *
- * Copyright (C) 2012 Asahi Kasei Microdevices Corporation, Japan
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- ******************************************************************************/
-#include "AKFS_AOC.h"
-#include "AKFS_Math.h"
-
-/*
- * CalcR
- */
-static AKFLOAT CalcR(
- const AKFVEC *x,
- const AKFVEC *y
-){
- int16 i;
- AKFLOAT r;
-
- r = 0.0;
- for (i = 0; i < 3; i++) {
- r += (x->v[i]-y->v[i]) * (x->v[i]-y->v[i]);
- }
- r = sqrt(r);
-
- return r;
-}
-
-/*
- * From4Points2Sphere()
- */
-static int16 From4Points2Sphere(
- const AKFVEC points[], /*!< (i/o) : input vectors */
- AKFVEC *center, /*!< (o) : center of sphere */
- AKFLOAT *r /*!< (i) : add/subtract value */
-){
- AKFLOAT dif[3][3];
- AKFLOAT r2[3];
-
- AKFLOAT A;
- AKFLOAT B;
- AKFLOAT C;
- AKFLOAT D;
- AKFLOAT E;
- AKFLOAT F;
- AKFLOAT G;
-
- AKFLOAT OU;
- AKFLOAT OD;
-
- int16 i, j;
-
- for (i = 0; i < 3; i++) {
- r2[i] = 0.0;
- for (j = 0; j < 3; j++) {
- dif[i][j] = points[i].v[j] - points[3].v[j];
- r2[i] += (points[i].v[j]*points[i].v[j]
- - points[3].v[j]*points[3].v[j]);
- }
- r2[i] *= 0.5;
- }
-
- A = dif[0][0]*dif[2][2] - dif[0][2]*dif[2][0];
- B = dif[0][1]*dif[2][0] - dif[0][0]*dif[2][1];
- C = dif[0][0]*dif[2][1] - dif[0][1]*dif[2][0];
- D = dif[0][0]*r2[2] - dif[2][0]*r2[0];
- E = dif[0][0]*dif[1][1] - dif[0][1]*dif[1][0];
- F = dif[1][0]*dif[0][2] - dif[0][0]*dif[1][2];
- G = dif[0][0]*r2[1] - dif[1][0]*r2[0];
-
- OU = D*E + B*G;
- OD = C*F + A*E;
-
- if (fabs(OD) < AKFS_EPSILON) {
- return -1;
- }
-
- center->v[2] = OU / OD;
-
- OU = F*center->v[2] + G;
- OD = E;
-
- if (fabs(OD) < AKFS_EPSILON) {
- return -1;
- }
-
- center->v[1] = OU / OD;
-
- OU = r2[0] - dif[0][1]*center->v[1] - dif[0][2]*center->v[2];
- OD = dif[0][0];
-
- if (fabs(OD) < AKFS_EPSILON) {
- return -1;
- }
-
- center->v[0] = OU / OD;
-
- *r = CalcR(&points[0], center);
-
- return 0;
-
-}
-
-/*
- * MeanVar
- */
-static void MeanVar(
- const AKFVEC v[], /*!< (i) : input vectors */
- const int16 n, /*!< (i) : number of vectors */
- AKFVEC *mean, /*!< (o) : (max+min)/2 */
- AKFVEC *var /*!< (o) : variation in vectors */
-){
- int16 i;
- int16 j;
- AKFVEC max;
- AKFVEC min;
-
- for (j = 0; j < 3; j++) {
- min.v[j] = v[0].v[j];
- max.v[j] = v[0].v[j];
- for (i = 1; i < n; i++) {
- if (v[i].v[j] < min.v[j]) {
- min.v[j] = v[i].v[j];
- }
- if (v[i].v[j] > max.v[j]) {
- max.v[j] = v[i].v[j];
- }
- }
- mean->v[j] = (max.v[j] + min.v[j]) / 2.0; /*mean */
- var->v[j] = max.v[j] - min.v[j]; /*var */
- }
-}
-
-/*
- * Get4points
- */
-static void Get4points(
- const AKFVEC v[], /*!< (i) : input vectors */
- const int16 n, /*!< (i) : number of vectors */
- AKFVEC out[] /*!< (o) : */
-){
- int16 i, j;
- AKFLOAT temp;
- AKFLOAT d;
-
- AKFVEC dv[AKFS_HBUF_SIZE];
- AKFVEC cross = {{0, 0, 0}};
- AKFVEC tempv = {{0, 0, 0}};
-
- /* out 0 */
- out[0] = v[0];
-
- /* out 1 */
- d = 0.0;
- for (i = 1; i < n; i++) {
- temp = CalcR(&v[i], &out[0]);
- if (d < temp) {
- d = temp;
- out[1] = v[i];
- }
- }
-
- /* out 2 */
- d = 0.0;
- for (j = 0; j < 3; j++) {
- dv[0].v[j] = out[1].v[j] - out[0].v[j];
- }
- for (i = 1; i < n; i++) {
- for (j = 0; j < 3; j++) {
- dv[i].v[j] = v[i].v[j] - out[0].v[j];
- }
- tempv.v[0] = dv[0].v[1]*dv[i].v[2] - dv[0].v[2]*dv[i].v[1];
- tempv.v[1] = dv[0].v[2]*dv[i].v[0] - dv[0].v[0]*dv[i].v[2];
- tempv.v[2] = dv[0].v[0]*dv[i].v[1] - dv[0].v[1]*dv[i].v[0];
- temp = tempv.u.x * tempv.u.x
- + tempv.u.y * tempv.u.y
- + tempv.u.z * tempv.u.z;
- if (d < temp) {
- d = temp;
- out[2] = v[i];
- cross = tempv;
- }
- }
-
- /* out 3 */
- d = 0.0;
- for (i = 1; i < n; i++) {
- temp = dv[i].u.x * cross.u.x
- + dv[i].u.y * cross.u.y
- + dv[i].u.z * cross.u.z;
- temp = fabs(temp);
- if (d < temp) {
- d = temp;
- out[3] = v[i];
- }
- }
-}
-
-/*
- * CheckInitFvec
- */
-static int16 CheckInitFvec(
- const AKFVEC *v /*!< [in] vector */
-){
- int16 i;
-
- for (i = 0; i < 3; i++) {
- if (AKFS_FMAX <= v->v[i]) {
- return 1; /* initvalue */
- }
- }
-
- return 0; /* not initvalue */
-}
-
-/*
- * AKFS_AOC
- */
-int16 AKFS_AOC( /*!< (o) : calibration success(AKFS_SUCCESS), failure(AKFS_ERROR) */
- AKFS_AOC_VAR *haocv, /*!< (i/o) : a set of variables */
- const AKFVEC *hdata, /*!< (i) : vectors of data */
- AKFVEC *ho /*!< (i/o) : offset */
-){
- int16 i, j;
- int16 num;
- AKFLOAT tempf;
- AKFVEC tempho;
-
- AKFVEC fourpoints[4];
-
- AKFVEC var;
- AKFVEC mean;
-
- /* buffer new data */
- for (i = 1; i < AKFS_HBUF_SIZE; i++) {
- haocv->hbuf[AKFS_HBUF_SIZE-i] = haocv->hbuf[AKFS_HBUF_SIZE-i-1];
- }
- haocv->hbuf[0] = *hdata;
-
- /* Check Init */
- num = 0;
- for (i = AKFS_HBUF_SIZE; 3 < i; i--) {
- if (CheckInitFvec(&haocv->hbuf[i-1]) == 0) {
- num = i;
- break;
- }
- }
- if (num < 4) {
- return AKFS_ERROR;
- }
-
- /* get 4 points */
- Get4points(haocv->hbuf, num, fourpoints);
-
- /* estimate offset */
- if (0 != From4Points2Sphere(fourpoints, &tempho, &haocv->hraoc)) {
- return AKFS_ERROR;
- }
-
- /* check distance */
- for (i = 0; i < 4; i++) {
- for (j = (i+1); j < 4; j++) {
- tempf = CalcR(&fourpoints[i], &fourpoints[j]);
- if ((tempf < haocv->hraoc) || (tempf < AKFS_HR_TH)) {
- return AKFS_ERROR;
- }
- }
- }
-
- /* update offset buffer */
- for (i = 1; i < AKFS_HOBUF_SIZE; i++) {
- haocv->hobuf[AKFS_HOBUF_SIZE-i] = haocv->hobuf[AKFS_HOBUF_SIZE-i-1];
- }
- haocv->hobuf[0] = tempho;
-
- /* clear hbuf */
- for (i = (AKFS_HBUF_SIZE>>1); i < AKFS_HBUF_SIZE; i++) {
- for (j = 0; j < 3; j++) {
- haocv->hbuf[i].v[j] = AKFS_FMAX;
- }
- }
-
- /* Check Init */
- if (CheckInitFvec(&haocv->hobuf[AKFS_HOBUF_SIZE-1]) == 1) {
- return AKFS_ERROR;
- }
-
- /* Check ovar */
- tempf = haocv->hraoc * AKFS_HO_TH;
- MeanVar(haocv->hobuf, AKFS_HOBUF_SIZE, &mean, &var);
- if ((var.u.x >= tempf) || (var.u.y >= tempf) || (var.u.z >= tempf)) {
- return AKFS_ERROR;
- }
-
- *ho = mean;
-
- return AKFS_SUCCESS;
-}
-
-/*
- * AKFS_InitAOC
- */
-void AKFS_InitAOC(
- AKFS_AOC_VAR *haocv
-){
- int16 i, j;
-
- /* Initialize buffer */
- for (i = 0; i < AKFS_HBUF_SIZE; i++) {
- for (j = 0; j < 3; j++) {
- haocv->hbuf[i].v[j] = AKFS_FMAX;
- }
- }
- for (i = 0; i < AKFS_HOBUF_SIZE; i++) {
- for (j = 0; j < 3; j++) {
- haocv->hobuf[i].v[j] = AKFS_FMAX;
- }
- }
-
- haocv->hraoc = 0.0;
-}
-
diff --git a/sensors/algo/common/compass/AKFS_AOC.h b/sensors/algo/common/compass/AKFS_AOC.h
deleted file mode 100644
index 7fff6c4..0000000
--- a/sensors/algo/common/compass/AKFS_AOC.h
+++ /dev/null
@@ -1,53 +0,0 @@
-/******************************************************************************
- *
- * Copyright (C) 2012 Asahi Kasei Microdevices Corporation, Japan
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- ******************************************************************************/
-#ifndef AKFS_INC_AOC_H
-#define AKFS_INC_AOC_H
-
-#include "AKFS_Device.h"
-
-/***** Constant definition ****************************************************/
-#define AKFS_HBUF_SIZE 20
-#define AKFS_HOBUF_SIZE 4
-#define AKFS_HR_TH 10
-#define AKFS_HO_TH 0.15
-
-/***** Macro definition *******************************************************/
-
-/***** Type declaration *******************************************************/
-typedef struct _AKFS_AOC_VAR{
- AKFVEC hbuf[AKFS_HBUF_SIZE];
- AKFVEC hobuf[AKFS_HOBUF_SIZE];
- AKFLOAT hraoc;
-} AKFS_AOC_VAR;
-
-/***** Prototype of function **************************************************/
-AKLIB_C_API_START
-int16 AKFS_AOC(
- AKFS_AOC_VAR *haocv,
- const AKFVEC *hdata,
- AKFVEC *ho
-);
-
-void AKFS_InitAOC(
- AKFS_AOC_VAR *haocv
-);
-
-AKLIB_C_API_END
-
-#endif
-
diff --git a/sensors/algo/common/compass/AKFS_Configure.h b/sensors/algo/common/compass/AKFS_Configure.h
deleted file mode 100644
index 1f80f48..0000000
--- a/sensors/algo/common/compass/AKFS_Configure.h
+++ /dev/null
@@ -1,37 +0,0 @@
-/******************************************************************************
- *
- * Copyright (C) 2012 Asahi Kasei Microdevices Corporation, Japan
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- ******************************************************************************/
-#ifndef AKFS_INC_CONFIG_H
-#define AKFS_INC_CONFIG_H
-
-/***** Language configuration *************************************************/
-#if defined(__cplusplus)
-#define AKLIB_C_API_START extern "C" {
-#define AKLIB_C_API_END }
-#else
-#define AKLIB_C_API_START
-#define AKLIB_C_API_END
-#endif
-
-/*! If following line is commented in, double type is used for floating point
- calculation */
-/*
-#define AKFS_PRECISION_DOUBLE
-*/
-
-#endif
-
diff --git a/sensors/algo/common/compass/AKFS_Decomp.c b/sensors/algo/common/compass/AKFS_Decomp.c
deleted file mode 100644
index da1d3ba..0000000
--- a/sensors/algo/common/compass/AKFS_Decomp.c
+++ /dev/null
@@ -1,51 +0,0 @@
-/******************************************************************************
- *
- * Copyright (C) 2012 Asahi Kasei Microdevices Corporation, Japan
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- ******************************************************************************/
-#include "AKFS_Decomp.h"
-#include "AKFS_Device.h"
-
-/******************************************************************************/
-/*! Convert from sensor local data unit to micro tesla, then buffer the data.
- @return #AKFS_SUCCESS on success. Otherwise the return value is #AKFS_ERROR.
- @param[in] mag
- @param[in] status
- @param[in] asa
- @param[in] nhdata
- @param[out] hdata
- */
-int16 AKFS_Decomp(
- const int16 mag[3],
- const int16 status,
- const uint8vec *asa,
- const int16 nhdata,
- AKFVEC hdata[]
-)
-{
- /* put st1 and st2 value */
- if (AKM_ST_ERROR(status)) {
- return AKFS_ERROR;
- }
-
- /* magnetic */
- AKFS_BufShift(nhdata, 1, hdata);
- hdata[0].u.x = AKM_HDATA_CONVERTER(mag[0], asa->u.x) * AKM_SENSITIVITY;
- hdata[0].u.y = AKM_HDATA_CONVERTER(mag[1], asa->u.y) * AKM_SENSITIVITY;
- hdata[0].u.z = AKM_HDATA_CONVERTER(mag[2], asa->u.z) * AKM_SENSITIVITY;
-
- return AKFS_SUCCESS;
-}
-
diff --git a/sensors/algo/common/compass/AKFS_Decomp.h b/sensors/algo/common/compass/AKFS_Decomp.h
deleted file mode 100644
index ef43fba..0000000
--- a/sensors/algo/common/compass/AKFS_Decomp.h
+++ /dev/null
@@ -1,58 +0,0 @@
-/******************************************************************************
- *
- * Copyright (C) 2012 Asahi Kasei Microdevices Corporation, Japan
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- ******************************************************************************/
-#ifndef AKFS_INC_DECOMP_H
-#define AKFS_INC_DECOMP_H
-
-#include "AKFS_Device.h"
-
-/***** Constant definition ****************************************************/
-#if defined(AKM_DEVICE_AK8963)
-#define AKM_SENSITIVITY 0.15f
-#define AKM_ST_ERROR(st) (((st)&0x19) != 0x11)
-#define AKM_HDATA_CONVERTER(data, asa) \
- (AKFLOAT)(((data)*(((asa)/256.0f) + 0.5f)))
-
-#elif defined(AKM_DEVICE_AK8975)
-#define AKM_SENSITIVITY 0.3f
-#define AKM_ST_ERROR(st) (((st)&0x09) != 0x01)
-#define AKM_HDATA_CONVERTER(data, asa) \
- (AKFLOAT)(((data)*(((asa)/256.0f) + 0.5f)))
-
-#elif defined(AKM_DEVICE_AK09911)
-#define AKM_SENSITIVITY 0.6f
-#define AKM_ST_ERROR(st) (((st)&0x09) != 0x01)
-#define AKM_HDATA_CONVERTER(data, asa) \
- (AKFLOAT)(((data)*(((asa)/128.0f) + 1.0f)))
-
-#endif
-
-
-/***** Type declaration *******************************************************/
-
-/***** Prototype of function **************************************************/
-AKLIB_C_API_START
-int16 AKFS_Decomp(
- const int16 mag[3],
- const int16 status,
- const uint8vec *asa,
- const int16 nhdata,
- AKFVEC hdata[]
-);
-AKLIB_C_API_END
-
-#endif
diff --git a/sensors/algo/common/compass/AKFS_Device.c b/sensors/algo/common/compass/AKFS_Device.c
deleted file mode 100644
index 75c36c3..0000000
--- a/sensors/algo/common/compass/AKFS_Device.c
+++ /dev/null
@@ -1,150 +0,0 @@
-/******************************************************************************
- *
- * Copyright (C) 2012 Asahi Kasei Microdevices Corporation, Japan
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- ******************************************************************************/
-#include "AKFS_Device.h"
-
-/******************************************************************************/
-/*! Initialize #AKFVEC array.
- @return #AKFS_SUCCESS on success. Otherwise the return value is #AKFS_ERROR.
- @param[in] ndata
- @param[out] vdata
- */
-int16 AKFS_InitBuffer(
- const int16 ndata, /*!< Size of vector buffer */
- AKFVEC vdata[] /*!< Vector buffer */
-)
-{
- int i;
-
- /* size check */
- if (ndata <= 0) {
- return AKFS_ERROR;
- }
-
- for (i = 0; i < ndata; i++) {
- vdata[i].u.x = AKFS_INIT_VALUE_F;
- vdata[i].u.y = AKFS_INIT_VALUE_F;
- vdata[i].u.z = AKFS_INIT_VALUE_F;
- }
-
- return AKFS_SUCCESS;
-}
-
-/******************************************************************************/
-/*! Shift #AKFVEC array.
- @return #AKFS_SUCCESS on success. Otherwise the return value is #AKFS_ERROR.
- @param[in] len
- @param[in] shift
- @param[in/out] v
- */
-int16 AKFS_BufShift(
- const int16 len, /*!< size of buffer */
- const int16 shift, /*!< shift size */
- AKFVEC v[] /*!< buffer */
-)
-{
- int16 i;
-
- if ((shift < 1) || (len < shift)) {
- return AKFS_ERROR;
- }
- for (i = len-1; i >= shift; i--) {
- v[i] = v[i-shift];
- }
- return AKFS_SUCCESS;
-}
-
-/******************************************************************************/
-/*! Rotate vector according to the specified layout pattern number.
- @return #AKFS_SUCCESS on success. Otherwise the return value is #AKFS_ERROR.
- @param[in] pat
- @param[in/out] vec
- */
-int16 AKFS_Rotate(
- const AKFS_PATNO pat,
- AKFVEC *vec
-)
-{
- AKFLOAT tmp;
- switch (pat) {
- /* Obverse */
- case PAT1:
- /* This is Android default */
- break;
- case PAT2:
- tmp = vec->u.x;
- vec->u.x = vec->u.y;
- vec->u.y = -tmp;
- break;
- case PAT3:
- vec->u.x = -(vec->u.x);
- vec->u.y = -(vec->u.y);
- break;
- case PAT4:
- tmp = vec->u.x;
- vec->u.x = -(vec->u.y);
- vec->u.y = tmp;
- break;
- /* Reverse */
- case PAT5:
- vec->u.x = -(vec->u.x);
- vec->u.z = -(vec->u.z);
- break;
- case PAT6:
- tmp = vec->u.x;
- vec->u.x = vec->u.y;
- vec->u.y = tmp;
- vec->u.z = -(vec->u.z);
- break;
- case PAT7:
- vec->u.y = -(vec->u.y);
- vec->u.z = -(vec->u.z);
- break;
- case PAT8:
- tmp = vec->u.x;
- vec->u.x = -(vec->u.y);
- vec->u.y = -tmp;
- vec->u.z = -(vec->u.z);
- break;
- default:
- return AKFS_ERROR;
- }
-
- return AKFS_SUCCESS;
-}
-
-/******************************************************************************/
-/*! Rotate vector according to the specified layout matrix.
- @return #AKFS_SUCCESS on success. Otherwise the return value is #AKFS_ERROR.
- @param[in] pat
- @param[in/out] vec
- */
-int16 AKFS_RotateMat(
- const int16 layout[3][3],
- AKFVEC *vec
-)
-{
- AKFVEC tmp;
-
- tmp.u.x = layout[0][0]*vec->u.x + layout[0][1]*vec->u.y + layout[0][2]*vec->u.z;
- tmp.u.y = layout[1][0]*vec->u.x + layout[1][1]*vec->u.y + layout[1][2]*vec->u.z;
- tmp.u.z = layout[2][0]*vec->u.x + layout[2][1]*vec->u.y + layout[2][2]*vec->u.z;
-
- *vec = tmp;
-
- return AKFS_SUCCESS;
-}
diff --git a/sensors/algo/common/compass/AKFS_Device.h b/sensors/algo/common/compass/AKFS_Device.h
deleted file mode 100644
index e1893e8..0000000
--- a/sensors/algo/common/compass/AKFS_Device.h
+++ /dev/null
@@ -1,112 +0,0 @@
-/******************************************************************************
- *
- * Copyright (C) 2012 Asahi Kasei Microdevices Corporation, Japan
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- ******************************************************************************/
-#ifndef AKFS_INC_DEVICE_H
-#define AKFS_INC_DEVICE_H
-
-#include <float.h>
-#include "AKFS_Configure.h"
-
-/***** Constant definition ****************************************************/
-#define AKFS_ERROR 0
-#define AKFS_SUCCESS 1
-
-#define AKFS_HDATA_SIZE 32
-#define AKFS_ADATA_SIZE 32
-
-/***** Type declaration *******************************************************/
-typedef signed char int8;
-typedef signed short int16;
-typedef unsigned char uint8;
-typedef unsigned short uint16;
-
-
-#ifdef AKFS_PRECISION_DOUBLE
-typedef double AKFLOAT;
-#define AKFS_EPSILON DBL_EPSILON
-#define AKFS_FMAX DBL_MAX
-#define AKFS_FMIN DBL_MIN
-
-#else
-typedef float AKFLOAT;
-#define AKFS_EPSILON FLT_EPSILON
-#define AKFS_FMAX FLT_MAX
-#define AKFS_FMIN FLT_MIN
-
-#endif
-
-/* Treat maximum value as initial value */
-#define AKFS_INIT_VALUE_F AKFS_FMAX
-
-/***** Vector ****************************************************************/
-typedef union _uint8vec {
- struct {
- uint8 x;
- uint8 y;
- uint8 z;
- } u;
- uint8 v[3];
-} uint8vec;
-
-typedef union _AKFVEC {
- struct {
- AKFLOAT x;
- AKFLOAT y;
- AKFLOAT z;
- } u;
- AKFLOAT v[3];
-} AKFVEC;
-
-/***** Layout pattern ********************************************************/
-typedef enum _AKFS_PATNO {
- PAT_INVALID = 0,
- PAT1, /* obverse: 1st pin is right down */
- PAT2, /* obverse: 1st pin is left down */
- PAT3, /* obverse: 1st pin is left top */
- PAT4, /* obverse: 1st pin is right top */
- PAT5, /* reverse: 1st pin is left down (from top view) */
- PAT6, /* reverse: 1st pin is left top (from top view) */
- PAT7, /* reverse: 1st pin is right top (from top view) */
- PAT8 /* reverse: 1st pin is right down (from top view) */
-} AKFS_PATNO;
-
-/***** Prototype of function **************************************************/
-AKLIB_C_API_START
-int16 AKFS_InitBuffer(
- const int16 ndata, /*!< Size of raw vector buffer */
- AKFVEC vdata[] /*!< Raw vector buffer */
-);
-
-int16 AKFS_BufShift(
- const int16 len,
- const int16 shift,
- AKFVEC v[]
-);
-
-int16 AKFS_Rotate(
- const AKFS_PATNO pat,
- AKFVEC *vec
-);
-
-int16 AKFS_RotateMat(
- const int16 layout[3][3],
- AKFVEC *vec
-);
-AKLIB_C_API_END
-
-#endif
-
diff --git a/sensors/algo/common/compass/AKFS_Direction.c b/sensors/algo/common/compass/AKFS_Direction.c
deleted file mode 100644
index 2107e7e..0000000
--- a/sensors/algo/common/compass/AKFS_Direction.c
+++ /dev/null
@@ -1,166 +0,0 @@
-/******************************************************************************
- *
- * Copyright (C) 2012 Asahi Kasei Microdevices Corporation, Japan
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- ******************************************************************************/
-#include "AKFS_Device.h"
-#include "AKFS_Direction.h"
-#include "AKFS_VNorm.h"
-#include "AKFS_Math.h"
-
-/******************************************************************************/
-/* About definition of coordinate system and calculated value.
- Coordinate system is right-handed.
- X-Axis: from left to right.
- Y-Axis: from bottom to top.
- Z-Axis: from reverse to obverse.
-
- azimuth: Rotation around Z axis, with positive values
- when y-axis moves toward the x-axis.
- pitch: Rotation around X axis, with positive values
- when z-axis moves toward the y-axis.
- roll: Rotation around Y axis, with positive values
- when x-axis moves toward the z-axis.
-*/
-
-
-/******************************************************************************/
-/*! This function is used internally, so output is RADIAN!
- @return #AKFS_SUCCESS on success. Otherwise the return value is #AKFS_ERROR.
- @param[in] avec
- @param[out] pitch
- @param[out] roll
- */
-static int16 AKFS_Angle(
- const AKFVEC *avec,
- AKFLOAT *pitch, /* radian */
- AKFLOAT *roll /* radian */
-)
-{
- AKFLOAT av; /* Size of vector */
-
- av = AKFS_SQRT((avec->u.x)*(avec->u.x) + (avec->u.y)*(avec->u.y) + (avec->u.z)*(avec->u.z));
-
- if (av < AKFS_EPSILON) {
- return AKFS_ERROR;
- }
-
- *pitch = AKFS_ASIN(-(avec->u.y) / av);
- *roll = AKFS_ASIN((avec->u.x) / av);
-
- return AKFS_SUCCESS;
-}
-
-/******************************************************************************/
-/*! This function is used internally, so output is RADIAN!
- @return None
- @param[in] hvec
- @param[in] pitch
- @param[in] roll
- @param[out] azimuth
- */
-static void AKFS_Azimuth(
- const AKFVEC *hvec,
- const AKFLOAT pitch, /* radian */
- const AKFLOAT roll, /* radian */
- AKFLOAT *azimuth /* radian */
-)
-{
- AKFLOAT sinP; /* sin value of pitch angle */
- AKFLOAT cosP; /* cos value of pitch angle */
- AKFLOAT sinR; /* sin value of roll angle */
- AKFLOAT cosR; /* cos value of roll angle */
- AKFLOAT Xh; /* X axis element of vector which is projected to horizontal plane */
- AKFLOAT Yh; /* Y axis element of vector which is projected to horizontal plane */
-
- sinP = AKFS_SIN(pitch);
- cosP = AKFS_COS(pitch);
- sinR = AKFS_SIN(roll);
- cosR = AKFS_COS(roll);
-
- Yh = -(hvec->u.x)*cosR + (hvec->u.z)*sinR;
- Xh = (hvec->u.x)*sinP*sinR + (hvec->u.y)*cosP + (hvec->u.z)*sinP*cosR;
-
- /* atan2(y, x) -> divisor and dividend is opposite from mathematical equation. */
- *azimuth = AKFS_ATAN2(Yh, Xh);
-}
-
-/******************************************************************************/
-/*! Output is DEGREE!
- @return #AKFS_SUCCESS on success. Otherwise the return value is #AKFS_ERROR.
- @param[in] nhvec
- @param[in] hvec
- @param[in] hnave
- @param[in] navec
- @param[in] avec
- @param[in] anave
- @param[out] azimuth
- @param[out] pitch
- @param[out] roll
- */
-int16 AKFS_Direction(
- const int16 nhvec,
- const AKFVEC hvec[],
- const int16 hnave,
- const int16 navec,
- const AKFVEC avec[],
- const int16 anave,
- AKFLOAT *azimuth,
- AKFLOAT *pitch,
- AKFLOAT *roll
-)
-{
- AKFVEC have, aave;
- AKFLOAT azimuthRad;
- AKFLOAT pitchRad;
- AKFLOAT rollRad;
-
- /* arguments check */
- if ((nhvec <= 0) || (navec <= 0) || (hnave <= 0) || (anave <= 0)) {
- return AKFS_ERROR;
- }
- if ((nhvec < hnave) || (navec < anave)) {
- return AKFS_ERROR;
- }
-
- /* average */
- if (AKFS_VbAve(nhvec, hvec, hnave, &have) != AKFS_SUCCESS) {
- return AKFS_ERROR;
- }
- if (AKFS_VbAve(navec, avec, anave, &aave) != AKFS_SUCCESS) {
- return AKFS_ERROR;
- }
-
- /* calculate pitch and roll */
- if (AKFS_Angle(&aave, &pitchRad, &rollRad) != AKFS_SUCCESS) {
- return AKFS_ERROR;
- }
-
- /* calculate azimuth */
- AKFS_Azimuth(&have, pitchRad, rollRad, &azimuthRad);
-
- *azimuth = RAD2DEG(azimuthRad);
- *pitch = RAD2DEG(pitchRad);
- *roll = RAD2DEG(rollRad);
-
- /* Adjust range of azimuth */
- if (*azimuth < 0) {
- *azimuth += 360.0f;
- }
-
- return AKFS_SUCCESS;
-}
-
-
diff --git a/sensors/algo/common/compass/AKFS_Direction.h b/sensors/algo/common/compass/AKFS_Direction.h
deleted file mode 100644
index fe1dc13..0000000
--- a/sensors/algo/common/compass/AKFS_Direction.h
+++ /dev/null
@@ -1,39 +0,0 @@
-/******************************************************************************
- *
- * Copyright (C) 2012 Asahi Kasei Microdevices Corporation, Japan
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- ******************************************************************************/
-#ifndef AKFS_INC_DIRECTION_H
-#define AKFS_INC_DIRECTION_H
-
-#include "AKFS_Device.h"
-
-/***** Prototype of function **************************************************/
-AKLIB_C_API_START
-int16 AKFS_Direction(
- const int16 nhvec,
- const AKFVEC hvec[],
- const int16 hnave,
- const int16 navec,
- const AKFVEC avec[],
- const int16 anave,
- AKFLOAT *azimuth,
- AKFLOAT *pitch,
- AKFLOAT *roll
-);
-AKLIB_C_API_END
-
-#endif
-
diff --git a/sensors/algo/common/compass/AKFS_Math.h b/sensors/algo/common/compass/AKFS_Math.h
deleted file mode 100644
index dfe48b3..0000000
--- a/sensors/algo/common/compass/AKFS_Math.h
+++ /dev/null
@@ -1,47 +0,0 @@
-/******************************************************************************
- *
- * Copyright (C) 2012 Asahi Kasei Microdevices Corporation, Japan
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- ******************************************************************************/
-#ifndef AKFS_INC_MATH_H
-#define AKFS_INC_MATH_H
-
-#include <math.h>
-#include "AKFS_Configure.h"
-
-/***** Constant definition ****************************************************/
-#define AKFS_PI 3.141592654f
-#define RAD2DEG(rad) ((rad)*180.0f/AKFS_PI)
-
-/***** Macro definition *******************************************************/
-
-#ifdef AKFS_PRECISION_DOUBLE
-#define AKFS_SIN(x) sin(x)
-#define AKFS_COS(x) cos(x)
-#define AKFS_ASIN(x) asin(x)
-#define AKFS_ACOS(x) acos(x)
-#define AKFS_ATAN2(y, x) atan2((y), (x))
-#define AKFS_SQRT(x) sqrt(x)
-#else
-#define AKFS_SIN(x) sinf(x)
-#define AKFS_COS(x) cosf(x)
-#define AKFS_ASIN(x) asinf(x)
-#define AKFS_ACOS(x) acosf(x)
-#define AKFS_ATAN2(y, x) atan2f((y), (x))
-#define AKFS_SQRT(x) sqrtf(x)
-#endif
-
-#endif
-
diff --git a/sensors/algo/common/compass/AKFS_VNorm.c b/sensors/algo/common/compass/AKFS_VNorm.c
deleted file mode 100644
index 5372a36..0000000
--- a/sensors/algo/common/compass/AKFS_VNorm.c
+++ /dev/null
@@ -1,123 +0,0 @@
-/******************************************************************************
- *
- * Copyright (C) 2012 Asahi Kasei Microdevices Corporation, Japan
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- ******************************************************************************/
-#include "AKFS_Device.h"
-#include "AKFS_VNorm.h"
-
-/******************************************************************************/
-/*! Normalize vector.
- @return #AKFS_SUCCESS on success. Otherwise the return value is #AKFS_ERROR.
- @param[in] ndata Size of raw vector buffer
- @param[in] vdata Raw vector buffer
- @param[in] nbuf Size of data to be buffered
- @param[in] o Offset
- @param[in] s Sensitivity
- @param[in] tgt Target sensitivity
- @param[in] nvec Size of normalized vector buffer
- @param[out] vvec Normalized vector buffer
- */
-int16 AKFS_VbNorm(
- const int16 ndata,
- const AKFVEC vdata[],
- const int16 nbuf,
- const AKFVEC *o,
- const AKFVEC *s,
- const AKFLOAT tgt,
- const int16 nvec,
- AKFVEC vvec[]
-)
-{
- int i;
-
- /* size check */
- if ((ndata <= 0) || (nvec <= 0) || (nbuf <= 0)) {
- return AKFS_ERROR;
- }
- /* dependency check */
- if ((nbuf < 1) || (ndata < nbuf) || (nvec < nbuf)) {
- return AKFS_ERROR;
- }
- /* sensitivity check */
- if ((s->u.x <= AKFS_EPSILON) ||
- (s->u.y <= AKFS_EPSILON) ||
- (s->u.z <= AKFS_EPSILON) ||
- (tgt <= 0)) {
- return AKFS_ERROR;
- }
-
- /* calculate and store data to buffer */
- if (AKFS_BufShift(nvec, nbuf, vvec) != AKFS_SUCCESS) {
- return AKFS_ERROR;
- }
- for (i = 0; i < nbuf; i++) {
- vvec[i].u.x = ((vdata[i].u.x - o->u.x) / (s->u.x) * (AKFLOAT)tgt);
- vvec[i].u.y = ((vdata[i].u.y - o->u.y) / (s->u.y) * (AKFLOAT)tgt);
- vvec[i].u.z = ((vdata[i].u.z - o->u.z) / (s->u.z) * (AKFLOAT)tgt);
- }
-
- return AKFS_SUCCESS;
-}
-
-/******************************************************************************/
-/*! Calculate an averaged vector form a given buffer.
- @return #AKFS_SUCCESS on success. Otherwise the return value is #AKFS_ERROR.
- @param[in] nvec Size of normalized vector buffer
- @param[in] vvec Normalized vector buffer
- @param[in] nave Number of average
- @param[out] vave Averaged vector
- */
-int16 AKFS_VbAve(
- const int16 nvec,
- const AKFVEC vvec[],
- const int16 nave,
- AKFVEC *vave
-)
-{
- int i;
-
- /* arguments check */
- if ((nave <= 0) || (nvec <= 0) || (nvec < nave)) {
- return AKFS_ERROR;
- }
-
- /* calculate average */
- vave->u.x = 0;
- vave->u.y = 0;
- vave->u.z = 0;
- for (i = 0; i < nave; i++) {
- if ((vvec[i].u.x == AKFS_INIT_VALUE_F) ||
- (vvec[i].u.y == AKFS_INIT_VALUE_F) ||
- (vvec[i].u.z == AKFS_INIT_VALUE_F)) {
- break;
- }
- vave->u.x += vvec[i].u.x;
- vave->u.y += vvec[i].u.y;
- vave->u.z += vvec[i].u.z;
- }
- if (i == 0) {
- vave->u.x = 0;
- vave->u.y = 0;
- vave->u.z = 0;
- } else {
- vave->u.x /= i;
- vave->u.y /= i;
- vave->u.z /= i;
- }
- return AKFS_SUCCESS;
-}
-
-
diff --git a/sensors/algo/common/compass/AKFS_VNorm.h b/sensors/algo/common/compass/AKFS_VNorm.h
deleted file mode 100644
index 92dd949..0000000
--- a/sensors/algo/common/compass/AKFS_VNorm.h
+++ /dev/null
@@ -1,46 +0,0 @@
-/******************************************************************************
- *
- * Copyright (C) 2012 Asahi Kasei Microdevices Corporation, Japan
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- ******************************************************************************/
-#ifndef AKFS_INC_VNORM_H
-#define AKFS_INC_VNORM_H
-
-#include "AKFS_Device.h"
-
-/***** Prototype of function **************************************************/
-AKLIB_C_API_START
-int16 AKFS_VbNorm(
- const int16 ndata,
- const AKFVEC vdata[],
- const int16 nbuf,
- const AKFVEC *o,
- const AKFVEC *s,
- const AKFLOAT tgt,
- const int16 nvec,
- AKFVEC vvec[]
-);
-
-int16 AKFS_VbAve(
- const int16 nvec,
- const AKFVEC vvec[],
- const int16 nave,
- AKFVEC *vave
-);
-
-AKLIB_C_API_END
-
-#endif
-
diff --git a/sensors/algo/common/compass/NOTICE b/sensors/algo/common/compass/NOTICE
deleted file mode 100644
index d645695..0000000
--- a/sensors/algo/common/compass/NOTICE
+++ /dev/null
@@ -1,202 +0,0 @@
-
- Apache License
- Version 2.0, January 2004
- http://www.apache.org/licenses/
-
- TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
-
- 1. Definitions.
-
- "License" shall mean the terms and conditions for use, reproduction,
- and distribution as defined by Sections 1 through 9 of this document.
-
- "Licensor" shall mean the copyright owner or entity authorized by
- the copyright owner that is granting the License.
-
- "Legal Entity" shall mean the union of the acting entity and all
- other entities that control, are controlled by, or are under common
- control with that entity. For the purposes of this definition,
- "control" means (i) the power, direct or indirect, to cause the
- direction or management of such entity, whether by contract or
- otherwise, or (ii) ownership of fifty percent (50%) or more of the
- outstanding shares, or (iii) beneficial ownership of such entity.
-
- "You" (or "Your") shall mean an individual or Legal Entity
- exercising permissions granted by this License.
-
- "Source" form shall mean the preferred form for making modifications,
- including but not limited to software source code, documentation
- source, and configuration files.
-
- "Object" form shall mean any form resulting from mechanical
- transformation or translation of a Source form, including but
- not limited to compiled object code, generated documentation,
- and conversions to other media types.
-
- "Work" shall mean the work of authorship, whether in Source or
- Object form, made available under the License, as indicated by a
- copyright notice that is included in or attached to the work
- (an example is provided in the Appendix below).
-
- "Derivative Works" shall mean any work, whether in Source or Object
- form, that is based on (or derived from) the Work and for which the
- editorial revisions, annotations, elaborations, or other modifications
- represent, as a whole, an original work of authorship. For the purposes
- of this License, Derivative Works shall not include works that remain
- separable from, or merely link (or bind by name) to the interfaces of,
- the Work and Derivative Works thereof.
-
- "Contribution" shall mean any work of authorship, including
- the original version of the Work and any modifications or additions
- to that Work or Derivative Works thereof, that is intentionally
- submitted to Licensor for inclusion in the Work by the copyright owner
- or by an individual or Legal Entity authorized to submit on behalf of
- the copyright owner. For the purposes of this definition, "submitted"
- means any form of electronic, verbal, or written communication sent
- to the Licensor or its representatives, including but not limited to
- communication on electronic mailing lists, source code control systems,
- and issue tracking systems that are managed by, or on behalf of, the
- Licensor for the purpose of discussing and improving the Work, but
- excluding communication that is conspicuously marked or otherwise
- designated in writing by the copyright owner as "Not a Contribution."
-
- "Contributor" shall mean Licensor and any individual or Legal Entity
- on behalf of whom a Contribution has been received by Licensor and
- subsequently incorporated within the Work.
-
- 2. Grant of Copyright License. Subject to the terms and conditions of
- this License, each Contributor hereby grants to You a perpetual,
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
- copyright license to reproduce, prepare Derivative Works of,
- publicly display, publicly perform, sublicense, and distribute the
- Work and such Derivative Works in Source or Object form.
-
- 3. Grant of Patent License. Subject to the terms and conditions of
- this License, each Contributor hereby grants to You a perpetual,
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
- (except as stated in this section) patent license to make, have made,
- use, offer to sell, sell, import, and otherwise transfer the Work,
- where such license applies only to those patent claims licensable
- by such Contributor that are necessarily infringed by their
- Contribution(s) alone or by combination of their Contribution(s)
- with the Work to which such Contribution(s) was submitted. If You
- institute patent litigation against any entity (including a
- cross-claim or counterclaim in a lawsuit) alleging that the Work
- or a Contribution incorporated within the Work constitutes direct
- or contributory patent infringement, then any patent licenses
- granted to You under this License for that Work shall terminate
- as of the date such litigation is filed.
-
- 4. Redistribution. You may reproduce and distribute copies of the
- Work or Derivative Works thereof in any medium, with or without
- modifications, and in Source or Object form, provided that You
- meet the following conditions:
-
- (a) You must give any other recipients of the Work or
- Derivative Works a copy of this License; and
-
- (b) You must cause any modified files to carry prominent notices
- stating that You changed the files; and
-
- (c) You must retain, in the Source form of any Derivative Works
- that You distribute, all copyright, patent, trademark, and
- attribution notices from the Source form of the Work,
- excluding those notices that do not pertain to any part of
- the Derivative Works; and
-
- (d) If the Work includes a "NOTICE" text file as part of its
- distribution, then any Derivative Works that You distribute must
- include a readable copy of the attribution notices contained
- within such NOTICE file, excluding those notices that do not
- pertain to any part of the Derivative Works, in at least one
- of the following places: within a NOTICE text file distributed
- as part of the Derivative Works; within the Source form or
- documentation, if provided along with the Derivative Works; or,
- within a display generated by the Derivative Works, if and
- wherever such third-party notices normally appear. The contents
- of the NOTICE file are for informational purposes only and
- do not modify the License. You may add Your own attribution
- notices within Derivative Works that You distribute, alongside
- or as an addendum to the NOTICE text from the Work, provided
- that such additional attribution notices cannot be construed
- as modifying the License.
-
- You may add Your own copyright statement to Your modifications and
- may provide additional or different license terms and conditions
- for use, reproduction, or distribution of Your modifications, or
- for any such Derivative Works as a whole, provided Your use,
- reproduction, and distribution of the Work otherwise complies with
- the conditions stated in this License.
-
- 5. Submission of Contributions. Unless You explicitly state otherwise,
- any Contribution intentionally submitted for inclusion in the Work
- by You to the Licensor shall be under the terms and conditions of
- this License, without any additional terms or conditions.
- Notwithstanding the above, nothing herein shall supersede or modify
- the terms of any separate license agreement you may have executed
- with Licensor regarding such Contributions.
-
- 6. Trademarks. This License does not grant permission to use the trade
- names, trademarks, service marks, or product names of the Licensor,
- except as required for reasonable and customary use in describing the
- origin of the Work and reproducing the content of the NOTICE file.
-
- 7. Disclaimer of Warranty. Unless required by applicable law or
- agreed to in writing, Licensor provides the Work (and each
- Contributor provides its Contributions) on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
- implied, including, without limitation, any warranties or conditions
- of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
- PARTICULAR PURPOSE. You are solely responsible for determining the
- appropriateness of using or redistributing the Work and assume any
- risks associated with Your exercise of permissions under this License.
-
- 8. Limitation of Liability. In no event and under no legal theory,
- whether in tort (including negligence), contract, or otherwise,
- unless required by applicable law (such as deliberate and grossly
- negligent acts) or agreed to in writing, shall any Contributor be
- liable to You for damages, including any direct, indirect, special,
- incidental, or consequential damages of any character arising as a
- result of this License or out of the use or inability to use the
- Work (including but not limited to damages for loss of goodwill,
- work stoppage, computer failure or malfunction, or any and all
- other commercial damages or losses), even if such Contributor
- has been advised of the possibility of such damages.
-
- 9. Accepting Warranty or Additional Liability. While redistributing
- the Work or Derivative Works thereof, You may choose to offer,
- and charge a fee for, acceptance of support, warranty, indemnity,
- or other liability obligations and/or rights consistent with this
- License. However, in accepting such obligations, You may act only
- on Your own behalf and on Your sole responsibility, not on behalf
- of any other Contributor, and only if You agree to indemnify,
- defend, and hold each Contributor harmless for any liability
- incurred by, or claims asserted against, such Contributor by reason
- of your accepting any such warranty or additional liability.
-
- END OF TERMS AND CONDITIONS
-
- APPENDIX: How to apply the Apache License to your work.
-
- To apply the Apache License to your work, attach the following
- boilerplate notice, with the fields enclosed by brackets "[]"
- replaced with your own identifying information. (Don't include
- the brackets!) The text should be enclosed in the appropriate
- comment syntax for the file format. We also recommend that a
- file or class name and description of purpose be included on the
- same "printed page" as the copyright notice for easier
- identification within third-party archives.
-
- Copyright [yyyy] [name of copyright owner]
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
diff --git a/sensors/algo/common/compass/README.md b/sensors/algo/common/compass/README.md
deleted file mode 100644
index a3e3803..0000000
--- a/sensors/algo/common/compass/README.md
+++ /dev/null
@@ -1,34 +0,0 @@
-AK8975/AK8963/AK09911 Sensor Daemon for Android.
-=========
-Compass Control Program for Android Open Source Project
-
-## NOTICE
- 1. Asahi Kasei Microdevices Corporation ("AKM") is pleased to make available to you the source codes of the Electronic Compass Control Program ("Software") for download from this website at no charge. By downloading the Software, you expressly assume all risk and liability associated with downloading and using the Software.
-
- 2. AKM PROVIDES THE SOFTWARE AND THIS DOWNLOADING SERVICE "AS IS" WITHOUT WARRANTY OF ANY KIND AND ALL SUCH WARRANTIES, EXPRESS OR IMPLIED, ARE HEREBY DISCLAIMED, INCLUDING, WITHOUT LIMITATION, WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE ACCURACY, AVAILABILITY, OR NON-INFRINGEMENT. YOU ACKNOWLEDGE THAT AKM IS NOT OBLIGATED TO PROVIDE AND DOES NOT PROVIDE ANY SUPPORT OR ASSISTANCE WITH RESPECT TO THE SOFTWARE.
-
- 3. This downloading service shall not affect nor extend any warranty or disclaimer which AKM makes in each of AKM's products in which the Software works with.
-
- 4. This NOTICE shall be governed by and interpreted under the laws of Japan. All disputes arising out of or under this NOTICE shall be subject to under the exclusive and agreed jurisdiction of the Tokyo District Court as the court of first instance.
-
-## About
-This software is developed by Asahi Kasei Microdevices Corporation ("AKM") to provide compatible daemon program, it is known as akmd2 in many production Android phones.
-
-This software consists from two parts, one is Sensor Control Program (i.e. akmd2) and Sensor HAL (sensors.*.so). Sensor Control Program gets magnetic sensor data form the AKM's compass IC, then estimate offset and calculate azimuth, pitch and roll angle. This behavior is quite similar to the original one. We aimed to develop a compatible daemon software.
-
-This software may help people who wants to study how to control AKM's magnetic sensor on Android.
-
-## License
-The license for all code in this source code is specified in the NOTICE file. Please, refer to this file for further details.
-
-## Build
-To build this project, uncomment your desired device from the top of Android.mk file.
-
- vi $(YOUR_ENV)/AK8975_FS/Android.mk
-
-For example, if you wish to have a software for AK8975, please uncomment the following line.
-
- export AKMD_DEVICE_TYPE=8975
-
-Type 'mm -B', then you will get two binary files, **akmdfs** and **sensors.default.so**.
-
diff --git a/sensors/calmodule.cfg b/sensors/calmodule.cfg
deleted file mode 100644
index 6fb4f3b..0000000
--- a/sensors/calmodule.cfg
+++ /dev/null
@@ -1,2 +0,0 @@
-libcalmodule_akm.so
-libcalmodule_common.so
diff --git a/sensors/sensors.cpp b/sensors/sensors.cpp
deleted file mode 100644
index 7faf7a1..0000000
--- a/sensors/sensors.cpp
+++ /dev/null
@@ -1,390 +0,0 @@
-/*
- * Copyright (c) 2014, The Linux Foundation. All rights reserved.
- * Not a Contribution.
- * Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#define LOG_TAG "Sensors"
-
-#include <hardware/sensors.h>
-#include <fcntl.h>
-#include <errno.h>
-#include <dirent.h>
-#include <math.h>
-#include <poll.h>
-#include <pthread.h>
-#include <stdlib.h>
-#include <linux/input.h>
-#include <utils/Atomic.h>
-#include <utils/Log.h>
-#include <CalibrationManager.h>
-
-#include "sensors.h"
-#include "AccelSensor.h"
-#include "LightSensor.h"
-#include "ProximitySensor.h"
-#include "CompassSensor.h"
-#include "GyroSensor.h"
-
-#include "NativeSensorManager.h"
-#include "sensors_extension.h"
-/*****************************************************************************/
-
-/**
- * structure representing a command to be dispatched to the poll thread
- */
-struct sensor_command {
- enum cmd_type {
- CMD_ENABLE,
- CMD_SET_PERIOD,
- };
- cmd_type type;
- size_t sz;
- int sensor;
- union {
- bool enabled;
- uint64_t period;
- };
-};
-
-static int open_sensors(const struct hw_module_t* module, const char* id,
- struct hw_device_t** device);
-
-static int sensors__get_sensors_list(struct sensors_module_t*,
- struct sensor_t const** list)
-{
- NativeSensorManager& sm(NativeSensorManager::getInstance());
-
- return sm.getSensorList(list);
-}
-
-static struct hw_module_methods_t sensors_module_methods = {
- open: open_sensors
-};
-
-struct sensors_module_t HAL_MODULE_INFO_SYM = {
- common: {
- tag: HARDWARE_MODULE_TAG,
- version_major: 1,
- version_minor: 0,
- id: SENSORS_HARDWARE_MODULE_ID,
- name: "Quic Sensor module",
- author: "Quic",
- methods: &sensors_module_methods,
- dso: NULL,
- reserved: {0},
- },
- get_sensors_list: sensors__get_sensors_list,
-};
-
-struct sensors_poll_context_t {
- struct sensors_poll_device_1_ext_t device;// must be first
-
- sensors_poll_context_t();
- ~sensors_poll_context_t();
- int activate(int handle, int enabled);
- int setDelay(int handle, int64_t ns);
- int pollEvents(sensors_event_t* data, int count);
- int handleCommandPipe();
- int calibrate(int handle, cal_cmd_t *para);
-
-private:
- struct pollfd mPollFds[MAX_SENSORS+1];
-
- /** index of the command read fd in mPollFds */
- int mCmdFdReadIdx;
- /** command write fd */
- int mCmdFdWrite;
- SensorBase* mSensors[MAX_SENSORS];
-};
-
-/*****************************************************************************/
-
-sensors_poll_context_t::sensors_poll_context_t()
-{
- int numSensors;
- int i;
- const struct sensor_t *slist;
- const struct SensorContext *context;
- NativeSensorManager& sm(NativeSensorManager::getInstance());
-
- numSensors = sm.getSensorList(&slist);
- if (numSensors > MAX_SENSORS) {
- ALOGW("Native sensor manager returned too many sensors (%d), truncating list %d",
- numSensors, MAX_SENSORS);
- numSensors = MAX_SENSORS;
- }
-
- /* use the dynamic sensor list */
- for (i = 0; i < numSensors; i++) {
- context = sm.getInfoByHandle(slist[i].handle);
-
- mPollFds[i].fd = (context == NULL) ? -1 : context->data_fd;
- mPollFds[i].events = POLLIN;
- mPollFds[i].revents = 0;
- }
-
- mCmdFdReadIdx = numSensors;
- ALOGD("Command pipe fd idx: %d", mCmdFdReadIdx);
-
- int cmdFds[2];
- int result = pipe(cmdFds);
- ALOGE_IF(result<0, "error creating cmd pipe (%s)", strerror(errno));
- fcntl(cmdFds[0], F_SETFL, O_NONBLOCK);
- fcntl(cmdFds[1], F_SETFL, O_NONBLOCK);
- mCmdFdWrite = cmdFds[1];
-
- mPollFds[mCmdFdReadIdx].fd = cmdFds[0];
- mPollFds[mCmdFdReadIdx].events = POLLIN;
- mPollFds[mCmdFdReadIdx].revents = 0;
-}
-
-sensors_poll_context_t::~sensors_poll_context_t() {
- NativeSensorManager& sm(NativeSensorManager::getInstance());
- close(mPollFds[mCmdFdReadIdx].fd);
- close(mCmdFdWrite);
-}
-
-int sensors_poll_context_t::activate(int handle, int enabled) {
-
- struct sensor_command cmd;
- memset(&cmd, 0x00, sizeof(cmd));
-
- cmd.type = sensor_command::CMD_ENABLE;
- cmd.sz = sizeof(cmd);
- cmd.sensor = handle;
- cmd.enabled = enabled;
-
- ssize_t rc = write(mCmdFdWrite, &cmd, sizeof(cmd));
-
- if (rc < 0) {
- ALOGE("error writing command to pipe (%s)", strerror(errno));
- return -errno;
- }
-
- if (rc != sizeof(cmd)) {
- ALOGE("error writing command, invalid len (%zd, expect=%zd)",
- rc, sizeof(cmd));
- return -EIO;
- }
-
- return 0;
-}
-
-int sensors_poll_context_t::setDelay(int handle, int64_t ns) {
-
- struct sensor_command cmd;
- memset(&cmd, 0x00, sizeof(cmd));
-
- cmd.type = sensor_command::CMD_SET_PERIOD;
- cmd.sz = sizeof(cmd);
- cmd.sensor = handle;
- cmd.period = ns;
-
- ssize_t rc = write(mCmdFdWrite, &cmd, sizeof(cmd));
-
- if (rc < 0) {
- ALOGE("error writing command to pipe (%s)", strerror(errno));
- return -errno;
- }
-
- if (rc != sizeof(cmd)) {
- ALOGE("error writing command, invalid len (%zd, expect=%zd)",
- rc, sizeof(cmd));
- return -EIO;
- }
-
- return 0;
-}
-
-int sensors_poll_context_t::pollEvents(sensors_event_t* data, int count)
-{
- int nbEvents = 0;
- int n = 0;
- NativeSensorManager& sm(NativeSensorManager::getInstance());
- const sensor_t *slist;
- int number = sm.getSensorList(&slist);
-
- do {
- // see if we have some leftover from the last poll()
- for (int i = 0 ; count && i < number ; i++) {
- if ((mPollFds[i].revents & POLLIN) || (sm.hasPendingEvents(slist[i].handle))) {
- int nb = sm.readEvents(slist[i].handle, data, count);
- if (nb < 0) {
- ALOGE("readEvents failed.(%d)", errno);
- return nb;
- }
- if (nb <= count) {
- // no more data for this sensor
- mPollFds[i].revents = 0;
- }
- count -= nb;
- nbEvents += nb;
- data += nb;
- }
- }
-
- if (count) {
- // we still have some room, so try to see if we can get
- // some events immediately or just wait if we don't have
- // anything to return
- do {
- n = poll(mPollFds, number + 1, nbEvents ? 0 : -1);
- } while (n < 0 && errno == EINTR);
- if (n<0) {
- ALOGE("poll() failed (%s)", strerror(errno));
- return -errno;
- }
- if (mPollFds[mCmdFdReadIdx].revents & POLLIN) {
- int rc = handleCommandPipe();
- if (rc) {
- return rc;
- }
- mPollFds[mCmdFdReadIdx].revents = 0;
- }
- }
- // if we have events and space, go read them
- } while (n && count);
-
- return nbEvents;
-}
-
-static inline double ns2hz(int64_t period_ns) {
- if (period_ns == 0) {
- return 0;
- }
- return 1.0 / (period_ns * 1e-9);
-}
-
-int sensors_poll_context_t::handleCommandPipe() {
- struct sensor_command cmd;
- ssize_t rc = read(mPollFds[mCmdFdReadIdx].fd, &cmd, sizeof(cmd));
- if (rc < 0) {
- ALOGE("error reading command from pipe (%s)",
- strerror(errno));
- return -errno;
- }
-
- if (rc != sizeof(cmd)) {
- ALOGE("error reading command from pipe, invalid len read: %zd/expect %zd)",
- rc, sizeof(cmd));
- return -EIO;
- }
-
- // sanity check
- if (cmd.sz != sizeof(cmd)) {
- ALOGE("invalid command read from pipe, unxpected sz: %zu/expect %zu",
- cmd.sz, sizeof(cmd));
- return -EIO;
- }
-
- NativeSensorManager& sm(NativeSensorManager::getInstance());
- SensorContext *ctx = sm.getInfoByHandle(cmd.sensor);
- if (!ctx) {
- ALOGW("Invalid sensor handle in command pipe: %d", cmd.sensor);
- return -EIO;
- }
-
- const char * name = ctx->sensor->name;
- switch (cmd.type) {
- case sensor_command::CMD_ENABLE:
- ALOGI("%s: activate: %d", name, cmd.enabled);
- rc = sm.activate(cmd.sensor, cmd.enabled);
- break;
- case sensor_command::CMD_SET_PERIOD:
- ALOGI("%s: setDelay: %.2f Hz", name, ns2hz(cmd.period));
- rc = sm.setDelay(cmd.sensor, cmd.period);
- break;
- default:
- ALOGE("%s: invalid command id received: %d", name, cmd.type);
- return -EIO;
- }
-
- ALOGE_IF(rc, "%s: error (%d) processing command", name, rc);
- return rc;
-}
-
-int sensors_poll_context_t::calibrate(int handle, struct cal_cmd_t *para)
-{
-
- int err = -1;
- NativeSensorManager& sm(NativeSensorManager::getInstance());
-
- err = sm.calibrate(handle, para);
-
- return err;
-}
-
-/*****************************************************************************/
-
-static int poll__close(struct hw_device_t *dev)
-{
- sensors_poll_context_t *ctx = (sensors_poll_context_t *)dev;
- if (ctx) {
- delete ctx;
- }
- return 0;
-}
-
-static int poll__activate(struct sensors_poll_device_t *dev,
- int handle, int enabled) {
- sensors_poll_context_t *ctx = (sensors_poll_context_t *)dev;
- return ctx->activate(handle, enabled);
-}
-
-static int poll__setDelay(struct sensors_poll_device_t *dev,
- int handle, int64_t ns) {
- sensors_poll_context_t *ctx = (sensors_poll_context_t *)dev;
- return ctx->setDelay(handle, ns);
-}
-
-static int poll__poll(struct sensors_poll_device_t *dev,
- sensors_event_t* data, int count) {
- sensors_poll_context_t *ctx = (sensors_poll_context_t *)dev;
- return ctx->pollEvents(data, count);
-}
-
-static int poll_calibrate(struct sensors_poll_device_1_ext_t *dev,
- int handle, struct cal_cmd_t *para)
-{
- sensors_poll_context_t *ctx = (sensors_poll_context_t *)dev;
- return ctx->calibrate(handle, para);
-}
-/*****************************************************************************/
-
-/** Open a new instance of a sensor device using name */
-static int open_sensors(const struct hw_module_t* module, const char*,
- struct hw_device_t** device)
-{
- int status = -EINVAL;
- sensors_poll_context_t *dev = new sensors_poll_context_t();
-
- memset(&dev->device, 0, sizeof(sensors_poll_device_1_ext_t));
-
- dev->device.common.tag = HARDWARE_DEVICE_TAG;
- dev->device.common.version = 0;
- dev->device.common.module = const_cast<hw_module_t*>(module);
- dev->device.common.close = poll__close;
- dev->device.activate = poll__activate;
- dev->device.setDelay = poll__setDelay;
- dev->device.poll = poll__poll;
- dev->device.calibrate = poll_calibrate;
-
- *device = &dev->device.common;
- status = 0;
-
- return status;
-}
-
diff --git a/sensors/sensors.h b/sensors/sensors.h
deleted file mode 100644
index 7072479..0000000
--- a/sensors/sensors.h
+++ /dev/null
@@ -1,152 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef ANDROID_SENSORS_H
-#define ANDROID_SENSORS_H
-
-#include <stdint.h>
-#include <errno.h>
-#include <sys/cdefs.h>
-#include <sys/types.h>
-
-#include <linux/input.h>
-
-#include <hardware/hardware.h>
-#include <hardware/sensors.h>
-
-__BEGIN_DECLS
-
-/*****************************************************************************/
-
-#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
-
-#define SENSORS_ACCELERATION_HANDLE 0
-#define SENSORS_MAGNETIC_FIELD_HANDLE 1
-#define SENSORS_ORIENTATION_HANDLE 2
-#define SENSORS_LIGHT_HANDLE 3
-#define SENSORS_PROXIMITY_HANDLE 4
-#define SENSORS_GYROSCOPE_HANDLE 5
-#define SENSORS_PRESSURE_HANDLE 6
-
-#define MAX_SENSORS (20)
-#define SYSFS_MAXLEN (20)
-#define SYSFS_CLASS "/sys/class/sensors/"
-#define SYSFS_NAME "name"
-#define SYSFS_VENDOR "vendor"
-#define SYSFS_VERSION "version"
-#define SYSFS_HANDLE "handle"
-#define SYSFS_TYPE "type"
-#define SYSFS_MAXRANGE "max_range"
-#define SYSFS_RESOLUTION "resolution"
-#define SYSFS_POWER "sensor_power"
-#define SYSFS_MINDELAY "min_delay"
-#define SYSFS_ENABLE "enable"
-#define SYSFS_POLL_DELAY "poll_delay"
-#define SYSFS_CALIBRATE "calibrate"
-#define SYSFS_CAL_PARAMS "cal_params"
-
-#define COMPASS_VENDOR_AKM "AKM"
-#define COMPASS_VENDOR_ALPS "Alps"
-#define COMPASS_VENDOR_YAMAHA "Yamaha"
-#define COMPASS_VENDOR_MEMSIC "Memsic"
-#define COMPASS_VENDOR_ST "STMicro"
-#define COMPASS_VENDOR_BOSCH "Bosch"
-#define COMPASS_VENDOR_KIONIX "Kionix"
-#define COMPASS_VENDOR_INVENSENSE "Invensense"
-
-#define ACCELEROMETER_NAME "accelerometer"
-#define COMPASS_NAME "compass"
-#define ORIENTATION_NAME "orientation"
-#define GYROSCOPE_NAME "gyroscope"
-#define LIGHT_NAME "light"
-#define PRESSURE_NAME "pressure"
-#define TEMPERATURE_NAME "temperature"
-#define PROXIMITY_NAME "proximity"
-#define GRAVITY_NAME "gravity"
-#define LINEAR_ACCELERATION_NAME "liner_acceleration"
-#define ROTATION_VECTOR_NAME "rotation_vector"
-#define RELATIVE_HUMIDITY_NAME "relative_humidity"
-#define AMBIENT_TEMPERATURE_NAME "ambient_temperature"
-#define MAGNETIC_FIELD_UNCALIBRATED_NAME "magnetic_field_uncalibrated"
-#define GAME_ROTATION_VECTOR_NAME "game_rotation_vector"
-#define GYROSCOPE_UNCALIBRATED_NAME "gyroscope_uncalibrated"
-#define SIGNIFICANT_MOTION_NAME "significant_motion"
-#define STEP_COUNTER_NAME "step_counter"
-#define STEP_DETECTOR_NAME "step_detector"
-#define GEOMAGNETIC_ROTATION_VECTOR_NAME "geomagnetic_field"
-
-/* The hardware sensor type supported by HAL */
-#define SUPPORTED_SENSORS_TYPE ( \
- (1ULL << SENSOR_TYPE_ACCELEROMETER) | \
- (1ULL << SENSOR_TYPE_MAGNETIC_FIELD) | \
- (1ULL << SENSOR_TYPE_PROXIMITY) | \
- (1ULL << SENSOR_TYPE_LIGHT) | \
- (1ULL << SENSOR_TYPE_GYROSCOPE))
-
-
-/*****************************************************************************/
-/* Helper function to convert sensor type to common sensor name */
-static inline const char* type_to_name(int type)
-{
- switch (type) {
- case SENSOR_TYPE_ACCELEROMETER:
- return ACCELEROMETER_NAME;
- case SENSOR_TYPE_GEOMAGNETIC_FIELD:
- return COMPASS_NAME;
- case SENSOR_TYPE_ORIENTATION:
- return ORIENTATION_NAME;
- case SENSOR_TYPE_GYROSCOPE:
- return GYROSCOPE_NAME;
- case SENSOR_TYPE_LIGHT:
- return LIGHT_NAME;
- case SENSOR_TYPE_PRESSURE:
- return PRESSURE_NAME;
- case SENSOR_TYPE_TEMPERATURE:
- return TEMPERATURE_NAME;
- case SENSOR_TYPE_PROXIMITY:
- return PROXIMITY_NAME;
- case SENSOR_TYPE_GRAVITY:
- return GRAVITY_NAME;
- case SENSOR_TYPE_LINEAR_ACCELERATION:
- return LINEAR_ACCELERATION_NAME;
- case SENSOR_TYPE_ROTATION_VECTOR:
- return ROTATION_VECTOR_NAME;
- case SENSOR_TYPE_RELATIVE_HUMIDITY:
- return RELATIVE_HUMIDITY_NAME;
- case SENSOR_TYPE_AMBIENT_TEMPERATURE:
- return AMBIENT_TEMPERATURE_NAME;
- case SENSOR_TYPE_MAGNETIC_FIELD_UNCALIBRATED:
- return MAGNETIC_FIELD_UNCALIBRATED_NAME;
- case SENSOR_TYPE_GAME_ROTATION_VECTOR:
- return GAME_ROTATION_VECTOR_NAME;
- case SENSOR_TYPE_GYROSCOPE_UNCALIBRATED:
- return GYROSCOPE_UNCALIBRATED_NAME;
- case SENSOR_TYPE_SIGNIFICANT_MOTION:
- return SIGNIFICANT_MOTION_NAME;
- case SENSOR_TYPE_STEP_DETECTOR:
- return STEP_DETECTOR_NAME;
- case SENSOR_TYPE_STEP_COUNTER:
- return STEP_COUNTER_NAME;
- case SENSOR_TYPE_GEOMAGNETIC_ROTATION_VECTOR:
- return GEOMAGNETIC_ROTATION_VECTOR_NAME;
- default:
- return "";
- }
-}
-
-__END_DECLS
-
-#endif // ANDROID_SENSORS_H
diff --git a/sensors/sensors_XML.cpp b/sensors/sensors_XML.cpp
deleted file mode 100644
index 24eae58..0000000
--- a/sensors/sensors_XML.cpp
+++ /dev/null
@@ -1,246 +0,0 @@
-/*--------------------------------------------------------------------------
-Copyright (c) 2014, The Linux Foundation. All rights reserved.
-
-Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions are
-met:
- * Redistributions of source code must retain the above copyright
- notice, this list of conditions and the following disclaimer.
- * Redistributions in binary form must reproduce the above
- copyright notice, this list of conditions and the following
- disclaimer in the documentation and/or other materials provided
- with the distribution.
- * Neither the name of The Linux Foundation nor the names of its
- contributors may be used to endorse or promote products derived
- from this software without specific prior written permission.
-
-THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
-WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
-MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
-ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
-BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
-CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
-SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
-BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
-OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
-IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
---------------------------------------------------------------------------*/
-
-#include <sensors_extension.h>
-#include "sensors_XML.h"
-#include <cutils/log.h>
-#include "unistd.h"
-
-#define SENSOR_XML_ROOT_ELEMENT "sensors"
-
-ANDROID_SINGLETON_STATIC_INSTANCE(sensors_XML);
-const static char *filepath[] = {
- "/persist/sensors_calibration_params.xml",
- "/data/sensors_calibration_param.xml"
-};
-
-char *sensor_param[] = {"offset_x", "offset_y", "offset_z", "threshold_h", "threshold_l", "bias"};
-sensors_XML :: sensors_XML()
- : mdoc(NULL)
-{
-}
-
-int sensors_XML :: write_sensors_params(struct sensor_t *sensor, struct cal_result_t *cal_result)
-{
- xmlNodePtr rootNode, curNode, newNode;
- xmlAttrPtr value;
- bool newcreate = false;
- char string[33];
- int i = 0, j, MAX = 0;
- if (cal_result == NULL) {
- ALOGE("Null pointer parameter\n");
- return -1;
- }
- if (!access(filepath[0], F_OK)) {
- mdoc = xmlReadFile(filepath[0], "UTF-8" , XML_PARSE_NOBLANKS);
- if (mdoc == NULL) {
- ALOGE("read calibration file error\n");
- return -EINVAL;
- }
- } else {
- mdoc = xmlNewDoc(BAD_CAST "1.0");
- if (mdoc == NULL) {
- ALOGE("create sensor calibration file error\n");
- return -EINVAL;
- }
- newcreate = true;
- }
- if(newcreate) {
- rootNode = xmlNewNode(NULL, BAD_CAST SENSOR_XML_ROOT_ELEMENT);
- xmlDocSetRootElement(mdoc, rootNode);
- curNode = xmlNewNode(NULL, BAD_CAST "sensor");
- xmlAddChild(rootNode, curNode);
- xmlNewProp(curNode, BAD_CAST "name", BAD_CAST sensor->name);
- } else {
- rootNode = xmlDocGetRootElement(mdoc);
- if (rootNode == NULL) {
- ALOGE("empty document\n");
- xmlFreeDoc(mdoc);
- }
-
- if (xmlStrcmp(rootNode->name, BAD_CAST SENSOR_XML_ROOT_ELEMENT)) {
- ALOGE("root node != sensors\n");
- xmlFreeDoc(mdoc);
- }
- curNode = rootNode->xmlChildrenNode;
- while(curNode != NULL) {
- if (!xmlStrcmp(xmlGetProp(curNode, BAD_CAST "name"), BAD_CAST sensor->name))
- break;
- curNode = curNode->next;
- }
- }
- switch(sensor->type) {
- case SENSOR_TYPE_ACCELEROMETER:
- i = 0;
- MAX = 3;
- break;
- case SENSOR_TYPE_PROXIMITY:
- i = 3;
- MAX = 6;
- break;
- case SENSOR_TYPE_LIGHT:
- case SENSOR_TYPE_MAGNETIC_FIELD:
- case SENSOR_TYPE_PRESSURE:
- case SENSOR_TYPE_TEMPERATURE:
- case SENSOR_TYPE_GYROSCOPE:
- default:
- break;
- }
- if (newcreate) {
- for(j = 0; i < MAX; i++, j++) {
- snprintf(string, sizeof(string), "%d", cal_result->offset[j]);
- xmlNewProp(curNode, BAD_CAST sensor_param[i], BAD_CAST string);
- }
- } else {
- if(curNode == NULL) {
- curNode = xmlNewNode(NULL, BAD_CAST "sensor");
- xmlAddChild(rootNode, curNode);
- value = xmlNewProp(curNode, BAD_CAST "name", BAD_CAST sensor->name);
- if (value == NULL) {
- ALOGE("\nname is NULL\n");
- }
- for(j = 0; i < MAX; i++, j++) {
- snprintf(string, sizeof(string), "%d", cal_result->offset[j]);
- xmlNewProp(curNode, BAD_CAST sensor_param[i], BAD_CAST string);
- }
- } else {
- for(j = 0; i < MAX; i++, j++) {
- snprintf(string, sizeof(string), "%d", cal_result->offset[j]);
- xmlSetProp(curNode, BAD_CAST sensor_param[i], BAD_CAST string);
- }
- }
- }
- xmlSaveFormatFileEnc(filepath[0], mdoc, "UTF-8", 1);
- xmlFreeDoc(mdoc);
- return 0;
-}
-
-int sensors_XML :: read_sensors_params(struct sensor_t *sensor, struct cal_result_t *cal_result)
-{
- xmlNodePtr rootNode, curNode;
- int i = 0, j, MAX = 0;
- if (cal_result == NULL) {
- ALOGE("Null pointer parameter\n");
- return -1;
- }
- if(!access(filepath[1], R_OK)) {
- mdoc = xmlReadFile(filepath[1], "UTF-8" , XML_PARSE_RECOVER);
- } else if (!access(filepath[0], F_OK)){
- char buf[200];
- snprintf(buf, sizeof(buf), "cp %s %s", filepath[0], filepath[1]);
- system(buf);
- if (!access(filepath[1], R_OK)) {
- mdoc = xmlReadFile(filepath[1], "UTF-8" , XML_PARSE_RECOVER);
- } else {
- ALOGE("file can't read\n");
- return -1;
- }
- } else {
- ALOGE("file can't read\n");
- return -1;
- }
- rootNode = xmlDocGetRootElement(mdoc);
- if (rootNode == NULL) {
- ALOGE("empty document\n");
- xmlFreeDoc(mdoc);
- return -1;
- }
-
- if (xmlStrcmp(rootNode->name, BAD_CAST SENSOR_XML_ROOT_ELEMENT)) {
- ALOGE("root node != sensors\n");
- xmlFreeDoc(mdoc);
- return -1;
- }
- curNode = rootNode->xmlChildrenNode;
- while(curNode != NULL) {
- if (!xmlStrcmp(xmlGetProp(curNode, BAD_CAST "name"), BAD_CAST sensor->name))
- break;
- curNode = curNode->next;
- }
- switch(sensor->type) {
- case SENSOR_TYPE_ACCELEROMETER:
- i = 0;
- MAX = 3;
- break;
- case SENSOR_TYPE_PROXIMITY:
- i = 3;
- MAX = 6;
- break;
- case SENSOR_TYPE_LIGHT:
- case SENSOR_TYPE_MAGNETIC_FIELD:
- case SENSOR_TYPE_PRESSURE:
- case SENSOR_TYPE_TEMPERATURE:
- case SENSOR_TYPE_GYROSCOPE:
- default:
- break;
- }
- if (curNode != NULL) {
- xmlChar* value;
- for(j = 0; i < MAX; ++i, ++j) {
- value = xmlGetProp(curNode, BAD_CAST sensor_param[i]);
- cal_result->offset[j] = atoi((char*)value);
- }
- } else {
- for(j = 0; j < 3; ++j) {
- cal_result->offset[j] = 0;
- }
- ALOGE("The sensor calibrate parameters is not found\n");
- }
- xmlFreeDoc(mdoc);
- return 0;
-}
-
-int sensors_XML :: sensors_calibrate_reset()
-{
- int i;
- for(i=0; i < 2; ++i) {
- if (access(filepath[i], F_OK)) {
- ALOGE("file is not exits\n");
- return -1;
- }
- if (remove(filepath[i])) {
- ALOGE("reset calibrate error\n");
- return -1;
- }
- }
- return 0;
-}
-
-int sensors_XML :: sensors_rm_file()
-{
-
- if (access(filepath[1], F_OK)) {
- return 0;
- }
- if (remove(filepath[1])) {
- ALOGE("reset calibrate error\n");
- return -1;
- }
- return 0;
-}
diff --git a/sensors/sensors_XML.h b/sensors/sensors_XML.h
deleted file mode 100644
index d9ab5e8..0000000
--- a/sensors/sensors_XML.h
+++ /dev/null
@@ -1,51 +0,0 @@
-/*--------------------------------------------------------------------------
-Copyright (c) 2014, The Linux Foundation. All rights reserved.
-
-Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions are
-met:
- * Redistributions of source code must retain the above copyright
- notice, this list of conditions and the following disclaimer.
- * Redistributions in binary form must reproduce the above
- copyright notice, this list of conditions and the following
- disclaimer in the documentation and/or other materials provided
- with the distribution.
- * Neither the name of The Linux Foundation nor the names of its
- contributors may be used to endorse or promote products derived
- from this software without specific prior written permission.
-
-THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
-WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
-MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
-ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
-BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
-CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
-SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
-BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
-OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
-IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
---------------------------------------------------------------------------*/
-
-#ifndef SENSOR_XML_H
-#define SENSOR_XML_H
-
-#include <sensors_extension.h>
-#include <libxml/parser.h>
-#include <libxml/tree.h>
-#include <utils/Singleton.h>
-
-using namespace android;
-
-class sensors_XML : public Singleton<sensors_XML> {
- friend class Singleton<sensors_XML>;
- xmlDocPtr mdoc;
-public:
- int read_sensors_params(struct sensor_t *sensor, struct cal_result_t *cal_result);
- int write_sensors_params(struct sensor_t *sensor, struct cal_result_t *cal_result);
- sensors_XML();
- int sensors_calibrate_reset();
- int sensors_rm_file();
-};
-
-#endif
diff --git a/sensors/sensors_extension.h b/sensors/sensors_extension.h
deleted file mode 100644
index 47a0f65..0000000
--- a/sensors/sensors_extension.h
+++ /dev/null
@@ -1,173 +0,0 @@
-/*--------------------------------------------------------------------------
-Copyright (c) 2014, The Linux Foundation. All rights reserved.
-
-Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions are
-met:
- * Redistributions of source code must retain the above copyright
- notice, this list of conditions and the following disclaimer.
- * Redistributions in binary form must reproduce the above
- copyright notice, this list of conditions and the following
- disclaimer in the documentation and/or other materials provided
- with the distribution.
- * Neither the name of The Linux Foundation nor the names of its
- contributors may be used to endorse or promote products derived
- from this software without specific prior written permission.
-
-THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
-WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
-MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
-ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
-BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
-CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
-SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
-BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
-OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
-IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
---------------------------------------------------------------------------*/
-
-#ifndef SENSORS_EXTENTION_H
-#define SENSORS_EXTENTION_H
-
-#include <hardware/sensors.h>
-#include <hardware/hardware.h>
-
-#define CMD_W_L_MASK 0x00
-#define CMD_W_H_MASK 0x10
-#define CMD_W_H_L 0x10
-#define DATA_H_MASK 0xFFFF0000
-#define DATA_L_MASK 0x0000FFFF
-
-/*
- *sensor calibrate command for sensors axis threshold or factor
- *AXIS_X,AXIS_Y,AXIS_Z,AXIS_XYZ used like accelerometer,magnetometer
- *gyroscope etc.AXIS_THRESHOLD_H AXIS,THRESHOLD_L is used to calibrate
- *proximity threshold,AXIS_BIAS calibrate the noise of proximity sensor.
- *AXIS_FACTOR is used to calibrate light sensor fatcor of the real data
- *AXIS_OFFSET is used to calibrate light sensor offset of the real data
- */
-#define AXIS_X 0
-#define AXIS_Y 1
-#define AXIS_Z 2
-#define AXIS_XYZ 3
-
-#define AXIS_THRESHOLD_H 0
-#define AXIS_THRESHOLD_L 1
-#define AXIS_BIAS 2
-
-#define AXIS_FACTOR 0
-#define AXIS_OFFSET 1
-
-#define AXIS_SHIFT 17
-#define SAVE_SHIFT 16
-#define CMD_SHIFT 16
-
-#define LENGTH 33 /*one cal_result and separator length*/
-__BEGIN_DECLS
-
-
-/*
- *CMD_DO_CAL when do sensor calibrate must use this
- *AXIS_X,AXIS_Y,AXIS_Z write axis params to driver like accelerometer
- *magnetometer,gyroscope etc.CMD_W_THRESHOLD_H,CMD_W_THRESHOLD_L,CMD_W_BIAS
- *write theshold and bias params to proximity driver.CMD_W_FACTOR,CMD_W_OFFSET
- *write factor and offset params to light sensor driver.
- */
-enum {
- CMD_DO_CAL = 0x0,
- CMD_W_OFFSET_X,
- CMD_W_OFFSET_Y,
- CMD_W_OFFSET_Z,
- CMD_W_THRESHOLD_H,
- CMD_W_THRESHOLD_L,
- CMD_W_BIAS,
- CMD_W_OFFSET,
- CMD_W_FACTOR,
- CMD_W_RANGE,
- CMD_COMPLETE,
- CMD_COUNT
-};
-
-/*
- *macro SET_CMD_H() write sensors params high 16 bits.
- *SET_CMD_L() write sensors params low 16 bits.
- *CMD_CAL()calibrate command
- */
-#define SET_CMD_H(param, CMDS) \
- (((param) & DATA_H_MASK) | CMDS \
- | (CMD_W_H_L & CMD_W_H_MASK))
-
-#define SET_CMD_L(param, CMDS) \
- (((param) & DATA_L_MASK) << CMD_SHIFT | CMDS \
- | (CMD_W_H_L & CMD_W_L_MASK))
-
-#define CMD_CAL(axis, apply_now) \
- ((axis) << AXIS_SHIFT | (apply_now)<< SAVE_SHIFT | CMD_DO_CAL)
-
-struct cal_cmd_t{
- int axis; /* The axis to calibrate */
- bool save; /* Whether to write to config file */
- bool apply_now; /* Whether to apply the calibration parameters now */
-};
-
-struct sensors_poll_device_1_ext_t {
- union {
-
- struct sensors_poll_device_1 aosp;
- struct {
- struct hw_device_t common;
- int (*activate)(struct sensors_poll_device_t *dev,
- int handle, int enabled);
- int (*setDelay)(struct sensors_poll_device_t *dev,
- int handle, int64_t period_ns);
- int (*poll)(struct sensors_poll_device_t *dev,
- sensors_event_t* data, int count);
- int (*batch)(struct sensors_poll_device_1* dev,
- int handle, int flags, int64_t period_ns, int64_t timeout);
- int (*flush)(struct sensors_poll_device_1* dev, int handle);
- void (*reserved_procs[8])(void);
- };
- };
-
- /* return -1 on error. Otherwise return the calibration result */
- int (*calibrate)(struct sensors_poll_device_1_ext_t *dev,
- int handle, struct cal_cmd_t *para);
-};
-
-struct cal_result_t {
- union{
-
- struct {
- int offset_x; /*axis offset of x axis*/
- int offset_y; /*axis offset of x axis*/
- int offset_z; /*axis offset of x axis*/
- };
- struct {
- int threshold_h; /*proximity threshold_h*/
- int threshold_l; /*proximity threshold_l*/
- int bias; /*proximity measure data noise*/
- };
- int offset[3];
- };
- int factor; /*light sensor factor for real ligt strength*/
- int range;
- int *node;
-};
-
-static inline int sensors_open_ext(const struct hw_module_t* module,
- struct sensors_poll_device_1_ext_t** device)
-{
- return module->methods->open(module,
- SENSORS_HARDWARE_POLL, (struct hw_device_t**)device);
-}
-
-static inline int sensors_close_ext(struct sensors_poll_device_1_ext_t* device)
-{
- return device->common.close(&device->common);
-}
-
-__END_DECLS
-#endif
-
-