-
Notifications
You must be signed in to change notification settings - Fork 13
Added InMotion general alarms #6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
e86dec7
6e01bb3
667719b
1c1d8bd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,12 +1,15 @@ | ||
| package com.cooper.wheellog; | ||
|
|
||
| import android.app.Activity; | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are you sure that it is needed?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably not. Will check. |
||
| import android.app.AlertDialog; | ||
| import android.app.Application; | ||
| import android.bluetooth.BluetoothGattCharacteristic; | ||
| import android.bluetooth.BluetoothGattDescriptor; | ||
| import android.bluetooth.BluetoothGattService; | ||
| import android.content.Context; | ||
| import android.content.DialogInterface; | ||
| import android.content.Intent; | ||
| import android.media.MediaPlayer; | ||
| import android.os.Vibrator; | ||
|
|
||
| import android.text.InputType; | ||
|
|
@@ -28,6 +31,7 @@ public class WheelData { | |
| private static final int TIME_BUFFER = 10; | ||
| private static WheelData mInstance; | ||
| private Timer ridingTimerControl; | ||
| private MediaPlayer mAlertSoundPlayer; | ||
|
|
||
| private BluetoothLeService mBluetoothLeService; | ||
|
|
||
|
|
@@ -68,6 +72,7 @@ public class WheelData { | |
| private String mBtName = ""; | ||
|
|
||
| private String mAlert = ""; | ||
| private int mAlertId = 0; | ||
|
|
||
| // private int mVersion; # sorry King, but INT not good for Inmo | ||
| private String mVersion = ""; | ||
|
|
@@ -84,6 +89,7 @@ public class WheelData { | |
| private int mWheelTiltHorizon = 0; | ||
|
|
||
| private boolean mAlarmsEnabled = false; | ||
| private boolean mInmotionAlarmsEnabled = false; | ||
| private boolean mDisablePhoneVibrate = false; | ||
| private int mAlarm1Speed = 0; | ||
| private int mAlarm2Speed = 0; | ||
|
|
@@ -101,6 +107,7 @@ public class WheelData { | |
| private boolean mSpeedAlarmExecuted = false; | ||
| private boolean mCurrentAlarmExecuted = false; | ||
| private boolean mTemperatureAlarmExecuted = false; | ||
| private boolean mGeneralInMotionAlarmExecuted = false; | ||
|
|
||
| static void initiate() { | ||
| if (mInstance == null) | ||
|
|
@@ -573,6 +580,10 @@ void setConnected(boolean connected) { | |
| void setAlarmsEnabled(boolean enabled) { | ||
| mAlarmsEnabled = enabled; | ||
| } | ||
|
|
||
| void setInmotionAlarmsEnabled(boolean enabled){ | ||
| mInmotionAlarmsEnabled = enabled; | ||
| } | ||
|
|
||
| void setUseRatio(boolean enabled) { | ||
| mUseRatio = enabled; | ||
|
|
@@ -680,11 +691,25 @@ else if (mAlarm3Speed > 0 && mAlarm3Battery > 0 && | |
| if (mTemperature < mAlarmTemperature) | ||
| mTemperatureAlarmExecuted = false; | ||
| } | ||
|
|
||
|
|
||
| } | ||
|
|
||
| private void checkInMotionAlarmStatus(Context mContext) { | ||
| // GENERAL inMotion Alarm | ||
| if (!mGeneralInMotionAlarmExecuted) | ||
| { | ||
| if (mAlertId != 0) { | ||
| raiseAlarm(ALARM_TYPE.GENERAL,mContext); | ||
| mAlertId = 0; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private void raiseAlarm(ALARM_TYPE alarmType, Context mContext) { | ||
| Vibrator v = (Vibrator) mContext.getSystemService(Context.VIBRATOR_SERVICE); | ||
| MediaPlayer mp = new MediaPlayer(); | ||
|
|
||
| long[] pattern = {0}; | ||
| Intent intent = new Intent(Constants.ACTION_ALARM_TRIGGERED); | ||
| intent.putExtra(Constants.INTENT_EXTRA_ALARM_TYPE, alarmType); | ||
|
|
@@ -702,8 +727,24 @@ private void raiseAlarm(ALARM_TYPE alarmType, Context mContext) { | |
| pattern = new long[]{0, 500, 100, 100, 100, 500, 100, 100, 100, 500, 100, 100, 100}; | ||
| mCurrentAlarmExecuted = true; | ||
| break; | ||
| case GENERAL: | ||
| if (mp.isPlaying() == false) { | ||
| mp = MediaPlayer.create(mContext, R.raw.bicycle_bell); | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why bicycle_bell? I think it should be separate sound, something like inmotion sound.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have a //TODO to change it. Will do, use the SCV default sound for that. |
||
| mp.start(); | ||
| //That fires after the sound has played so it releases the resourse. | ||
| //Needed otherwise it would stop working after a while | ||
| mp.setOnCompletionListener(new MediaPlayer.OnCompletionListener() { | ||
| public void onCompletion(MediaPlayer mp) { | ||
| mp.reset(); | ||
| mp.release(); | ||
| mGeneralInMotionAlarmExecuted = false; | ||
| } | ||
| }); | ||
| } | ||
| break; | ||
| } | ||
| mContext.sendBroadcast(intent); | ||
|
|
||
| if (v.hasVibrator() && !mDisablePhoneVibrate) | ||
| v.vibrate(pattern, -1); | ||
| } | ||
|
|
@@ -758,6 +799,9 @@ else if (mWheelType == WHEEL_TYPE.NINEBOT_Z) { | |
|
|
||
| if (mAlarmsEnabled) | ||
| checkAlarmStatus(mContext); | ||
| if (mInmotionAlarmsEnabled) | ||
| checkInMotionAlarmStatus(mContext); | ||
|
|
||
| mContext.sendBroadcast(intent); | ||
|
|
||
|
|
||
|
|
@@ -998,6 +1042,11 @@ private boolean decodeInmotion(byte[] data) { | |
| } else { | ||
| mAlert = mAlert + " | " + ((InMotionAdapter.Alert) status).getfullText(); | ||
| } | ||
| mAlertId = ((InMotionAdapter.Alert) status).getAlertId(); //mAlertId is checked on checkAlarms function. | ||
| if (mAlertId == 0x05) //Discards alerts that the user does not need. | ||
| { | ||
| mAlertId = 0; | ||
| } | ||
| } else { | ||
| mSpeed = (int) (status.getSpeed() * 360d); | ||
| mVoltage = (int) (status.getVoltage() * 100d); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -519,6 +519,9 @@ public String getfullText() { | |
| return fullText; | ||
|
|
||
| } | ||
| public int getAlertId(){ | ||
| return alertId; | ||
| } | ||
|
|
||
|
|
||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,6 +8,11 @@ | |
| android:title="Enable Alarms" | ||
| android:summary="Allow the phone to vibrate as a warning" /> | ||
|
|
||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure that it is good idea to put inmotion-specific option to general menu. Maybe it's better to move it to inmotion_preferences, or at least make it disabled by default?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You |
||
| <CheckBoxPreference | ||
| android:key="@string/inMotion_alarms_enabled" | ||
| android:title="Enable InMotion Alarms" | ||
| android:summary="Enable InMotion Specific General Alarms" /> | ||
|
|
||
| <CheckBoxPreference | ||
| android:key="@string/disable_phone_vibrate" | ||
| android:dependency="alarms_enabled" | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
compile instruction deprecated, please update Android studio/graddle
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That was probably added automatically... or stayed there when I merged with your most current code. Will update.