use of nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventSendBytes in project Gadgetbridge by Freeyourgadget.
the class AppMessageHandlerMorpheuz method handleMessage.
@Override
public GBDeviceEvent[] handleMessage(ArrayList<Pair<Integer, Object>> pairs) {
int ctrl_message = 0;
for (Pair<Integer, Object> pair : pairs) {
if (Objects.equals(pair.first, keyTransmit)) {
ctrl_message |= CTRL_TRANSMIT_DONE;
GB.signalActivityDataFinish();
} else if (pair.first.equals(keyGoneoff)) {
alarm_gone_off = (int) pair.second;
LOG.info("got gone off: " + alarm_gone_off / 60 + ":" + alarm_gone_off % 60);
ctrl_message |= CTRL_DO_NEXT | CTRL_GONEOFF_DONE;
} else if (pair.first.equals(keyPoint)) {
if (recording_base_timestamp == -1) {
// we have no base timestamp but received points, stop this
ctrl_message = CTRL_VERSION_DONE | CTRL_GONEOFF_DONE | CTRL_TRANSMIT_DONE | CTRL_SET_LAST_SENT;
} else {
int index = ((int) pair.second >> 16);
int intensity = ((int) pair.second & 0xffff);
LOG.info("got point:" + index + " " + intensity);
if (index >= 0) {
try (DBHandler db = GBApplication.acquireDB()) {
Long userId = DBHelper.getUser(db.getDaoSession()).getId();
Long deviceId = DBHelper.getDevice(getDevice(), db.getDaoSession()).getId();
PebbleMorpheuzSampleProvider sampleProvider = new PebbleMorpheuzSampleProvider(getDevice(), db.getDaoSession());
PebbleMorpheuzSample sample = new PebbleMorpheuzSample(recording_base_timestamp + index * 600, deviceId, userId, intensity);
sample.setProvider(sampleProvider);
sampleProvider.addGBActivitySample(sample);
} catch (Exception e) {
LOG.error("Error acquiring database", e);
}
}
ctrl_message |= CTRL_SET_LAST_SENT | CTRL_DO_NEXT;
}
} else if (pair.first.equals(keyFrom)) {
smartalarm_from = (int) pair.second;
LOG.info("got from: " + smartalarm_from / 60 + ":" + smartalarm_from % 60);
ctrl_message |= CTRL_SET_LAST_SENT | CTRL_DO_NEXT;
} else if (pair.first.equals(keyTo)) {
smartalarm_to = (int) pair.second;
LOG.info("got to: " + smartalarm_to / 60 + ":" + smartalarm_to % 60);
ctrl_message |= CTRL_SET_LAST_SENT | CTRL_DO_NEXT;
} else if (pair.first.equals(keyVersion)) {
int version = (int) pair.second;
LOG.info("got version: " + ((float) version / 10.0f));
ctrl_message |= CTRL_VERSION_DONE;
} else if (pair.first.equals(keyBase)) {
recording_base_timestamp = (int) pair.second;
if (mPebbleProtocol.mFwMajor < 3) {
recording_base_timestamp -= SimpleTimeZone.getDefault().getOffset(recording_base_timestamp * 1000L) / 1000;
}
LOG.info("got base: " + recording_base_timestamp);
ctrl_message |= CTRL_SET_LAST_SENT | CTRL_DO_NEXT;
} else if (pair.first.equals(keyAutoReset)) {
ctrl_message |= CTRL_SET_LAST_SENT | CTRL_DO_NEXT;
} else if (pair.first.equals(keySnoozes)) {
ctrl_message |= CTRL_SNOOZES_DONE | CTRL_DO_NEXT;
} else if (pair.first.equals(keyFault)) {
LOG.info("fault code: " + (int) pair.second);
ctrl_message |= CTRL_DO_NEXT;
} else {
LOG.info("unhandled key: " + pair.first);
}
}
// always ack
GBDeviceEventSendBytes sendBytesAck = new GBDeviceEventSendBytes();
sendBytesAck.encodedBytes = mPebbleProtocol.encodeApplicationMessageAck(mUUID, mPebbleProtocol.last_id);
// sometimes send control message
GBDeviceEventSendBytes sendBytesCtrl = null;
if (ctrl_message > 0) {
sendBytesCtrl = new GBDeviceEventSendBytes();
sendBytesCtrl.encodedBytes = encodeMorpheuzMessage(keyCtrl, ctrl_message);
}
// ctrl might be null, thats okay
return new GBDeviceEvent[] { sendBytesAck, sendBytesCtrl };
}
use of nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventSendBytes in project Gadgetbridge by Freeyourgadget.
the class AppMessageHandlerObsidian method onAppStart.
@Override
public GBDeviceEvent[] onAppStart() {
WeatherSpec weatherSpec = Weather.getInstance().getWeatherSpec();
if (weatherSpec == null) {
return new GBDeviceEvent[] { null };
}
GBDeviceEventSendBytes sendBytes = new GBDeviceEventSendBytes();
sendBytes.encodedBytes = encodeObsidianWeather(weatherSpec);
return new GBDeviceEvent[] { sendBytes };
}
use of nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventSendBytes in project Gadgetbridge by Freeyourgadget.
the class AppMessageHandlerRealWeather method onAppStart.
@Override
public GBDeviceEvent[] onAppStart() {
WeatherSpec weatherSpec = Weather.getInstance().getWeatherSpec();
if (weatherSpec == null) {
return new GBDeviceEvent[] { null };
}
GBDeviceEventSendBytes sendBytes = new GBDeviceEventSendBytes();
sendBytes.encodedBytes = encodeRealWeatherMessage(weatherSpec);
return new GBDeviceEvent[] { sendBytes };
}
use of nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventSendBytes in project Gadgetbridge by Freeyourgadget.
the class AppMessageHandlerSquare method onAppStart.
@Override
public GBDeviceEvent[] onAppStart() {
WeatherSpec weatherSpec = Weather.getInstance().getWeatherSpec();
if (weatherSpec == null) {
return new GBDeviceEvent[] { null };
}
GBDeviceEventSendBytes sendBytes = new GBDeviceEventSendBytes();
sendBytes.encodedBytes = encodeSquareWeatherMessage(weatherSpec);
return new GBDeviceEvent[] { sendBytes };
}
Aggregations