Skip to content

Commit 210b3a2

Browse files
committedApr 27, 2014
update readme, release wakelock, check for non triggering values betwee triggers
1 parent 36d37d7 commit 210b3a2

File tree

2 files changed

+22
-14
lines changed

2 files changed

+22
-14
lines changed
 

Diff for: ‎README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,13 @@ And the manifest needs to contain:
6161
* complete sensor listing and data visualisation
6262
* add grahps for data view
6363
* communicate sensor readings from service to configuration fragment
64-
* add check for threshold values, should go beyond threshold before triggering again
6564

6665
## Version History
6766

68-
### Upcoming 0.1.1
67+
### 0.1.1 (Upcoming)
6968

70-
* update on deprecated wakelock options, using the methods referenced at http://developer.android.com/reference/android/os/PowerManager.html form now on.
69+
* release wake lock directly after acquiring it now
70+
* check for non triggering values between triggers
7171

7272
### 0.1.0
7373

Diff for: ‎app/src/main/java/be/hcpl/android/sensors/service/SensorBackgroundService.java

+19-11
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ public class SensorBackgroundService extends Service implements SensorEventListe
3434
private boolean mLogging = false;
3535

3636
/**
37-
* an interval for the sensor value reading;
37+
* also keep track of the previous value
3838
*/
39-
private long mInterval;
39+
private static float previousValue;
4040

4141
/**
4242
* treshold values
@@ -117,7 +117,7 @@ public void onSensorChanged(SensorEvent event) {
117117
for (float value : event.values)
118118
sb.append(String.valueOf(value)).append(" | ");
119119

120-
Log.d(TAG, "received sensor valures are: " + sb.toString());
120+
Log.d(TAG, "received sensor valures are: " + sb.toString()+ " and previosValue was: "+previousValue);
121121
}
122122

123123
// get the value
@@ -126,25 +126,33 @@ public void onSensorChanged(SensorEvent event) {
126126

127127
// if first value is below min or above max threshold but only when configured
128128
// we need to enable the screen
129-
if (sensorValue < mThresholdMin || sensorValue > mThresholdMax) {
129+
if ((previousValue > mThresholdMin && sensorValue < mThresholdMin)
130+
|| (previousValue < mThresholdMax && sensorValue > mThresholdMax)) {
130131

131132
// and a check in between that there should have been a non triggering value before
132133
// we can mark a given value as trigger. This is to overcome unneeded wakeups during
133134
// night for instance where the sensor readings for a light sensor would always be below
134135
// the threshold needed for day time use.
135136

136-
137137
// TODO we could even make the actions configurable...
138138

139139
// wake screen here
140-
PowerManager pm = (PowerManager) getSystemService(getApplicationContext().POWER_SERVICE);
141-
PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK, TAG);
142-
wl.acquire();
143-
//..screen will stay on during this section..
144-
wl.release();
140+
PowerManager pm = (PowerManager) getApplicationContext().getSystemService(getApplicationContext().POWER_SERVICE);
141+
PowerManager.WakeLock wakeLock = pm.newWakeLock((PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP), TAG);
142+
wakeLock.acquire();
143+
144+
//and release again
145+
wakeLock.release();
146+
147+
// optional to release screen lock
148+
//KeyguardManager keyguardManager = (KeyguardManager) getApplicationContext().getSystemService(getApplicationContext().KEYGUARD_SERVICE);
149+
//KeyguardManager.KeyguardLock keyguardLock = keyguardManager.newKeyguardLock(TAG);
150+
//keyguardLock.disableKeyguard();
145151
}
146152

147-
// stop the sensor and service
153+
previousValue = sensorValue;
154+
155+
// stop the sensor and service
148156
mSensorManager.unregisterListener(this);
149157
stopSelf();
150158
}

0 commit comments

Comments
 (0)