Skip to content

Commit 620e6af

Browse files
author
JumpMaster
committed
Added onboard/mp3 horn option and new theme.
1 parent 6ede932 commit 620e6af

40 files changed

Lines changed: 528 additions & 446 deletions

app/build.gradle

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ android {
88
applicationId "com.cooper.wheellog"
99
minSdkVersion 18
1010
targetSdkVersion 24
11-
versionCode 1
12-
versionName "0.1"
11+
versionCode 2
12+
versionName "0.9"
1313
}
1414
buildTypes {
1515
release {
@@ -23,4 +23,6 @@ dependencies {
2323
compile fileTree(dir: 'libs', include: ['*.jar'])
2424
compile 'com.getpebble:pebblekit:3.0.0'
2525
compile 'com.android.support:appcompat-v7:24.0.0'
26+
compile 'com.android.support:design:24.0.0'
27+
compile 'com.android.support:gridlayout-v7:24.0.0'
2628
}

app/src/main/AndroidManifest.xml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,18 @@
99
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
1010

1111
<application
12+
android:name=".WheelLog"
1213
android:allowBackup="true"
1314
android:icon="@mipmap/ic_launcher"
1415
android:label="@string/app_name"
1516
android:supportsRtl="true"
16-
android:theme="@style/AppTheme">
17+
android:theme="@style/AppTheme"
18+
android:resizeableActivity="false"
19+
android:supportsPictureInPicture="false">
1720
<activity
1821
android:name=".MainActivity"
19-
android:launchMode="singleInstance">
22+
android:launchMode="singleInstance"
23+
android:configChanges="orientation|keyboardHidden|screenSize">
2024
<intent-filter>
2125
<action android:name="android.intent.action.MAIN" />
2226
<category android:name="android.intent.category.LAUNCHER" />

app/src/main/java/com/cooper/wheellog/BluetoothLeService.java

Lines changed: 51 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@
1212
import android.bluetooth.BluetoothGattService;
1313
import android.bluetooth.BluetoothManager;
1414
import android.bluetooth.BluetoothProfile;
15+
import android.content.BroadcastReceiver;
1516
import android.content.Context;
1617
import android.content.Intent;
1718
import android.content.IntentFilter;
1819
import android.os.Binder;
19-
import android.os.Handler;
2020
import android.os.IBinder;
2121
import android.support.v7.app.NotificationCompat;
2222
import android.util.Log;
@@ -49,15 +49,58 @@ public class BluetoothLeService extends Service {
4949
public static final int STATE_CONNECTING = 1;
5050
public static final int STATE_CONNECTED = 2;
5151

52-
private Handler mHandler = new Handler();
52+
53+
private final BroadcastReceiver messageReceiver = new BroadcastReceiver() {
54+
@Override
55+
public void onReceive(Context context, Intent intent) {
56+
if (mConnectionState != STATE_CONNECTED)
57+
return;
58+
59+
final String action = intent.getAction();
60+
if (Constants.ACTION_REQUEST_NAME_DATA.equals(action)) {
61+
62+
byte[] data = new byte[20];
63+
data[0] = (byte) -86;
64+
data[1] = (byte) 85;
65+
data[16] = (byte) -101;
66+
data[17] = (byte) 20;
67+
data[18] = (byte) 90;
68+
data[19] = (byte) 90;
69+
writeBluetoothGattCharacteristic(data);
70+
} else if (Constants.ACTION_REQUEST_SERIAL_DATA.equals(action)) {
71+
72+
byte[] data = new byte[20];
73+
data[0] = (byte) -86;
74+
data[1] = (byte) 85;
75+
data[16] = (byte) 99;
76+
data[17] = (byte) 20;
77+
data[18] = (byte) 90;
78+
data[19] = (byte) 90;
79+
writeBluetoothGattCharacteristic(data);
80+
} else if (Constants.ACTION_REQUEST_HORN.equals(action)) {
81+
82+
byte[] data = new byte[20];
83+
data[0] = (byte) -86;
84+
data[1] = (byte) 85;
85+
data[16] = (byte) -120;
86+
data[17] = (byte) 20;
87+
data[18] = (byte) 90;
88+
data[19] = (byte) 90;
89+
writeBluetoothGattCharacteristic(data);
90+
}
91+
}
92+
};
5393

5494
public static IntentFilter makeBluetoothUpdateIntentFilter() {
5595
final IntentFilter intentFilter = new IntentFilter();
96+
intentFilter.addAction(Constants.ACTION_BLUETOOTH_CONNECTING);
5697
intentFilter.addAction(Constants.ACTION_BLUETOOTH_CONNECTED);
5798
intentFilter.addAction(Constants.ACTION_BLUETOOTH_DISCONNECTED);
5899
intentFilter.addAction(Constants.ACTION_BLUETOOTH_DATA_AVAILABLE);
59100
intentFilter.addAction(Constants.ACTION_WHEEL_DATA_AVAILABLE);
60101
intentFilter.addAction(Constants.ACTION_REQUEST_SERIAL_DATA);
102+
intentFilter.addAction(Constants.ACTION_REQUEST_NAME_DATA);
103+
intentFilter.addAction(Constants.ACTION_REQUEST_HORN);
61104
return intentFilter;
62105
}
63106

@@ -84,7 +127,7 @@ public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState
84127

85128
} else if (newState == BluetoothProfile.STATE_DISCONNECTED) {
86129
mConnectionState = STATE_DISCONNECTED;
87-
Wheel.getInstance().setConnectionState(false);
130+
((WheelLog) getApplicationContext()).setConnectionState(false);
88131
LOGI("Disconnected from GATT server.");
89132
broadcastUpdate(Constants.ACTION_BLUETOOTH_DISCONNECTED);
90133
}
@@ -120,7 +163,6 @@ public void onServicesDiscovered(BluetoothGatt gatt, int status) {
120163
BluetoothGattDescriptor descriptor = characteristic.getDescriptor(UUID.fromString(BluetoothLeService.DESCRIPTER_UUID));
121164
descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
122165
mBluetoothGatt.writeDescriptor(descriptor);
123-
mConnectionState = BluetoothLeService.STATE_CONNECTED;
124166
mConnectionState = STATE_CONNECTED;
125167
return;
126168
}
@@ -150,9 +192,7 @@ public void onCharacteristicChanged(BluetoothGatt gatt, BluetoothGattCharacteris
150192
// stringBuilder.append(String.format("%02X ", objArr));
151193
// }
152194
// LOGI("received data = " + stringBuilder);
153-
int result = Wheel.getInstance().decodeResponse(value);
154-
if (result == Constants.REQUEST_SERIAL_DATA)
155-
sendBroadcast(new Intent(Constants.ACTION_REQUEST_SERIAL_DATA));
195+
((WheelLog) getApplicationContext()).decodeResponse(value);
156196

157197
Intent intent = new Intent(Constants.ACTION_WHEEL_DATA_AVAILABLE);
158198
sendBroadcast(intent);
@@ -164,7 +204,7 @@ public void onDescriptorWrite(BluetoothGatt gatt, BluetoothGattDescriptor descri
164204
super.onDescriptorWrite(gatt, descriptor, status);
165205
LOGI("onDescriptorWrite " + String.valueOf(status));
166206
if (status == BluetoothGatt.GATT_SUCCESS) {
167-
Wheel.getInstance().setConnectionState(true);
207+
((WheelLog) getApplicationContext()).setConnectionState(true);
168208
broadcastUpdate(Constants.ACTION_BLUETOOTH_CONNECTED);
169209
}
170210
}
@@ -202,6 +242,7 @@ public int onStartCommand(Intent intent, int flags, int startId) {
202242
.setContentIntent(pendingIntent)
203243
.build();
204244

245+
registerReceiver(messageReceiver, makeBluetoothUpdateIntentFilter());
205246
startForeground(1, notification);
206247

207248
return START_STICKY;
@@ -263,6 +304,7 @@ public boolean connect(final String address) {
263304
Log.d(TAG, "Trying to use an existing mBluetoothGatt for connection.");
264305
if (mBluetoothGatt.connect()) {
265306
mConnectionState = STATE_CONNECTING;
307+
broadcastUpdate(Constants.ACTION_BLUETOOTH_CONNECTING);
266308
return true;
267309
} else {
268310
return false;
@@ -279,6 +321,7 @@ public boolean connect(final String address) {
279321
Log.d(TAG, "Trying to create a new connection.");
280322
mBluetoothDeviceAddress = address;
281323
mConnectionState = STATE_CONNECTING;
324+
broadcastUpdate(Constants.ACTION_BLUETOOTH_CONNECTING);
282325
return true;
283326
}
284327

@@ -305,7 +348,6 @@ public void disconnect() {
305348
* released properly.
306349
*/
307350
public void close() {
308-
mHandler.removeCallbacksAndMessages(null);
309351

310352
if (mBluetoothGatt == null) {
311353
return;

app/src/main/java/com/cooper/wheellog/Constants.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,21 @@
44

55
public class Constants {
66

7+
public static final String ACTION_BLUETOOTH_CONNECTING = "com.cooper.wheellog.bluetoothConnecting";
78
public static final String ACTION_BLUETOOTH_CONNECTED = "com.cooper.wheellog.bluetoothConnected";
89
public static final String ACTION_BLUETOOTH_DISCONNECTED = "com.cooper.wheellog.bluetoothDisconnected";
910
public static final String ACTION_BLUETOOTH_DATA_AVAILABLE = "com.cooper.wheellog.bluetoothDataAvailable";
1011
public static final String ACTION_WHEEL_DATA_AVAILABLE = "com.cooper.wheellog.wheelDataAvailable";
1112
public static final String ACTION_REQUEST_SERIAL_DATA = "com.cooper.wheellog.requestSerialData";
13+
public static final String ACTION_REQUEST_NAME_DATA = "com.cooper.wheellog.requestNameData";
14+
public static final String ACTION_REQUEST_HORN = "com.cooper.wheellog.requestHorn";
1215
// public static final String ACTION_PEBBLE_SERVICE_STARTED = "com.cooper.wheellog.pebbleServiceStarted";
1316
// public static final String ACTION_LOGGING_SERVICE_STARTED = "com.cooper.wheellog.loggingServiceStarted";
1417

1518
public static final UUID PEBBLE_APP_UUID = UUID.fromString("185c8ae9-7e72-451a-a1c7-8f1e81df9a3d");
16-
public static final int PEBBLE_KEY_LAUNCH_APP = 10007;
17-
public static final int PEBBLE_KEY_PLAY_HORN = 10008;
19+
public static final int PEBBLE_KEY_LAUNCH_APP = 10008;
20+
public static final int PEBBLE_KEY_PLAY_HORN = 10009;
21+
public static final int PEBBLE_KEY_PLAY_HORN_MP3 = 10010;
1822

1923
public static final String LAUNCHED_FROM_PEBBLE = "launched_from_pebble";
2024

app/src/main/java/com/cooper/wheellog/DataLogger.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ public class DataLogger extends Service
2727
SimpleDateFormat sdf;
2828
private boolean fileExists;
2929
private File file;
30+
private WheelLog wheelLog;
3031

3132
public static boolean isInstanceCreated() {
3233
return instance != null;
@@ -69,7 +70,7 @@ public int onStartCommand(Intent intent, int flags, int startId) {
6970

7071
file = new File(dir, fileName);
7172
fileExists = file.exists();
72-
73+
wheelLog = (WheelLog) getApplicationContext();
7374
Log.d(TAG, "DataLogger Started");
7475
return START_STICKY;
7576
}
@@ -120,13 +121,13 @@ private void writeToSDFile(){
120121

121122
pw.println(String.format(Locale.US, "%s,%f,%f,%f,%d,%f,%d,%d",
122123
sdf.format(new Date()),
123-
Wheel.getInstance().getSpeedDouble(),
124-
Wheel.getInstance().getVoltageDouble(),
125-
Wheel.getInstance().getCurrentDouble(),
126-
Wheel.getInstance().getBatteryLevel(),
127-
Wheel.getInstance().getCurrentDistanceDouble(),
128-
Wheel.getInstance().getTemperature(),
129-
Wheel.getInstance().getFanStatus()
124+
wheelLog.getSpeedDouble(),
125+
wheelLog.getVoltageDouble(),
126+
wheelLog.getCurrentDouble(),
127+
wheelLog.getBatteryLevel(),
128+
wheelLog.getDistanceDouble(),
129+
wheelLog.getTemperature(),
130+
wheelLog.getFanStatus()
130131
));
131132
pw.flush();
132133
pw.close();

0 commit comments

Comments
 (0)