• Bangle GPS service for Kospet ROCK and Magic 3

    In a previous post I posted the image of a Bangle simulation environment for the ROCK and Magic3 watches. These watches have an NRF52840 processor and a large 240x280 screen which in the case of the ROCK is very bright.

    The image showed Wave Clock loaded directly from the BangleApp Loader as a demonstration of the Bangle emulation environment for the ROCK. However, this is very limited as many of the most interesting Bangle Apps use sensors such as GPS so following an idea suggested some time ago by @fanoush, I have implemented an App for the Bangle which provides a BLE service that makes the Bangle's GPS readings available externally.

    img

    Using this, the ROCK and Magic 3 can now run Bangle GPS apps loaded again directly from the App Loader. The Open Street Map App is shown below:

    img

    The interface to the GPS on the Bangle 1 & 2 is very narrow and that facilitates emulation. For interest, I include the full emulation code here:

    Bangle.setGPSPower = function(on){
        if (Bangle.gpsOn && on) return; //already started
        function unpack(v){
            var fix = v.getInt8(29);
            function ck(d) {return d==-1 ? NaN : d;}
            return {
              lat:ck(v.getFloat32(0)),
              lon:ck(v.getFloat32(4)),
              alt:ck(v.getFloat32(8)),
              speed:ck(v.getFloat32(12)),
              course:ck(v.getFloat32(16)),
              time:new Date(v.getFloat64(20)),
              satellites:v.getInt8(28),
              fix:fix,
              hdop:ck(v.getFloat32(30)),
            }
        }
        if (on) {
            Bangle.gpsOn=true;
            NRF.requestDevice({timeout:4000, filters: [{ name: 'gps' }] }).then(function(device) {
            //console.log("Found");
            return device.gatt.connect();
            }).then(function(g) {
                //console.log("Connected");
                Bangle.gpsgatt = g;
                return g.getPrimaryService("974e0001-1b9a-4468-­a83d-7f811b3dbaff");
            }).then(function(service) {
                return service.getCharacteristic("974e0002-1b9a­-4468-a83d-7f811b3dbaff");
            }).then(function (c) {
                Bangle.gpscharistic=c;
                //console.log("Got Characteristic");
                Bangle.gpsInterval = setInterval(function(){
                    Bangle.gpscharistic.readValue().then(fun­ction(d){
                        Bangle.gpsFix=unpack(d);
                        Bangle.emit("GPS",Bangle.gpsFix);
                    });
                },1000);
            }).catch(function(e){
                E.showMessage("GPS: "+e,"ERROR");
            });
        } else {
            Bangle.gpsOn=false;
            if (Bangle.gpsInterval) Bangle.gpsInterval = clearInterval(Bangle.gpsInterval);
            if(Bangle.gpsgatt) Bangle.gpsgatt.disconnect();
            delete Bangle.gpsgatt;
            delete Bangle.gpscharistic;
        }
    }
    
    Bangle.getGPSFix = function() {return Bangle.gpsFix;}
    

    The Bangle GPS server code can be found here.

    I have found the Bangle 1 GPS to be more sensitive than the Bangle 2, so it may be that if you have both Bangles, this may be of use. I have found the Bluetooth link between ROCK and Bangle really reliable and its no problem to carry the Bangle in a top pocket or a back pack.

About

Avatar for jeffmer @jeffmer started