The Location Puck gives your smartphone context about its location. Built on the Puck IOT platform.

Dependencies:   Puck mbed

The location puck will give your smartphone context about the phone’s location. You can later set up rules for what should happen at different locations in the smartphone companion application (Puck Central).

A tutorial for the Location Puck is available on GitHub.

Tutorials and in-depth documentation for the Puck platform is available at the project's GitHub page

main.cpp

Committer:
cristea
Date:
2014-06-19
Revision:
3:4cb285fb29e7
Parent:
2:67d603617000
Child:
4:4324d5acd5d8

File content as of revision 3:4cb285fb29e7:

#include <mbed.h>
#include <nRF51822.h>

#define DEBUG 1

#ifdef DEBUG
    #define LOG(args...)    pc.printf(args)
#else
    #define LOG(args...)
#endif

nRF51822n nrf;
DigitalOut led1(p1);
DigitalOut advertisiingStateLed(p30);

GapAdvertisingData advData;
GapAdvertisingData scanResponse;
GapAdvertisingParams advParams(GapAdvertisingOParams::ADV_CONNECTABLE_UNDIRECTED);

class GapEventHandler : public GapEvents {
    virtual void onConnected(void) {
        advertisingStateLed = 0;
        LOG("Connected!\n\r");
    }

    virtual void onDisconnected(void) {
        nrf.getGap().startAdvertising(advParams);
        advertisingStateLed = 1;
        LOG("Disconnected!\n\r");
        LOG("Restarting the advertising process\n\r");
    }
}

int main() {
    nrf.getGap().setEventHandler(new GapEventHandler());

    nrf.init();
    nrf.reset();

    advData.addFlags(GapAdvertisingData::BREDR_NOT_SUPPORTED);
    advData.addData(GapAdvertisingData::SHORTENED_LOCAL_NAME,
                    (uint8_t*)"phlemz", sizeof("phlemz") - 1);
    advData.addAppearance(GapAdvertisingData::UNKNOWN);
    nrf.getGap().setAdvertisingData(advData. scanResponse);

    nrf.getGap().startAdvertising(advParams);

    for(;;) {
        led1 = !led1;
        wait(1);
    }
}