Search in sources :

Example 1 with GBDeviceEventMusicControl

use of nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventMusicControl in project Gadgetbridge by Freeyourgadget.

the class SMAQ2OSSSupport method handleMusicEvent.

private void handleMusicEvent(byte value) {
    GBDeviceEventMusicControl deviceEventMusicControl = new GBDeviceEventMusicControl();
    switch(value) {
        case SMAQ2OSSConstants.EVT_PLAY_PAUSE:
            deviceEventMusicControl.event = GBDeviceEventMusicControl.Event.PLAYPAUSE;
            break;
        case SMAQ2OSSConstants.EVT_FWD:
            deviceEventMusicControl.event = GBDeviceEventMusicControl.Event.NEXT;
            break;
        case SMAQ2OSSConstants.EVT_REV:
            deviceEventMusicControl.event = GBDeviceEventMusicControl.Event.PREVIOUS;
            break;
        case SMAQ2OSSConstants.EVT_VOL_UP:
            deviceEventMusicControl.event = GBDeviceEventMusicControl.Event.VOLUMEUP;
            break;
        case SMAQ2OSSConstants.EVT_VOL_DOWN:
            deviceEventMusicControl.event = GBDeviceEventMusicControl.Event.VOLUMEDOWN;
            break;
    }
    evaluateGBDeviceEvent(deviceEventMusicControl);
}
Also used : GBDeviceEventMusicControl(nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventMusicControl)

Example 2 with GBDeviceEventMusicControl

use of nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventMusicControl in project Gadgetbridge by Freeyourgadget.

the class HuamiSupport method handleDeviceEvent.

private void handleDeviceEvent(byte[] value) {
    if (value == null || value.length == 0) {
        return;
    }
    GBDeviceEventCallControl callCmd = new GBDeviceEventCallControl();
    switch(value[0]) {
        case HuamiDeviceEvent.CALL_REJECT:
            LOG.info("call rejected");
            callCmd.event = GBDeviceEventCallControl.Event.REJECT;
            evaluateGBDeviceEvent(callCmd);
            break;
        case HuamiDeviceEvent.CALL_IGNORE:
            LOG.info("call ignored");
            callCmd.event = GBDeviceEventCallControl.Event.IGNORE;
            evaluateGBDeviceEvent(callCmd);
            break;
        case HuamiDeviceEvent.BUTTON_PRESSED:
            LOG.info("button pressed");
            handleButtonEvent();
            break;
        case HuamiDeviceEvent.BUTTON_PRESSED_LONG:
            LOG.info("button long-pressed ");
            handleLongButtonEvent();
            break;
        case HuamiDeviceEvent.START_NONWEAR:
            LOG.info("non-wear start detected");
            processDeviceEvent(HuamiDeviceEvent.START_NONWEAR);
            break;
        case HuamiDeviceEvent.ALARM_TOGGLED:
        case HuamiDeviceEvent.ALARM_CHANGED:
            LOG.info("An alarm was toggled or changed");
            TransactionBuilder builder = new TransactionBuilder("requestAlarms");
            requestAlarms(builder);
            builder.queue(getQueue());
            break;
        case HuamiDeviceEvent.FELL_ASLEEP:
            LOG.info("Fell asleep");
            processDeviceEvent(HuamiDeviceEvent.FELL_ASLEEP);
            break;
        case HuamiDeviceEvent.WOKE_UP:
            LOG.info("Woke up");
            processDeviceEvent(HuamiDeviceEvent.WOKE_UP);
            break;
        case HuamiDeviceEvent.STEPSGOAL_REACHED:
            LOG.info("Steps goal reached");
            break;
        case HuamiDeviceEvent.TICK_30MIN:
            LOG.info("Tick 30 min (?)");
            break;
        case HuamiDeviceEvent.FIND_PHONE_START:
            LOG.info("find phone started");
            // FIXME: premature
            acknowledgeFindPhone();
            findPhoneEvent.event = GBDeviceEventFindPhone.Event.START;
            evaluateGBDeviceEvent(findPhoneEvent);
            break;
        case HuamiDeviceEvent.FIND_PHONE_STOP:
            LOG.info("find phone stopped");
            findPhoneEvent.event = GBDeviceEventFindPhone.Event.STOP;
            evaluateGBDeviceEvent(findPhoneEvent);
            break;
        case HuamiDeviceEvent.MUSIC_CONTROL:
            LOG.info("got music control");
            GBDeviceEventMusicControl deviceEventMusicControl = new GBDeviceEventMusicControl();
            switch(value[1]) {
                case 0:
                    deviceEventMusicControl.event = GBDeviceEventMusicControl.Event.PLAY;
                    break;
                case 1:
                    deviceEventMusicControl.event = GBDeviceEventMusicControl.Event.PAUSE;
                    break;
                case 3:
                    deviceEventMusicControl.event = GBDeviceEventMusicControl.Event.NEXT;
                    break;
                case 4:
                    deviceEventMusicControl.event = GBDeviceEventMusicControl.Event.PREVIOUS;
                    break;
                case 5:
                    deviceEventMusicControl.event = GBDeviceEventMusicControl.Event.VOLUMEUP;
                    break;
                case 6:
                    deviceEventMusicControl.event = GBDeviceEventMusicControl.Event.VOLUMEDOWN;
                    break;
                case (byte) 224:
                    LOG.info("Music app started");
                    isMusicAppStarted = true;
                    sendMusicStateToDevice();
                    break;
                case (byte) 225:
                    LOG.info("Music app terminated");
                    isMusicAppStarted = false;
                    break;
                default:
                    LOG.info("unhandled music control event " + value[1]);
                    return;
            }
            evaluateGBDeviceEvent(deviceEventMusicControl);
            break;
        case HuamiDeviceEvent.MTU_REQUEST:
            int mtu = (value[2] & 0xff) << 8 | value[1] & 0xff;
            LOG.info("device announced MTU of " + mtu);
            Prefs prefs = new Prefs(GBApplication.getDeviceSpecificSharedPrefs(gbDevice.getAddress()));
            if (!prefs.getBoolean(PREF_ALLOW_HIGH_MTU, false)) {
                break;
            }
            if (mtu < 23) {
                LOG.error("Device announced unreasonable low MTU of " + mtu + ", ignoring");
                break;
            }
            mMTU = mtu;
            /*
                 * not really sure if this would make sense, is this event already a proof of a successful MTU
                 * negotiation initiated by the Huami device, and acknowledged by the phone? do we really have to
                 * requestMTU() from our side after receiving this?
                 * /
                if (mMTU != mtu) {
                    requestMTU(mtu);
                }
                */
            break;
        default:
            LOG.warn("unhandled event " + value[0]);
    }
}
Also used : GBDeviceEventMusicControl(nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventMusicControl) TransactionBuilder(nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder) GBDeviceEventCallControl(nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventCallControl) Prefs(nodomain.freeyourgadget.gadgetbridge.util.Prefs) GBPrefs(nodomain.freeyourgadget.gadgetbridge.util.GBPrefs)

