Sensors for the pinephone
- 
 Draft: Sensors for the pinephone with the sensors stk3310, mpu6050 and lis3mdl. 
 Please note that not all the pinephone starting from 2021 have the lis3mdl sensor.
 This topic tries to give all the information you need if you want to work on the pinephone sensors.
 Please note that in the worst case, your pinephone could crash and you need to reinstall the os on your phone and the data will be lost. Therefore use a separate sd card for development.Using the sensors in combination with bash to get information: 
 cat /sys/bus/iio/devices/iio\:device3/name
 This gives the result: lis3mdl
 To set the sensor properties in bash you have to be root, hence:
 sudo -i
 echo 2 > /sys/bus/iio/devices/iio\:device3/sampling_frequency
 This will set the sampling frequency to 2 Hz.Sensorfw is started and stopped with upstart. 
 Restarting the service could be done with:
 sudo service sensorfw restartThe log of sensorfw is given in /var/log/upstart/sensorfw.log 
 To remove the log before you restart it:
 sudo rm /var/log/upstart/sensorfw.log*Reading the log can be done with you favorite command line reader: 
 sudo cat /var/log/upstart/sensorfw.logLocation of the sensorfw upstart file: 
 /etc/init/sensorfw.conf
 To make the output more verbose, switch from--log-level=warningto--log-level=test.
 See below.description "Sensorfw Services" start on started dbus respawn exec /usr/sbin/sensorfwd --device-info --log-level=test --no-magnetometer-bg-calibrationLocation configuration file: 
 /etc/deviceinfo/sensorfw/pinephone.conf
 If the configuration file is updating correctly after a change in the file is not completely known. Investigation point.[plugins] accelerometeradaptor = iiosensorsadaptor orientationadaptor = iiosensorsadaptor alsadaptor = iiosensorsadaptor magnetometeradaptor = iiosensorsadaptor gyroscopeadaptor = iiosensorsadaptor proximityadaptor = iiosensorsadaptor [accelerometer] input_match=mpu6050 default_interval=500 transformation_matrix = "0,1,0,-1,0,0,0,0,-1" [als] input_match=stk3310 intervals = "200=>2000" default_interval=500 [gyroscope] input_match=mpu6050 default_interval=500 transformation_matrix = "0,1,0,-1,0,0,0,0,-1" [magnetometer] input_match=lis3mdl intervals = "12.5,25,50,100,200,333.3,500,1000" default_interval=500 #scale_coefficient = 1 needs_calibration = 1 #dataranges = "-4096=>4096" #interval_compensation = 16 ???? calibration_rate = 12.5 calibration_timeout = 60000 [proximity] input_match=stk3310 intervals = "200=>2000" default_interval=500 threshold=19Using crossbuilder: 
 clone the git repository of you project which you would like to build
 git clone https://github.com/wouter182/sensorfw.git
 Go into the project directory
 cd sensorfwEdited: 
 Build the package
 crossbuilder --architecture=arm64 build
 Create the deb package and deploy it on the pinephone
 crossbuilder --architecture=arm64 --ssh=<Your IP> deploy
 Please make sure that you prevent the automatic lock of the home screen. This prevents the phone going into sleep. If the phone is in sleep mode, the wifi connection is not stable anymore (this to reduce energy consumption).Restart sensorfw or reboot the phone and check your work (not completely sure if this works correct with loading of the sensorfw config file) For building the SensorStatus app: 
 Clone the sensorstatus repo from wouter182.
 git clone https://gitlab.com/wouter182/SensorsStatus.git
 Go inside the sensorstatus folder
 cd SensorsStatus
 and runclickable --ssh <Your IP>, this will generate the app in click format and will start it automatically.
 Withclickable log --ssh <Your IP>you can check the log files from the app. In case of a crash or to check for errors.Setting up ssh on the pinephone: 
 https://docs.ubports.com/en/latest/userguide/advanceduse/ssh.htmlSetting up crossbuilder: 
 Download the crossbuilder script:
 git clone https://github.com/wouter182/crossbuilder
 For further instruction see https://docs.ubports.com/en/latest/systemdev/testing-locally.htmlRead only rootfs: 
 Usesudo mount / -o remount,rwto make the rootfs temporary read and writable.
 Note that after an system upgrade, the changed files will be overwritten.Testing a merge request: 
 Testing a merge request can be done with ubports-qa, see https://docs.ubports.com/en/latest/systemdev/uploading-changes.htmlSetting up clickable: 
 See https://clickable-ut.dev/en/latest/install.htmlLinks with the information you probably need. 
 Crossbuilder in combination with ssh and automatic delploy:
 https://github.com/ubports/crossbuilder/pull/53
 Sensorfw for the pinephone:
 https://github.com/ubports/sensorfw/tree/xenial_-_edge
 https://github.com/ubports/sensorfw/pull/4
 Please take note that the pinpehone uses the xenial_-_edge repository at the moment.
 See https://gitlab.com/ubports/core/rootfs-builder-debos/-/blob/master/scripts/add-mainline-repos.sh#L23Configuration file for sensorfw from deviceinfo: 
 https://gitlab.com/ubports/core/deviceinfo/-/blob/main/configs/sensorfw/pinephone.confSensorfw plugin in Qt: 
 https://code.qt.io/cgit/qt/qtsensors.git/tree/src/plugins/sensors/sensorfw?h=5.12SensorStatus app: 
 https://gitlab.com/wouter182/SensorsStatus
 SensorStatus app in the open store:
 https://gitlab.com/balcy/SensorsStatusBackground information: 
 Information about the iio (industrial input and output) sensors in combination with linux:
 https://www.kernel.org/doc/Documentation/ABI/testing/sysfs-bus-iio
 Magnetometer driver in linux for reference:
 https://gitlab.com/pine64-org/linux/-/tree/pine64-kernel-ubports-5.10.y-megi/drivers/iio/magnetometer
 Upstream sensorfw if you liked the gitlab search function like me:
 https://git.sailfishos.org/mer-core/sensorfw
 https://github.com/sailfishos/sensorfw
 QML information for sensors:
 https://doc.qt.io/qt-5.12/qtsensors-index.htmlTo be continued... 
- 
 Hi Wouter, Thanks for the detailed instructions. I was able to succesfully build Sensorstatus with clickable and deploy it via ssh. I cannot say the same about sensorfw and crossbuilder though. I can build and generate the deb files with 
 crossbuilder --architecture=arm64
 but if I attempt to deploy them with the--ssh=argument it fails. It asks for the ssh password several times at the beginning, then it builds everything, and it will ask for the password again at the end, several times. Always fails to accept it.I have also tried to set up my ssh keys first. This prevents the password prompts, giving instead a wrong password error automatically at the end of the build process. Any ideas? If not, perhaps I can instead deploy the deb files manually... 
- 
 Hi @lgtrombetta 
 The recommended way is to use click packages and not .deb
 The easiest way is to use clickable which will help to deploy it to the phone.BTW the password for SSH is not enabled, setting the key was the right thing to do. 
 But the error is strange ?! ?!
- 
 Hi @applee 
 The deb packages are the recommended way for the middleware. Sensorfw is the software which connects the linux drivers of the sensors to Qt and does the calibration.
 In this way all apps which use Qt could make use of the sensors.
 For the SensorsStatus app clickable is the way to go.

