Skip to content
This repository has been archived by the owner on Mar 25, 2024. It is now read-only.

Add device s200 #711

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ protected TransactionBuilder initializeDevice(TransactionBuilder builder) {
gbDevice.setState(GBDevice.State.INITIALIZED);
gbDevice.sendDeviceUpdateIntent(getContext());

if(syncHelper == null) {
if (syncHelper == null) {
syncHelper = new HPlusHandlerThread(getDevice(), getContext(), this);
syncHelper.start();
}
Expand Down Expand Up @@ -439,7 +439,7 @@ public void onSetTime() {
setCurrentDate(builder);
setCurrentTime(builder);
performConnected(builder.getTransaction());
}catch(IOException e){
} catch (IOException e) {

}
}
Expand Down Expand Up @@ -472,7 +472,8 @@ public void onSetAlarms(ArrayList<? extends Alarm> alarms) {
performConnected(builder.getTransaction());

GB.toast(getContext(), getContext().getString(R.string.user_feedback_all_alarms_disabled), Toast.LENGTH_SHORT, GB.INFO);
}catch(Exception e){}
} catch (Exception e) {
}


}
Expand Down Expand Up @@ -540,7 +541,7 @@ public void onAppReorder(UUID[] uuids) {
@Override
public void onFetchActivityData() {

if (syncHelper == null){
if (syncHelper == null) {
syncHelper = new HPlusHandlerThread(gbDevice, getContext(), this);
syncHelper.start();
}
Expand All @@ -556,20 +557,20 @@ public void onReboot() {
TransactionBuilder builder = performInitialized("Shutdown");
builder.write(ctrlCharacteristic, new byte[]{HPlusConstants.CMD_SHUTDOWN, HPlusConstants.ARG_SHUTDOWN_EN});
performConnected(builder.getTransaction());
}catch(Exception e){
} catch (Exception e) {

}
}

@Override
public void onHeartRateTest() {
getQueue().clear();
try{
try {
TransactionBuilder builder = performInitialized("HeartRateTest");

builder.write(ctrlCharacteristic, new byte[]{HPlusConstants.CMD_SET_HEARTRATE_STATE, HPlusConstants.ARG_HEARTRATE_MEASURE_ON}); //Set Real Time... ?
performConnected(builder.getTransaction());
}catch(Exception e){
} catch (Exception e) {

}
}
Expand All @@ -587,7 +588,7 @@ public void onEnableRealtimeHeartRateMeasurement(boolean enable) {

builder.write(ctrlCharacteristic, new byte[]{HPlusConstants.CMD_SET_ALLDAY_HRM, state});
performConnected(builder.getTransaction());
}catch(Exception e){
} catch (Exception e) {

}
}
Expand Down Expand Up @@ -660,87 +661,138 @@ public void onSendWeather(WeatherSpec weatherSpec) {

}

public void setUnicodeSupport(boolean support){
public void setUnicodeSupport(boolean support) {
HPlusCoordinator.setUnicodeSupport(gbDevice.getAddress(), support);
}


private void showIncomingCall(String name, String rawNumber) {
try {
private void showIncomingCall_sendName(String name, TransactionBuilder builder) {
if (name != null) {
byte[] msg = new byte[13];

TransactionBuilder builder = performInitialized("incomingCall");
//Show call name
for (int i = 0; i < msg.length; i++)
msg[i] = ' ';

//Enable call notifications
builder.write(ctrlCharacteristic, new byte[]{HPlusConstants.CMD_ACTION_INCOMING_CALL, 1});
byte[] nameBytes = encodeStringToDevice(name, HPlusConstants.CMD_ACTION_INCOMING_CALL);
for (int i = 0; i < nameBytes.length && i < (msg.length - 1); i++)
msg[i + 1] = nameBytes[i];

//Show Call Icon
builder.write(ctrlCharacteristic, new byte[]{HPlusConstants.CMD_SET_INCOMING_CALL, HPlusConstants.ARG_INCOMING_CALL});

if(name != null) {
byte[] msg = new byte[13];
msg[0] = HPlusConstants.CMD_ACTION_DISPLAY_TEXT_NAME;
builder.write(ctrlCharacteristic, msg);

//Show call name
for (int i = 0; i < msg.length; i++)
msg[i] = ' ';
msg[0] = HPlusConstants.CMD_ACTION_DISPLAY_TEXT_NAME_CN;
builder.write(ctrlCharacteristic, msg);
} else if (this.getDevice().getType() == DeviceType.MAKIBESF68) {
byte[] msg = new byte[13];

byte[] nameBytes = encodeStringToDevice(name);
for (int i = 0; i < nameBytes.length && i < (msg.length - 1); i++)
msg[i + 1] = nameBytes[i];
//Show call name
for (int i = 0; i < msg.length; i++)
msg[i] = ' ';

msg[0] = HPlusConstants.CMD_ACTION_DISPLAY_TEXT_NAME;
builder.write(ctrlCharacteristic, msg);
msg[0] = HPlusConstants.CMD_ACTION_DISPLAY_TEXT_NAME;
builder.write(ctrlCharacteristic, msg);

msg[0] = HPlusConstants.CMD_ACTION_DISPLAY_TEXT_NAME_CN;
builder.write(ctrlCharacteristic, msg);
}
msg[0] = HPlusConstants.CMD_ACTION_DISPLAY_TEXT_NAME_CN;
builder.write(ctrlCharacteristic, msg);
}
}

if(rawNumber != null) {
StringBuilder number = new StringBuilder();
private void showIncomingCall_sendNumber(String rawNumber, TransactionBuilder builder) {
if (rawNumber != null) {
StringBuilder number = new StringBuilder();

//Clean up number as the device only accepts digits
for (char c : rawNumber.toCharArray()) {
if (Character.isDigit(c)) {
number.append(c);
}
//Clean up number as the device only accepts digits
for (char c : rawNumber.toCharArray()) {
if (Character.isDigit(c)) {
number.append(c);
}
}

byte[] msg = new byte[13];

byte[] msg = new byte[13];
//Show call number
for (int i = 0; i < msg.length; i++)
msg[i] = ' ';

for (int i = 0; i < number.length() && i < (msg.length - 1); i++)
msg[i + 1] = (byte) number.charAt(i);

//Show call number
for (int i = 0; i < msg.length; i++)
msg[i] = ' ';
msg[0] = HPlusConstants.CMD_SET_INCOMING_CALL_NUMBER;

for (int i = 0; i < number.length() && i < (msg.length - 1); i++)
msg[i + 1] = (byte) number.charAt(i);
builder.wait(200);
builder.write(ctrlCharacteristic, msg);
} else if (this.getDevice().getType() == DeviceType.MAKIBESF68) {
byte[] msg = new byte[13];

msg[0] = HPlusConstants.CMD_SET_INCOMING_CALL_NUMBER;
//Show call number
for (int i = 0; i < msg.length; i++)
msg[i] = ' ';

msg[0] = HPlusConstants.CMD_SET_INCOMING_CALL_NUMBER;

builder.wait(200);
builder.write(ctrlCharacteristic, msg);
// builder.wait(200);
builder.write(ctrlCharacteristic, msg);
}
}

private void showIncomingCall(String name, String rawNumber) {
try {

TransactionBuilder builder = performInitialized("incomingCall");

//Enable call notifications
builder.write(ctrlCharacteristic, new byte[]{HPlusConstants.CMD_ACTION_INCOMING_CALL, 1});

//Show Call Icon
builder.write(ctrlCharacteristic, new byte[]{HPlusConstants.CMD_SET_INCOMING_CALL, HPlusConstants.ARG_INCOMING_CALL});

if (this.getDevice().getType() == DeviceType.MAKIBESF68) {
//ATTENTION, MAKIBESF68 RESET DISPLAY ONLY WHEN SEND THE NUMBER,IF SEND FIRST NAME THE DISPLAY RETURN OLD NUMBER
showIncomingCall_sendNumber(rawNumber, builder);
showIncomingCall_sendName(name, builder);
} else if (this.getDevice().getType() == DeviceType.HPLUS) {
showIncomingCall_sendName(name, builder);
showIncomingCall_sendNumber(rawNumber, builder);
}


performConnected(builder.getTransaction());
} catch (IOException e) {
GB.toast(getContext(), "Error showing incoming call: " + e.getLocalizedMessage(), Toast.LENGTH_LONG, GB.ERROR);

}
}


private void showText(String title, String body) {
try {
TransactionBuilder builder = performInitialized("notification");

String message = "";

if (title != null && title.length() > 0) {
message = StringUtils.pad(StringUtils.truncate(title, 16), 16); //Limit title to top row
if (getDevice().getType() == DeviceType.MAKIBESF68) {
message = StringUtils.truncate(title, 9) + ":"; //Limit title to top row
for (int i = message.length(); i < 10; i++)
message += ' ';
}
if (getDevice().getType() == DeviceType.HPLUS) {
message = StringUtils.pad(StringUtils.truncate(title, 16), 16); //Limit title to top row
}
}

if (body != null) {
message += body;
if (getDevice().getType() == DeviceType.MAKIBESF68) {
message += StringUtils.truncate(body, 49 - message.length());
}
if (getDevice().getType() == DeviceType.HPLUS) {
message += body;
}
}

byte[] messageBytes = encodeStringToDevice(message);
byte[] messageBytes = encodeStringToDevice(message, HPlusConstants.CMD_ACTION_DISPLAY_TEXT);

int length = messageBytes.length / 17;

Expand Down Expand Up @@ -805,8 +857,8 @@ private void close() {
* @param s The String to transliterate
* @return An array of bytes ready to be sent to the device
*/
private byte[] encodeStringToDevice(String s) {

private byte[] encodeStringToDevice(String s, byte cmd) {
String encoding = "";
List<Byte> outBytes = new ArrayList<Byte>();
Boolean unicode = HPlusCoordinator.getUnicodeSupport(this.gbDevice.getAddress());
LOG.info("Encode String: Unicode=" + unicode);
Expand All @@ -819,17 +871,33 @@ private byte[] encodeStringToDevice(String s) {
cs = HPlusConstants.transliterateMap.get(c);
} else {
try {
if(unicode)
cs = c.toString().getBytes("Unicode");
else
cs = c.toString().getBytes("GB2312");
if (unicode) {
switch (cmd) {
case HPlusConstants.CMD_ACTION_INCOMING_CALL:
encoding = "GB2312";
break;
case HPlusConstants.CMD_ACTION_DISPLAY_TEXT:
default:
encoding = "Unicode";
break;
}
cs = c.toString().getBytes(encoding);
} else {
encoding = "GB2312";
cs = c.toString().getBytes(encoding);
}
} catch (UnsupportedEncodingException e) {
//Fallback. Result string may be strange, but better than nothing
cs = c.toString().getBytes();
LOG.error("Could not convert String to Bytes: " + e.getMessage());
}
}
for (int j = 0; j < cs.length; j++)

int star_byte = 0;
if (encoding == "Unicode" && !outBytes.isEmpty()) {
star_byte = 2;
}
for (int j = star_byte; j < cs.length; j++)
outBytes.add(cs[j]);
}

Expand All @@ -856,7 +924,7 @@ public boolean onCharacteristicChanged(BluetoothGatt gatt,
case HPlusConstants.DATA_STATS:
boolean result = syncHelper.processRealtimeStats(data, HPlusCoordinator.getUserAge());
if (result) {
processExtraInfo (data);
processExtraInfo(data);
}
return result;

Expand All @@ -878,7 +946,7 @@ public boolean onCharacteristicChanged(BluetoothGatt gatt,
}
}

private void processExtraInfo (byte[] data) {
private void processExtraInfo(byte[] data) {
try {
HPlusDataRecordRealtime record = new HPlusDataRecordRealtime(data, HPlusCoordinator.getUserAge());

Expand Down Expand Up @@ -912,10 +980,10 @@ private void processExtraInfo (byte[] data) {
}

private void handleBatteryInfo(byte data) {
if (batteryCmd.level != (short) data) {
batteryCmd.level = (short) data;
handleGBDeviceEvent(batteryCmd);
}
if (batteryCmd.level != (short) data) {
batteryCmd.level = (short) data;
handleGBDeviceEvent(batteryCmd);
}
}

}
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.2'
classpath 'com.android.tools.build:gradle:2.3.3'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand Down