Example 3 with GBDeviceEventMusicControl

use of nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventMusicControl in project Gadgetbridge by Freeyourgadget.

the class FitProDeviceSupport method handleMediaButton.

public void handleMediaButton(byte command) {
    GBDeviceEventMusicControl deviceEventMusicControl = new GBDeviceEventMusicControl();
    if (command == RX_MEDIA_PLAY_PAUSE) {
        deviceEventMusicControl.event = GBDeviceEventMusicControl.Event.PLAYPAUSE;
        evaluateGBDeviceEvent(deviceEventMusicControl);
    } else if (command == RX_MEDIA_FORW) {
        deviceEventMusicControl.event = GBDeviceEventMusicControl.Event.NEXT;
        evaluateGBDeviceEvent(deviceEventMusicControl);
    } else if (command == RX_MEDIA_BACK) {
        deviceEventMusicControl.event = GBDeviceEventMusicControl.Event.PREVIOUS;
        evaluateGBDeviceEvent(deviceEventMusicControl);
    }
}
Also used : GBDeviceEventMusicControl(nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventMusicControl)

Example 4 with GBDeviceEventMusicControl

use of nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventMusicControl in project Gadgetbridge by Freeyourgadget.

the class CasioGB6900DeviceSupport method onCharacteristicWriteRequest.

