Skip to content

Commit 12f387c

Browse files
committed
Add support for Air Pressure sensor module
1 parent b0b710c commit 12f387c

File tree

8 files changed

+121
-3
lines changed

8 files changed

+121
-3
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
# Changelog
22

33
### Next
4-
- Added support for Humidity sensor module.
4+
- Added support for Air Pressure sensor module
5+
- Added support for Humidity sensor module
56
- Updated Google Play Services to 7.8.0
67
- Added support for Android Studio 1.3.1
78
- Updated gradle to 1.3.0

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ The following sensor modules are currently supported in SensingKit-Android, (lis
2525
- Audio Level
2626
- Bluetooth
2727
- Humidity
28+
- Air Pressure
2829

2930
## Configuring the Library
3031

SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/SKSensorModuleManager.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public class SKSensorModuleManager {
3333
@SuppressWarnings("unused")
3434
private static final String TAG = "SKSensorModuleManager";
3535

36-
private static final int TOTAL_SENSOR_MODULES = 18;
36+
private static final int TOTAL_SENSOR_MODULES = 19;
3737

3838
private static SKSensorModuleManager sSensorModuleManager;
3939
private final Context mApplicationContext;
@@ -198,6 +198,10 @@ protected SKAbstractSensorModule createSensorModule(SKSensorModuleType moduleTyp
198198
sensorModule = new SKHumidity(mApplicationContext);
199199
break;
200200

201+
case AIR_PRESSURE:
202+
sensorModule = new SKAirPressure(mApplicationContext);
203+
break;
204+
201205
// Don't forget the break; here
202206

203207
default:

SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/SKSensorModuleType.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,6 @@ public enum SKSensorModuleType {
3939
AUDIO_RECORDER,
4040
AUDIO_LEVEL,
4141
BLUETOOTH,
42-
HUMIDITY
42+
HUMIDITY,
43+
AIR_PRESSURE
4344
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* Copyright (c) 2015. Queen Mary University of London
3+
* Kleomenis Katevas, k.katevas@qmul.ac.uk
4+
*
5+
* This file is part of SensingKit-Android library.
6+
* For more information, please visit http://www.sensingkit.org
7+
*
8+
* SensingKit-Android is free software: you can redistribute it and/or modify
9+
* it under the terms of the GNU Lesser General Public License as published by
10+
* the Free Software Foundation, either version 3 of the License, or
11+
* (at your option) any later version.
12+
*
13+
* SensingKit-Android is distributed in the hope that it will be useful,
14+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
* GNU Lesser General Public License for more details.
17+
*
18+
* You should have received a copy of the GNU Lesser General Public License
19+
* along with SensingKit-Android. If not, see <http://www.gnu.org/licenses/>.
20+
*/
21+
22+
package org.sensingkit.sensingkitlib.data;
23+
24+
import org.sensingkit.sensingkitlib.SKSensorModuleType;
25+
26+
import java.util.Locale;
27+
28+
public class SKAirPressureData extends SKAbstractData {
29+
30+
@SuppressWarnings("unused")
31+
private static final String TAG = "SKAirPressureData";
32+
33+
protected final float pressure;
34+
35+
public SKAirPressureData(long timestamp, float pressure) {
36+
37+
super(SKSensorModuleType.AIR_PRESSURE, timestamp);
38+
39+
this.pressure = pressure;
40+
}
41+
42+
@Override
43+
public String getDataInCSV() {
44+
return String.format(Locale.US, "%d,%f", this.timestamp, this.pressure);
45+
}
46+
47+
@SuppressWarnings("unused")
48+
public float getLight() {
49+
return this.pressure;
50+
}
51+
52+
}

SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/modules/SKAbstractNativeSensorModule.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,9 @@ private static int getSensorType(SKSensorModuleType sensorType) throws SKExcepti
142142
case HUMIDITY:
143143
return Sensor.TYPE_RELATIVE_HUMIDITY;
144144

145+
case AIR_PRESSURE:
146+
return Sensor.TYPE_PRESSURE;
147+
145148
case LOCATION:
146149
case ACTIVITY:
147150
case BATTERY:
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
* Copyright (c) 2015. Queen Mary University of London
3+
* Kleomenis Katevas, k.katevas@qmul.ac.uk
4+
*
5+
* This file is part of SensingKit-Android library.
6+
* For more information, please visit http://www.sensingkit.org
7+
*
8+
* SensingKit-Android is free software: you can redistribute it and/or modify
9+
* it under the terms of the GNU Lesser General Public License as published by
10+
* the Free Software Foundation, either version 3 of the License, or
11+
* (at your option) any later version.
12+
*
13+
* SensingKit-Android is distributed in the hope that it will be useful,
14+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
* GNU Lesser General Public License for more details.
17+
*
18+
* You should have received a copy of the GNU Lesser General Public License
19+
* along with SensingKit-Android. If not, see <http://www.gnu.org/licenses/>.
20+
*/
21+
22+
package org.sensingkit.sensingkitlib.modules;
23+
24+
import android.content.Context;
25+
import android.hardware.SensorEvent;
26+
27+
import org.sensingkit.sensingkitlib.SKException;
28+
import org.sensingkit.sensingkitlib.SKSensorModuleType;
29+
import org.sensingkit.sensingkitlib.data.SKAbstractData;
30+
import org.sensingkit.sensingkitlib.data.SKAirPressureData;
31+
32+
public class SKAirPressure extends SKAbstractNativeSensorModule {
33+
34+
@SuppressWarnings("unused")
35+
private static final String TAG = "SKAirPressure";
36+
37+
public SKAirPressure(final Context context) throws SKException {
38+
super(context, SKSensorModuleType.AIR_PRESSURE);
39+
}
40+
41+
@Override
42+
protected SKAbstractData buildData(SensorEvent event)
43+
{
44+
return new SKAirPressureData(System.currentTimeMillis(), event.values[0]);
45+
}
46+
47+
@Override
48+
protected boolean shouldPostSensorData(SKAbstractData data) {
49+
50+
// Always post sensor data
51+
return true;
52+
}
53+
}

SensingKitLib/src/main/java/org/sensingkit/sensingkitlib/modules/SKSensorModuleUtilities.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,9 @@ public static String getSensorModuleInString(SKSensorModuleType moduleType) thro
8888
case HUMIDITY:
8989
return "Humidity";
9090

91+
case AIR_PRESSURE:
92+
return "Air Pressure";
93+
9194
default:
9295
throw new SKException(TAG, "Unknown SensorModule", SKExceptionErrorCode.UNKNOWN_ERROR);
9396
}

0 commit comments

Comments
 (0)