termux / termux/termux-api

Duplicate Sensor Values with SensorAPI

Open
#289 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Java
Stars
4.3k
Forks
920
PR merge metrics
No merged PRs in 30d

Description

Problem description
When subscribing to continuous sensor updates, SensorOutputWriter sleeps for a fixed amount of time, then sends out the most recent sensor data. This sensor data may be exactly the same as was sent out previously.

Steps to reproduce

$ termux-sensor -s Pressure -d 10
{
  "BMP280 Pressure": {
    "values": [
      1004.2263793945312,
      0,
      0
    ]
  }
}
{
  "BMP280 Pressure": {
    "values": [
      1004.2263793945312,
      0,
      0
    ]
  }
}
{
  "BMP280 Pressure": {
    "values": [
      1004.2263793945312,
      0,
      0
    ]
  }
}
{
  "BMP280 Pressure": {
    "values": [
      1004.230224609375,
      0,
      0
    ]
  }
}
{
  "BMP280 Pressure": {
    "values": [
      1004.230224609375,
      0,
      0
    ]
  }
}
{
  "BMP280 Pressure": {
    "values": [
      1004.230224609375,
      0,
      0
    ]
  }
}

Notice the duplicate values.

Expected behavior
No duplicate values.

I'm not sure what the intention was with the -d flag.

Android allows you to configure a sensor's update rate, and it notifies you when a sensor's value changes.

I think SensorAPI should:

  • Allow the user to set a sensor's update rate
  • Print a new sensor value whenever Android notifies SensorAPI that a sensor's value has changed

I think this would be a much more useful behavior. I'm currently trying to automate logging of sensor values, and I want to squeeze the maximum performance out of my device's sensors. However, the updates termux-sensors produces are not in-sync with the actual sensor updates.

Additional information

$ termux-info
Updatable packages:
All packages up to date
Subscribed repositories:
https://dl.bintray.com/xeffyr/x11-packages-24 x11/main
https://dl.bintray.com/xeffyr/unstable-packages-24 unstable/main
https://dl.bintray.com/grimler/science-packages-24 science/stable
https://dl.bintray.com/grimler/termux-root-packages-24 root/stable
https://dl.bintray.com/grimler/game-packages-24 games/stable
https://dl.bintray.com/termux/termux-packages-24 stable/main
System information:
Linux localhost 3.18.31-10376601-eng #1 SMP PREEMPT Thu Feb 2 19:51:12 KST 2017 aarch64 Android
Termux-packages arch:
aarch64
Android version:
7.0
Device manufacturer:
samsung
Device model:
SM-G930V

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with SensorOutputWriter and the SensorAPI behavior exercised by termux-sensor -s Pressure -d 10; trace how the fixed delay selects and emits sensor data. Compare that flow with Android's sensor update notifications and define completion as no repeated values while preserving the requested update-rate behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
api, mobile
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.