@Override
public boolean onCharacteristicWriteRequest(BluetoothDevice device, int requestId, BluetoothGattCharacteristic characteristic, boolean preparedWrite, boolean responseNeeded, int offset, byte[] value) {
    GBDeviceEventMusicControl musicCmd = new GBDeviceEventMusicControl();
    if (!characteristic.getUuid().equals(CasioConstants.KEY_CONTAINER_CHARACTERISTIC_UUID)) {
        LOG.warn("unexpected write request");
        return false;
    }
    if ((value[0] & 0x03) == 0) {
        int button = value[1] & 0x0f;
        LOG.info("Button pressed: " + button);
        switch(getModel()) {
            case MODEL_CASIO_5600B:
                musicCmd.event = parse2Button(button);
                break;
            case MODEL_CASIO_6900B:
            case MODEL_CASIO_GENERIC:
                musicCmd.event = parse3Button(button);
                break;
            case MODEL_CASIO_STB1000:
                musicCmd.event = parse5Button(button);
                break;
            default:
                LOG.warn("Unhandled device");
                return false;
        }
        evaluateGBDeviceEvent(musicCmd);
    } else {
        LOG.info("received from device: " + value.toString());
    }
    return true;
}
Also used : GBDeviceEventMusicControl(nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventMusicControl)

Example 5 with GBDeviceEventMusicControl

use of nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventMusicControl in project Gadgetbridge by Freeyourgadget.

the class FossilHRWatchAdapter method handleMusicRequest.

private void handleMusicRequest(byte[] value) {
    byte command = value[3];
    LOG.info("got music command: " + command);
    MUSIC_WATCH_REQUEST request = MUSIC_WATCH_REQUEST.fromCommandByte(command);
    GBDeviceEventMusicControl deviceEventMusicControl = new GBDeviceEventMusicControl();
    deviceEventMusicControl.event = GBDeviceEventMusicControl.Event.PLAY;
    switch(request) {
        case MUSIC_REQUEST_PLAY_PAUSE:
            {
                queueWrite(new MusicControlRequest(MUSIC_PHONE_REQUEST.MUSIC_REQUEST_PLAY_PAUSE));
                deviceEventMusicControl.event = GBDeviceEventMusicControl.Event.PLAYPAUSE;
                break;
            }
        case MUSIC_REQUEST_NEXT:
            {
                queueWrite(new MusicControlRequest(MUSIC_PHONE_REQUEST.MUSIC_REQUEST_NEXT));
                deviceEventMusicControl.event = GBDeviceEventMusicControl.Event.NEXT;
                break;
            }
        case MUSIC_REQUEST_PREVIOUS:
            {
                queueWrite(new MusicControlRequest(MUSIC_PHONE_REQUEST.MUSIC_REQUEST_PREVIOUS));
                deviceEventMusicControl.event = GBDeviceEventMusicControl.Event.PREVIOUS;
                break;
            }
        case MUSIC_REQUEST_LOUDER:
            {
                queueWrite(new MusicControlRequest(MUSIC_PHONE_REQUEST.MUSIC_REQUEST_LOUDER));
                deviceEventMusicControl.event = GBDeviceEventMusicControl.Event.VOLUMEUP;
                break;
            }
        case MUSIC_REQUEST_QUITER:
            {
                queueWrite(new MusicControlRequest(MUSIC_PHONE_REQUEST.MUSIC_REQUEST_QUITER));
                deviceEventMusicControl.event = GBDeviceEventMusicControl.Event.VOLUMEDOWN;
                break;
            }
    }
    getDeviceSupport().evaluateGBDeviceEvent(deviceEventMusicControl);
}
Also used : MUSIC_WATCH_REQUEST(nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil_hr.music.MusicControlRequest.MUSIC_WATCH_REQUEST) MusicControlRequest(nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil_hr.music.MusicControlRequest) GBDeviceEventMusicControl(nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventMusicControl)

Aggregations

GBDeviceEventMusicControl (nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventMusicControl)8 GBDeviceEventCallControl (nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventCallControl)3 UUID (java.util.UUID)2 Pair (android.util.Pair)1 ByteBuffer (java.nio.ByteBuffer)1 GBDeviceEvent (nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEvent)1 GBDeviceEventAppInfo (nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventAppInfo)1 GBDeviceEventAppManagement (nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventAppManagement)1 GBDeviceEventAppMessage (nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventAppMessage)1 GBDeviceEventSendBytes (nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventSendBytes)1 GBDeviceEventVersionInfo (nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventVersionInfo)1 GBDeviceApp (nodomain.freeyourgadget.gadgetbridge.impl.GBDeviceApp)1 TransactionBuilder (nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder)1 MusicControlRequest (nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil_hr.music.MusicControlRequest)1 MUSIC_WATCH_REQUEST (nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil_hr.music.MusicControlRequest.MUSIC_WATCH_REQUEST)1 GBPrefs (nodomain.freeyourgadget.gadgetbridge.util.GBPrefs)1 Prefs (nodomain.freeyourgadget.gadgetbridge.util.Prefs)1 JSONException (org.json.JSONException)1