Merge branch 'master' into ble-whitelisting
This commit is contained in:
commit
4f1870fda9
13 changed files with 592 additions and 528 deletions
|
@ -3,7 +3,7 @@
|
|||
|
||||
#include "mbed.h"
|
||||
|
||||
#include "MicroBitConfig.h"
|
||||
#include "MicroBitConfig.h"
|
||||
#include "MicroBitHeapAllocator.h"
|
||||
#include "MicroBitPanic.h"
|
||||
#include "ErrorNo.h"
|
||||
|
@ -12,7 +12,7 @@
|
|||
#include "MicroBitComponent.h"
|
||||
#include "ManagedType.h"
|
||||
#include "ManagedString.h"
|
||||
#include "MicroBitImage.h"
|
||||
#include "MicroBitImage.h"
|
||||
#include "MicroBitFont.h"
|
||||
#include "MicroBitEvent.h"
|
||||
#include "DynamicPwm.h"
|
||||
|
@ -59,16 +59,16 @@
|
|||
* Represents the device as a whole, and includes member variables to that reflect the components of the system.
|
||||
*/
|
||||
class MicroBit
|
||||
{
|
||||
{
|
||||
private:
|
||||
|
||||
|
||||
void seedRandom();
|
||||
void compassCalibrator(MicroBitEvent e);
|
||||
uint32_t randomValue;
|
||||
|
||||
|
||||
|
||||
public:
|
||||
|
||||
|
||||
// Map of device state.
|
||||
uint32_t flags;
|
||||
|
||||
|
@ -76,43 +76,43 @@ class MicroBit
|
|||
Ticker systemTicker;
|
||||
|
||||
// I2C Interface
|
||||
MicroBitI2C i2c;
|
||||
|
||||
MicroBitI2C i2c;
|
||||
|
||||
// Serial Interface
|
||||
MicroBitSerial serial;
|
||||
MicroBitSerial serial;
|
||||
|
||||
// Array of components which are iterated during a system tick
|
||||
MicroBitComponent* systemTickComponents[MICROBIT_SYSTEM_COMPONENTS];
|
||||
|
||||
|
||||
// Array of components which are iterated during idle thread execution, isIdleCallbackNeeded is polled during a systemTick.
|
||||
MicroBitComponent* idleThreadComponents[MICROBIT_IDLE_COMPONENTS];
|
||||
|
||||
// Device level Message Bus abstraction
|
||||
MicroBitMessageBus MessageBus;
|
||||
|
||||
MicroBitMessageBus MessageBus;
|
||||
|
||||
// Member variables to represent each of the core components on the device.
|
||||
MicroBitDisplay display;
|
||||
MicroBitButton buttonA;
|
||||
MicroBitButton buttonB;
|
||||
MicroBitMultiButton buttonAB;
|
||||
MicroBitMultiButton buttonAB;
|
||||
MicroBitAccelerometer accelerometer;
|
||||
MicroBitCompass compass;
|
||||
MicroBitThermometer thermometer;
|
||||
|
||||
//An object of available IO pins on the device
|
||||
MicroBitIO io;
|
||||
|
||||
|
||||
// Bluetooth related member variables.
|
||||
MicroBitBLEManager bleManager;
|
||||
BLEDevice *ble;
|
||||
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
* Constructor.
|
||||
* Create a representation of a MicroBit device as a global singleton.
|
||||
* @param messageBus callback function to receive MicroBitMessageBus events.
|
||||
*
|
||||
* Exposed objects:
|
||||
* @code
|
||||
* @code
|
||||
* uBit.systemTicker; //the Ticker callback that performs routines like updating the display.
|
||||
* uBit.MessageBus; //The message bus where events are fired.
|
||||
* uBit.display; //The display object for the LED matrix.
|
||||
|
@ -124,16 +124,16 @@ class MicroBit
|
|||
* uBit.io.P*; //Where P* is P0 to P16, P19 & P20 on the edge connector
|
||||
* @endcode
|
||||
*/
|
||||
MicroBit();
|
||||
MicroBit();
|
||||
|
||||
/**
|
||||
* Post constructor initialisation method.
|
||||
* After *MUCH* pain, it's noted that the BLE stack can't be brought up in a
|
||||
* After *MUCH* pain, it's noted that the BLE stack can't be brought up in a
|
||||
* static context, so we bring it up here rather than in the constructor.
|
||||
* n.b. This method *must* be called in main() or later, not before.
|
||||
*
|
||||
* Example:
|
||||
* @code
|
||||
* @code
|
||||
* uBit.init();
|
||||
* @endcode
|
||||
*/
|
||||
|
@ -157,7 +157,7 @@ class MicroBit
|
|||
* Will reset the micro:bit when called.
|
||||
*
|
||||
* Example:
|
||||
* @code
|
||||
* @code
|
||||
* uBit.reset();
|
||||
* @endcode
|
||||
*/
|
||||
|
@ -168,15 +168,15 @@ class MicroBit
|
|||
* If the scheduler is running, this will deschedule the current fiber and perform
|
||||
* a power efficent, concurrent sleep operation.
|
||||
* If the scheduler is disabled or we're running in an interrupt context, this
|
||||
* will revert to a busy wait.
|
||||
*
|
||||
* will revert to a busy wait.
|
||||
*
|
||||
* @note Values of 6 and below tend to lose resolution - do you really need to sleep for this short amount of time?
|
||||
*
|
||||
* @param milliseconds the amount of time, in ms, to wait for. This number cannot be negative.
|
||||
* @return MICROBIT_OK on success, MICROBIT_INVALID_PARAMETER milliseconds is less than zero.
|
||||
* @return MICROBIT_OK on success, MICROBIT_INVALID_PARAMETER milliseconds is less than zero.
|
||||
*
|
||||
* Example:
|
||||
* @code
|
||||
* @code
|
||||
* uBit.sleep(20); //sleep for 20ms
|
||||
* @endcode
|
||||
*/
|
||||
|
@ -191,7 +191,7 @@ class MicroBit
|
|||
* @return A random, natural number between 0 and the max-1. Or MICROBIT_INVALID_PARAMETER if max is <= 0.
|
||||
*
|
||||
* Example:
|
||||
* @code
|
||||
* @code
|
||||
* uBit.random(200); //a number between 0 and 199
|
||||
* @endcode
|
||||
*/
|
||||
|
@ -202,27 +202,27 @@ class MicroBit
|
|||
* provide a power efficient sense of time.
|
||||
*/
|
||||
void systemTick();
|
||||
|
||||
|
||||
/**
|
||||
* System tasks to be executed by the idle thread when the Micro:Bit isn't busy or when data needs to be read.
|
||||
*/
|
||||
void systemTasks();
|
||||
|
||||
/**
|
||||
* add a component to the array of system components which invocate the systemTick member function during a systemTick
|
||||
* add a component to the array of system components which invocate the systemTick member function during a systemTick
|
||||
*
|
||||
* @param component The component to add.
|
||||
* @return MICROBIT_OK on success. MICROBIT_NO_RESOURCES is returned if further components cannot be supported.
|
||||
*/
|
||||
int addSystemComponent(MicroBitComponent *component);
|
||||
|
||||
|
||||
/**
|
||||
* remove a component from the array of system components
|
||||
* @param component The component to remove.
|
||||
* @return MICROBIT_OK on success. MICROBIT_INVALID_PARAMETER is returned if the given component has not been previous added.
|
||||
*/
|
||||
int removeSystemComponent(MicroBitComponent *component);
|
||||
|
||||
|
||||
/**
|
||||
* add a component to the array of of idle thread components.
|
||||
* isIdleCallbackNeeded is polled during a systemTick to determine if the idle thread should jump to the front of the queue
|
||||
|
@ -230,7 +230,7 @@ class MicroBit
|
|||
* @return MICROBIT_OK on success. MICROBIT_NO_RESOURCES is returned if further components cannot be supported.
|
||||
*/
|
||||
int addIdleComponent(MicroBitComponent *component);
|
||||
|
||||
|
||||
/**
|
||||
* remove a component from the array of idle thread components
|
||||
* @param component The component to remove.
|
||||
|
@ -245,7 +245,7 @@ class MicroBit
|
|||
* TODO: handle overflow case.
|
||||
*/
|
||||
unsigned long systemTime();
|
||||
|
||||
|
||||
/**
|
||||
* Determine the version of the micro:bit runtime currently in use.
|
||||
*
|
||||
|
@ -256,7 +256,7 @@ class MicroBit
|
|||
|
||||
/**
|
||||
* Triggers a microbit panic where an infinite loop will occur swapping between the panicFace and statusCode if provided.
|
||||
*
|
||||
*
|
||||
* @param statusCode the status code of the associated error. Status codes must be in the range 0-255.
|
||||
*/
|
||||
void panic(int statusCode = 0);
|
||||
|
@ -274,4 +274,3 @@ extern "C" void app_main();
|
|||
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -57,7 +57,7 @@
|
|||
#define MICROBIT_ACCELEROMETER_EVT_FACE_UP 5
|
||||
#define MICROBIT_ACCELEROMETER_EVT_FACE_DOWN 6
|
||||
#define MICROBIT_ACCELEROMETER_EVT_FREEFALL 7
|
||||
#define MICROBIT_ACCELEROMETER_EVT_3G 8
|
||||
#define MICROBIT_ACCELEROMETER_EVT_3G 8
|
||||
#define MICROBIT_ACCELEROMETER_EVT_6G 9
|
||||
#define MICROBIT_ACCELEROMETER_EVT_8G 10
|
||||
#define MICROBIT_ACCELEROMETER_EVT_SHAKE 11
|
||||
|
@ -140,10 +140,10 @@ struct ShakeHistory
|
|||
class MicroBitAccelerometer : public MicroBitComponent
|
||||
{
|
||||
/**
|
||||
* Unique, enumerated ID for this component.
|
||||
* Unique, enumerated ID for this component.
|
||||
* Used to track asynchronous events in the event bus.
|
||||
*/
|
||||
|
||||
|
||||
uint16_t address; // I2C address of this accelerometer.
|
||||
uint16_t samplePeriod; // The time between samples, in milliseconds.
|
||||
uint8_t sampleRange; // The sample range of the accelerometer in g.
|
||||
|
@ -152,20 +152,20 @@ class MicroBitAccelerometer : public MicroBitComponent
|
|||
float pitch; // Pitch of the device, in radians.
|
||||
float roll; // Roll of the device, in radians.
|
||||
uint8_t sigma; // the number of ticks that the instantaneous gesture has been stable.
|
||||
BasicGesture lastGesture; // the last, stable gesture recorded.
|
||||
BasicGesture lastGesture; // the last, stable gesture recorded.
|
||||
BasicGesture currentGesture; // the instantaneous, unfiltered gesture detected.
|
||||
ShakeHistory shake; // State information needed to detect shake events.
|
||||
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
* Constructor.
|
||||
* Create an accelerometer representation with the given ID.
|
||||
* @param id the ID of the new object.
|
||||
* @param address the default base address of the accelerometer.
|
||||
* @param address the default base address of the accelerometer.
|
||||
*
|
||||
* Example:
|
||||
* @code
|
||||
* @code
|
||||
* accelerometer(MICROBIT_ID_ACCELEROMETER, MMA8653_DEFAULT_ADDR)
|
||||
* @endcode
|
||||
*/
|
||||
|
@ -199,7 +199,7 @@ class MicroBitAccelerometer : public MicroBitComponent
|
|||
int setPeriod(int period);
|
||||
|
||||
/**
|
||||
* Reads the currently configured sample rate of the accelerometer.
|
||||
* Reads the currently configured sample rate of the accelerometer.
|
||||
* @return The time between samples, in milliseconds.
|
||||
*/
|
||||
int getPeriod();
|
||||
|
@ -214,17 +214,17 @@ class MicroBitAccelerometer : public MicroBitComponent
|
|||
int setRange(int range);
|
||||
|
||||
/**
|
||||
* Reads the currently configured sample range of the accelerometer.
|
||||
* Reads the currently configured sample range of the accelerometer.
|
||||
* @return The sample range, in g.
|
||||
*/
|
||||
int getRange();
|
||||
|
||||
/**
|
||||
* Attempts to determine the 8 bit ID from the accelerometer.
|
||||
* Attempts to determine the 8 bit ID from the accelerometer.
|
||||
* @return the 8 bit ID returned by the accelerometer, or MICROBIT_I2C_ERROR if the request fails.
|
||||
*
|
||||
* Example:
|
||||
* @code
|
||||
* @code
|
||||
* uBit.accelerometer.whoAmI();
|
||||
* @endcode
|
||||
*/
|
||||
|
@ -236,32 +236,32 @@ class MicroBitAccelerometer : public MicroBitComponent
|
|||
* @return The force measured in the X axis, in milli-g.
|
||||
*
|
||||
* Example:
|
||||
* @code
|
||||
* @code
|
||||
* uBit.accelerometer.getX();
|
||||
* @endcode
|
||||
*/
|
||||
int getX(MicroBitCoordinateSystem system = SIMPLE_CARTESIAN);
|
||||
|
||||
|
||||
/**
|
||||
* Reads the Y axis value of the latest update from the accelerometer.
|
||||
* @return The force measured in the Y axis, in milli-g.
|
||||
*
|
||||
* Example:
|
||||
* @code
|
||||
* @code
|
||||
* uBit.accelerometer.getY();
|
||||
* @endcode
|
||||
*/
|
||||
*/
|
||||
int getY(MicroBitCoordinateSystem system = SIMPLE_CARTESIAN);
|
||||
|
||||
|
||||
/**
|
||||
* Reads the Z axis value of the latest update from the accelerometer.
|
||||
* @return The force measured in the Z axis, in milli-g.
|
||||
*
|
||||
* Example:
|
||||
* @code
|
||||
* @code
|
||||
* uBit.accelerometer.getZ();
|
||||
* @endcode
|
||||
*/
|
||||
*/
|
||||
int getZ(MicroBitCoordinateSystem system = SIMPLE_CARTESIAN);
|
||||
|
||||
/**
|
||||
|
@ -269,10 +269,10 @@ class MicroBitAccelerometer : public MicroBitComponent
|
|||
* @return The pitch of the device, in degrees.
|
||||
*
|
||||
* Example:
|
||||
* @code
|
||||
* @code
|
||||
* uBit.accelerometer.getPitch();
|
||||
* @endcode
|
||||
*/
|
||||
*/
|
||||
int getPitch();
|
||||
float getPitchRadians();
|
||||
|
||||
|
@ -281,10 +281,10 @@ class MicroBitAccelerometer : public MicroBitComponent
|
|||
* @return The roll of the device, in degrees.
|
||||
*
|
||||
* Example:
|
||||
* @code
|
||||
* @code
|
||||
* uBit.accelerometer.getRoll();
|
||||
* @endcode
|
||||
*/
|
||||
*/
|
||||
int getRoll();
|
||||
float getRollRadians();
|
||||
|
||||
|
@ -293,16 +293,16 @@ class MicroBitAccelerometer : public MicroBitComponent
|
|||
* @return The last gesture detected.
|
||||
*
|
||||
* Example:
|
||||
* @code
|
||||
* @code
|
||||
* if (uBit.accelerometer.getGesture() == SHAKE)
|
||||
* @endcode
|
||||
*/
|
||||
*/
|
||||
BasicGesture getGesture();
|
||||
|
||||
/**
|
||||
* periodic callback from MicroBit idle thread.
|
||||
* Check if any data is ready for reading by checking the interrupt flag on the accelerometer
|
||||
*/
|
||||
*/
|
||||
virtual void idleTick();
|
||||
|
||||
/**
|
||||
|
@ -310,6 +310,11 @@ class MicroBitAccelerometer : public MicroBitComponent
|
|||
*/
|
||||
virtual int isIdleCallbackNeeded();
|
||||
|
||||
/**
|
||||
* Destructor for MicroBitButton, so that we deregister ourselves as an idleComponent
|
||||
*/
|
||||
~MicroBitAccelerometer();
|
||||
|
||||
private:
|
||||
/**
|
||||
* Issues a standard, 2 byte I2C command write to the accelerometer.
|
||||
|
@ -341,7 +346,7 @@ class MicroBitAccelerometer : public MicroBitComponent
|
|||
|
||||
/**
|
||||
*
|
||||
* Updates the basic gesture recognizer. This performs instantaneous pose recognition, and also some low pass filtering to promote
|
||||
* Updates the basic gesture recognizer. This performs instantaneous pose recognition, and also some low pass filtering to promote
|
||||
* stability.
|
||||
*/
|
||||
void updateGesture();
|
||||
|
|
|
@ -17,8 +17,8 @@
|
|||
#define MICROBIT_BUTTON_EVT_HOLD 5
|
||||
#define MICROBIT_BUTTON_EVT_DOUBLE_CLICK 6
|
||||
|
||||
#define MICROBIT_BUTTON_LONG_CLICK_TIME 1000
|
||||
#define MICROBIT_BUTTON_HOLD_TIME 1500
|
||||
#define MICROBIT_BUTTON_LONG_CLICK_TIME 1000
|
||||
#define MICROBIT_BUTTON_HOLD_TIME 1500
|
||||
|
||||
#define MICROBIT_BUTTON_STATE 1
|
||||
#define MICROBIT_BUTTON_STATE_HOLD_TRIGGERED 2
|
||||
|
@ -47,27 +47,27 @@ class MicroBitButton : public MicroBitComponent
|
|||
{
|
||||
PinName name; // mbed pin name of this pin.
|
||||
DigitalIn pin; // The mbed object looking after this pin at any point in time (may change!).
|
||||
|
||||
|
||||
unsigned long downStartTime; // used to store the current system clock when a button down event occurs
|
||||
uint8_t sigma; // integration of samples over time. We use this for debouncing, and noise tolerance for touch sensing
|
||||
MicroBitButtonEventConfiguration eventConfiguration; // Do we want to generate high level event (clicks), or defer this to another service.
|
||||
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
* Constructor.
|
||||
* Create a pin representation with the given ID.
|
||||
* @param id the ID of the new MicroBitButton object.
|
||||
* @param name the physical pin on the processor that this butotn is connected to.
|
||||
* @param mode the configuration of internal pullups/pulldowns, as define in the mbed PinMode class. PullNone by default.
|
||||
*
|
||||
* Example:
|
||||
* @code
|
||||
* @code
|
||||
* buttonA(MICROBIT_ID_BUTTON_A,MICROBIT_PIN_BUTTON_A); //a number between 0 and 200 inclusive
|
||||
* @endcode
|
||||
*
|
||||
* Possible Events:
|
||||
* @code
|
||||
* @code
|
||||
* MICROBIT_BUTTON_EVT_DOWN
|
||||
* MICROBIT_BUTTON_EVT_UP
|
||||
* MICROBIT_BUTTON_EVT_CLICK
|
||||
|
@ -77,25 +77,29 @@ class MicroBitButton : public MicroBitComponent
|
|||
* @endcode
|
||||
*/
|
||||
MicroBitButton(uint16_t id, PinName name, MicroBitButtonEventConfiguration eventConfiguration = MICROBIT_BUTTON_ALL_EVENTS, PinMode mode = PullNone);
|
||||
|
||||
|
||||
/**
|
||||
* Tests if this Button is currently pressed.
|
||||
* @return 1 if this button is pressed, 0 otherwise.
|
||||
*
|
||||
* Example:
|
||||
* @code
|
||||
* @code
|
||||
* if(uBit.buttonA.isPressed())
|
||||
* print("Pressed!");
|
||||
* @endcode
|
||||
*/
|
||||
int isPressed();
|
||||
|
||||
|
||||
/**
|
||||
* periodic callback from MicroBit clock.
|
||||
* Check for state change for this button, and fires a hold event if button is pressed.
|
||||
*/
|
||||
*/
|
||||
virtual void systemTick();
|
||||
|
||||
|
||||
/**
|
||||
* Destructor for MicroBitButton, so that we deregister ourselves as a systemComponent
|
||||
*/
|
||||
~MicroBitButton();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -48,7 +48,7 @@ struct MAG3110SampleRateConfig
|
|||
|
||||
extern const MAG3110SampleRateConfig MAG3110SampleRate[];
|
||||
|
||||
#define MAG3110_SAMPLE_RATES 11
|
||||
#define MAG3110_SAMPLE_RATES 11
|
||||
|
||||
/*
|
||||
* Compass events
|
||||
|
@ -66,7 +66,7 @@ extern const MAG3110SampleRateConfig MAG3110SampleRate[];
|
|||
*/
|
||||
#define MICROBIT_COMPASS_STATUS_CALIBRATED 1
|
||||
#define MICROBIT_COMPASS_STATUS_CALIBRATING 2
|
||||
|
||||
|
||||
/*
|
||||
* Term to convert sample data into SI units
|
||||
*/
|
||||
|
@ -83,19 +83,19 @@ struct CompassSample
|
|||
int x;
|
||||
int y;
|
||||
int z;
|
||||
|
||||
|
||||
CompassSample()
|
||||
{
|
||||
this->x = 0;
|
||||
this->y = 0;
|
||||
this->z = 0;
|
||||
this->z = 0;
|
||||
}
|
||||
|
||||
CompassSample(int x, int y, int z)
|
||||
{
|
||||
this->x = x;
|
||||
this->y = y;
|
||||
this->z = z;
|
||||
this->z = z;
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -108,11 +108,11 @@ struct CompassSample
|
|||
class MicroBitCompass : public MicroBitComponent
|
||||
{
|
||||
/**
|
||||
* Unique, enumerated ID for this component.
|
||||
* Unique, enumerated ID for this component.
|
||||
* Used to track asynchronous events in the event bus.
|
||||
*/
|
||||
|
||||
uint16_t address; // I2C address of the magnetmometer.
|
||||
|
||||
uint16_t address; // I2C address of the magnetmometer.
|
||||
uint16_t samplePeriod; // The time between samples, in millseconds.
|
||||
|
||||
CompassSample average; // Centre point of sample data.
|
||||
|
@ -120,9 +120,9 @@ class MicroBitCompass : public MicroBitComponent
|
|||
DigitalIn int1; // Data ready interrupt.
|
||||
|
||||
public:
|
||||
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
* Constructor.
|
||||
* Create a compass representation with the given ID.
|
||||
* @param id the event ID of the compass object.
|
||||
* @param address the default address for the compass register
|
||||
|
@ -140,7 +140,7 @@ class MicroBitCompass : public MicroBitComponent
|
|||
* @endcode
|
||||
*/
|
||||
MicroBitCompass(uint16_t id, uint16_t address);
|
||||
|
||||
|
||||
/**
|
||||
* Configures the compass for the sample rate defined
|
||||
* in this object. The nearest values are chosen to those defined
|
||||
|
@ -160,7 +160,7 @@ class MicroBitCompass : public MicroBitComponent
|
|||
int setPeriod(int period);
|
||||
|
||||
/**
|
||||
* Reads the currently configured sample rate of the compass.
|
||||
* Reads the currently configured sample rate of the compass.
|
||||
* @return The time between samples, in milliseconds.
|
||||
*/
|
||||
int getPeriod();
|
||||
|
@ -169,10 +169,10 @@ class MicroBitCompass : public MicroBitComponent
|
|||
* Gets the current heading of the device, relative to magnetic north.
|
||||
* If the compass is not calibrated, it will raise the MICROBIT_COMPASS_EVT_CALIBRATE event.
|
||||
* Users wishing to implement their own calibration algorithms should listen for this event,
|
||||
* using MESSAGE_BUS_LISTENER_IMMEDIATE model. This ensures that calibration is complete before
|
||||
* the user program continues.
|
||||
*
|
||||
* @return the current heading, in degrees. Or MICROBIT_CALIBRATION_IN_PROGRESS if the compass is calibrating.
|
||||
* using MESSAGE_BUS_LISTENER_IMMEDIATE model. This ensures that calibration is complete before
|
||||
* the user program continues.
|
||||
*
|
||||
* @return the current heading, in degrees. Or MICROBIT_CALIBRATION_IN_PROGRESS if the compass is calibrating.
|
||||
*
|
||||
* Example:
|
||||
* @code
|
||||
|
@ -182,7 +182,7 @@ class MicroBitCompass : public MicroBitComponent
|
|||
int heading();
|
||||
|
||||
/**
|
||||
* Attempts to determine the 8 bit ID from the magnetometer.
|
||||
* Attempts to determine the 8 bit ID from the magnetometer.
|
||||
* @return the id of the compass (magnetometer), or MICROBIT_I2C_ERROR if the magnetometer could not be updated.
|
||||
*
|
||||
* Example:
|
||||
|
@ -202,7 +202,7 @@ class MicroBitCompass : public MicroBitComponent
|
|||
* @endcode
|
||||
*/
|
||||
int getX(MicroBitCoordinateSystem system = SIMPLE_CARTESIAN);
|
||||
|
||||
|
||||
/**
|
||||
* Reads the Y axis value of the latest update from the compass.
|
||||
* @return The magnetic force measured in the Y axis, in nano teslas.
|
||||
|
@ -211,9 +211,9 @@ class MicroBitCompass : public MicroBitComponent
|
|||
* @code
|
||||
* uBit.compass.getY();
|
||||
* @endcode
|
||||
*/
|
||||
*/
|
||||
int getY(MicroBitCoordinateSystem system = SIMPLE_CARTESIAN);
|
||||
|
||||
|
||||
/**
|
||||
* Reads the Z axis value of the latest update from the compass.
|
||||
* @return The magnetic force measured in the Z axis, in nano teslas.
|
||||
|
@ -222,8 +222,8 @@ class MicroBitCompass : public MicroBitComponent
|
|||
* @code
|
||||
* uBit.compass.getZ();
|
||||
* @endcode
|
||||
*/
|
||||
int getZ(MicroBitCoordinateSystem system = SIMPLE_CARTESIAN);
|
||||
*/
|
||||
int getZ(MicroBitCoordinateSystem system = SIMPLE_CARTESIAN);
|
||||
|
||||
/**
|
||||
* Determines the overall magnetic field strength based on the latest update from the compass.
|
||||
|
@ -233,21 +233,21 @@ class MicroBitCompass : public MicroBitComponent
|
|||
* @code
|
||||
* uBit.compass.getFieldStrength();
|
||||
* @endcode
|
||||
*/
|
||||
*/
|
||||
int getFieldStrength();
|
||||
|
||||
/**
|
||||
* Reads the current die temperature of the compass.
|
||||
* Reads the current die temperature of the compass.
|
||||
* @return the temperature in degrees celsius, or MICROBIT_I2C_ERROR if the magnetometer could not be updated.
|
||||
*/
|
||||
int readTemperature();
|
||||
|
||||
/**
|
||||
* Perform a calibration of the compass.
|
||||
*
|
||||
*
|
||||
* This method will be called automatically if a user attempts to read a compass value when
|
||||
* the compass is uncalibrated. It can also be called at any time by the user.
|
||||
*
|
||||
*
|
||||
* Any old calibration data is deleted.
|
||||
* The method will only return once the compass has been calibrated.
|
||||
*
|
||||
|
@ -265,7 +265,7 @@ class MicroBitCompass : public MicroBitComponent
|
|||
* @note *** THIS FUNCITON IS NOW DEPRECATED AND WILL BE REMOVED IN THE NEXT MAJOR RELEASE ***
|
||||
* @note *** PLEASE USE THE calibrate() FUNCTION INSTEAD ***
|
||||
*/
|
||||
void calibrateAsync();
|
||||
void calibrateAsync();
|
||||
|
||||
/**
|
||||
* Perform a calibration of the compass.
|
||||
|
@ -274,62 +274,67 @@ class MicroBitCompass : public MicroBitComponent
|
|||
* @note *** THIS FUNCITON IS NOW DEPRECATED AND WILL BE REMOVED IN THE NEXT MAJOR RELEASE ***
|
||||
* @note *** PLEASE USE THE calibrate() FUNCTION INSTEAD ***
|
||||
*/
|
||||
int calibrateStart();
|
||||
int calibrateStart();
|
||||
|
||||
/**
|
||||
* Complete the calibration of the compass.
|
||||
* This will fire MICROBIT_COMPASS_EVT_CAL_END.
|
||||
*
|
||||
* @note *** THIS FUNCITON IS NOW DEPRECATED AND WILL BE REMOVED IN THE NEXT MAJOR RELEASE ***
|
||||
*/
|
||||
void calibrateEnd();
|
||||
*/
|
||||
void calibrateEnd();
|
||||
|
||||
/**
|
||||
* Configure the compass to use the given calibration data.
|
||||
* Calibration data is comprised of the perceived zero offset of each axis of the compass.
|
||||
* After calibration this should now take into account trimming errors in the magnetometer,
|
||||
* After calibration this should now take into account trimming errors in the magnetometer,
|
||||
* and any "hard iron" offsets on the device.
|
||||
*
|
||||
* @param The x, y and z zero offsets to use as calibration data.
|
||||
*/
|
||||
*/
|
||||
void setCalibration(CompassSample calibration);
|
||||
|
||||
/**
|
||||
* Provides the calibration data currently in use by the compass.
|
||||
* More specifically, the x, y and z zero offsets of the compass.
|
||||
*
|
||||
* @return The x, y and z xero offsets of the compass.
|
||||
*/
|
||||
* @return The x, y and z xero offsets of the compass.
|
||||
*/
|
||||
CompassSample getCalibration();
|
||||
|
||||
/**
|
||||
* Periodic callback from MicroBit idle thread.
|
||||
* Check if any data is ready for reading by checking the interrupt.
|
||||
*/
|
||||
*/
|
||||
virtual void idleTick();
|
||||
|
||||
|
||||
/**
|
||||
* Returns 0 or 1. 1 indicates that the compass is calibrated, zero means the compass requires calibration.
|
||||
*/
|
||||
int isCalibrated();
|
||||
|
||||
|
||||
/**
|
||||
* Returns 0 or 1. 1 indicates that the compass is calibrating, zero means the compass is not currently calibrating.
|
||||
*/
|
||||
int isCalibrating();
|
||||
|
||||
|
||||
/**
|
||||
* Clears the calibration held in persistent storage, and sets the calibrated flag to zero.
|
||||
*/
|
||||
void clearCalibration();
|
||||
|
||||
|
||||
/**
|
||||
* Returns 0 or 1. 1 indicates data is waiting to be read, zero means data is not ready to be read.
|
||||
*/
|
||||
virtual int isIdleCallbackNeeded();
|
||||
|
||||
|
||||
/**
|
||||
* Destructor for MicroBitCompass, so that we deregister ourselves as an idleComponent
|
||||
*/
|
||||
~MicroBitCompass();
|
||||
|
||||
private:
|
||||
|
||||
|
||||
/**
|
||||
* Issues a standard, 2 byte I2C command write to the magnetometer.
|
||||
* Blocks the calling thread until complete.
|
||||
|
@ -339,7 +344,7 @@ class MicroBitCompass : public MicroBitComponent
|
|||
* @return MICROBIT_OK on success, MICROBIT_I2C_ERROR if the magnetometer could not be accessed.
|
||||
*/
|
||||
int writeCommand(uint8_t reg, uint8_t value);
|
||||
|
||||
|
||||
/**
|
||||
* Issues a read command into the specified buffer.
|
||||
* Blocks the calling thread until complete.
|
||||
|
@ -350,7 +355,7 @@ class MicroBitCompass : public MicroBitComponent
|
|||
* @return MICROBIT_OK on success, MICROBIT_INVALID_PARAMETER or MICROBIT_I2C_ERROR if the magnetometer could not be accessed.
|
||||
*/
|
||||
int readCommand(uint8_t reg, uint8_t* buffer, int length);
|
||||
|
||||
|
||||
/**
|
||||
* Issues a read of a given address, and returns the value.
|
||||
* Blocks the calling thread until complete.
|
||||
|
@ -359,8 +364,8 @@ class MicroBitCompass : public MicroBitComponent
|
|||
* @return The register value, interpreted as a 16 but signed value, or MICROBIT_I2C_ERROR if the magnetometer could not be accessed.
|
||||
*/
|
||||
int read16(uint8_t reg);
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Issues a read of a given address, and returns the value.
|
||||
* Blocks the calling thread until complete.
|
||||
|
|
|
@ -73,7 +73,7 @@ enum AnimationMode {
|
|||
|
||||
enum DisplayMode {
|
||||
DISPLAY_MODE_BLACK_AND_WHITE,
|
||||
DISPLAY_MODE_GREYSCALE
|
||||
DISPLAY_MODE_GREYSCALE
|
||||
};
|
||||
|
||||
enum DisplayRotation {
|
||||
|
@ -172,24 +172,24 @@ class MicroBitDisplay : public MicroBitComponent
|
|||
* Periodic callback, that we use to perform any animations we have running.
|
||||
*/
|
||||
void animationUpdate();
|
||||
|
||||
|
||||
/**
|
||||
* Called by the display in an interval determined by the brightness of the display, to give an impression
|
||||
* of brightness.
|
||||
*/
|
||||
void renderFinish();
|
||||
|
||||
|
||||
/**
|
||||
* Translates a bit mask to a bit mask suitable for the nrf PORT0 and PORT1.
|
||||
* Brightness has two levels on, or off.
|
||||
*/
|
||||
void render();
|
||||
|
||||
|
||||
/**
|
||||
* Translates a bit mask into a timer interrupt that gives the appearence of greyscale.
|
||||
*/
|
||||
void renderGreyscale();
|
||||
|
||||
|
||||
/**
|
||||
* Internal scrollText update method.
|
||||
* Shift the screen image by one pixel to the left. If necessary, paste in the next char.
|
||||
|
@ -224,7 +224,7 @@ class MicroBitDisplay : public MicroBitComponent
|
|||
/**
|
||||
* Blocks the current fiber until the display is available (i.e. not effect is being displayed).
|
||||
* Animations are queued until their time to display.
|
||||
*/
|
||||
*/
|
||||
void waitForFreeDisplay();
|
||||
|
||||
public:
|
||||
|
@ -255,16 +255,16 @@ public:
|
|||
* Frame update method, invoked periodically to strobe the display.
|
||||
*/
|
||||
virtual void systemTick();
|
||||
|
||||
|
||||
/**
|
||||
* Prints the given character to the display, if it is not in use.
|
||||
*
|
||||
* @param c The character to display.
|
||||
* @param delay Optional parameter - the time for which to show the character. Zero displays the character forever.
|
||||
* @return MICROBIT_OK, MICROBIT_BUSY is the screen is in use, or MICROBIT_INVALID_PARAMETER.
|
||||
*
|
||||
*
|
||||
* Example:
|
||||
* @code
|
||||
* @code
|
||||
* uBit.display.printAsync('p');
|
||||
* uBit.display.printAsync('p',100);
|
||||
* @endcode
|
||||
|
@ -294,7 +294,7 @@ public:
|
|||
* @param i The image to display.
|
||||
* @param x The horizontal position on the screen to display the image (default 0)
|
||||
* @param y The vertical position on the screen to display the image (default 0)
|
||||
* @param alpha Treats the brightness level '0' as transparent (default 0)
|
||||
* @param alpha Treats the brightness level '0' as transparent (default 0)
|
||||
* @param delay The time to delay between characters, in milliseconds. set to 0 to display forever. (default 0).
|
||||
*
|
||||
* Example:
|
||||
|
@ -334,7 +334,7 @@ public:
|
|||
* @endcode
|
||||
*/
|
||||
int print(ManagedString s, int delay = MICROBIT_DEFAULT_PRINT_SPEED);
|
||||
|
||||
|
||||
/**
|
||||
* Prints the given image to the display.
|
||||
* Blocks the calling thread until all the text has been displayed.
|
||||
|
@ -350,7 +350,7 @@ public:
|
|||
* @endcode
|
||||
*/
|
||||
int print(MicroBitImage i, int x, int y, int alpha, int delay = 0);
|
||||
|
||||
|
||||
/**
|
||||
* Scrolls the given string to the display, from right to left.
|
||||
* Uses the given delay between characters.
|
||||
|
@ -474,14 +474,14 @@ public:
|
|||
/**
|
||||
* Sets the mode of the display.
|
||||
* @param mode The mode to swap the display into. (can be either DISPLAY_MODE_GREYSCALE, or DISPLAY_MODE_NORMAL)
|
||||
*
|
||||
*
|
||||
* Example:
|
||||
* @code
|
||||
* @code
|
||||
* uBit.display.setDisplayMode(DISPLAY_MODE_GREYSCALE); //per pixel brightness
|
||||
* @endcode
|
||||
*/
|
||||
*/
|
||||
void setDisplayMode(DisplayMode mode);
|
||||
|
||||
|
||||
/**
|
||||
* Fetches the current brightness of this display.
|
||||
* @return the brightness of this display, in the range 0..255.
|
||||
|
@ -557,12 +557,16 @@ public:
|
|||
* Retreives the font object used for rendering characters on the display.
|
||||
*/
|
||||
MicroBitFont getFont();
|
||||
|
||||
|
||||
/**
|
||||
* Captures the bitmap currently being rendered on the display.
|
||||
*/
|
||||
MicroBitImage screenShot();
|
||||
|
||||
/**
|
||||
* Destructor for MicroBitDisplay, so that we deregister ourselves as a systemComponent
|
||||
*/
|
||||
~MicroBitDisplay();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
* MicroBit platform. It serves a number of purposes:
|
||||
*
|
||||
* 1) It provides an eventing abstraction that is independent of the underlying substrate.
|
||||
* 2) It provides a mechanism to decouple user code from trusted system code
|
||||
* 2) It provides a mechanism to decouple user code from trusted system code
|
||||
* i.e. the basis of a message passing nano kernel.
|
||||
* 3) It allows a common high level eventing abstraction across a range of hardware types.e.g. buttons, BLE...
|
||||
* 4) It provides a mechanims for extensibility - new devices added via I/O pins can have OO based
|
||||
|
@ -34,23 +34,23 @@ class MicroBitMessageBus : public MicroBitComponent
|
|||
public:
|
||||
|
||||
/**
|
||||
* Default constructor.
|
||||
* Default constructor.
|
||||
* Anticipating only one MessageBus per device, as filtering is handled within the class.
|
||||
*/
|
||||
MicroBitMessageBus();
|
||||
MicroBitMessageBus();
|
||||
|
||||
/**
|
||||
* Queues the given event to be sent to all registered recipients.
|
||||
*
|
||||
* @param The event to send.
|
||||
* @param The event to send.
|
||||
*
|
||||
* n.b. THIS IS NOW WRAPPED BY THE MicroBitEvent CLASS FOR CONVENIENCE...
|
||||
*
|
||||
* Example:
|
||||
* @code
|
||||
* @code
|
||||
* MicroBitEvent evt(id,MICROBIT_BUTTON_EVT_DOWN,ticks,false);
|
||||
* evt.fire();
|
||||
* //OR YOU CAN DO THIS...
|
||||
* //OR YOU CAN DO THIS...
|
||||
* MicroBitEvent evt(id,MICROBIT_BUTTON_EVT_DOWN);
|
||||
* @endcode
|
||||
*/
|
||||
|
@ -63,7 +63,7 @@ class MicroBitMessageBus : public MicroBitComponent
|
|||
* IT IS RECOMMENDED THAT ALL EXTERNAL CODE USE THE send() FUNCTIONS INSTEAD OF THIS FUNCTION,
|
||||
* or the constructors provided by MicroBitEvent.
|
||||
*
|
||||
* @param evt The event to send.
|
||||
* @param evt The event to send.
|
||||
* @param urgent The type of listeners to process (optional). If set to true, only listeners defined as urgent and non-blocking will be processed
|
||||
* otherwise, all other (standard) listeners will be processed.
|
||||
* @return 1 if all matching listeners were processed, 0 if further processing is required.
|
||||
|
@ -72,19 +72,19 @@ class MicroBitMessageBus : public MicroBitComponent
|
|||
|
||||
/**
|
||||
* Register a listener function.
|
||||
*
|
||||
* @param id The source of messages to listen for. Events sent from any other IDs will be filtered.
|
||||
*
|
||||
* @param id The source of messages to listen for. Events sent from any other IDs will be filtered.
|
||||
* Use MICROBIT_ID_ANY to receive events from all components.
|
||||
*
|
||||
* @param value The value of messages to listen for. Events with any other values will be filtered.
|
||||
* @param value The value of messages to listen for. Events with any other values will be filtered.
|
||||
* Use MICROBIT_EVT_ANY to receive events of any value.
|
||||
*
|
||||
* @param handler The function to call when an event is received.
|
||||
*
|
||||
* @return MICROBIT_OK on success MICROBIT_INVALID_PARAMETER
|
||||
*
|
||||
*
|
||||
* Example:
|
||||
* @code
|
||||
* @code
|
||||
* void onButtonBClick()
|
||||
* {
|
||||
* //do something
|
||||
|
@ -93,22 +93,22 @@ class MicroBitMessageBus : public MicroBitComponent
|
|||
* @endcode
|
||||
*/
|
||||
int listen(int id, int value, void (*handler)(MicroBitEvent), uint16_t flags = MESSAGE_BUS_LISTENER_DEFAULT_FLAGS);
|
||||
|
||||
|
||||
/**
|
||||
* Register a listener function.
|
||||
*
|
||||
* @param id The source of messages to listen for. Events sent from any other IDs will be filtered.
|
||||
*
|
||||
* @param id The source of messages to listen for. Events sent from any other IDs will be filtered.
|
||||
* Use MICROBIT_ID_ANY to receive events from all components.
|
||||
*
|
||||
* @param value The value of messages to listen for. Events with any other values will be filtered.
|
||||
* @param value The value of messages to listen for. Events with any other values will be filtered.
|
||||
* Use MICROBIT_EVT_ANY to receive events of any value.
|
||||
*
|
||||
* @param hander The function to call when an event is received.
|
||||
*
|
||||
* @return MICROBIT_OK on success MICROBIT_INVALID_PARAMETER
|
||||
*
|
||||
*
|
||||
* Example:
|
||||
* @code
|
||||
* @code
|
||||
* void onButtonBClick(void *arg)
|
||||
* {
|
||||
* //do something
|
||||
|
@ -120,26 +120,26 @@ class MicroBitMessageBus : public MicroBitComponent
|
|||
|
||||
/**
|
||||
* Register a listener function.
|
||||
*
|
||||
* @param id The source of messages to listen for. Events sent from any other IDs will be filtered.
|
||||
*
|
||||
* @param id The source of messages to listen for. Events sent from any other IDs will be filtered.
|
||||
* Use MICROBIT_ID_ANY to receive events from all components.
|
||||
*
|
||||
* @param value The value of messages to listen for. Events with any other values will be filtered.
|
||||
* @param value The value of messages to listen for. Events with any other values will be filtered.
|
||||
* Use MICROBIT_EVT_ANY to receive events of any value.
|
||||
*
|
||||
* @param hander The function to call when an event is received.
|
||||
*
|
||||
* @return MICROBIT_OK on success MICROBIT_INVALID_PARAMETER
|
||||
*
|
||||
*
|
||||
* Example:
|
||||
* @code
|
||||
* @code
|
||||
* void SomeClass::onButtonBClick()
|
||||
* {
|
||||
* //do something
|
||||
* }
|
||||
*
|
||||
* SomeClass s = new SomeClass();
|
||||
* uBit.MessageBus.listen(MICROBIT_ID_BUTTON_B, MICROBIT_BUTTON_EVT_CLICK, s, &SomeClass::onButtonBClick);
|
||||
* uBit.MessageBus.listen(MICROBIT_ID_BUTTON_B, MICROBIT_BUTTON_EVT_CLICK, s, &SomeClass::onButtonBClick);
|
||||
* @endcode
|
||||
*/
|
||||
template <typename T>
|
||||
|
@ -149,7 +149,7 @@ class MicroBitMessageBus : public MicroBitComponent
|
|||
/**
|
||||
* Unregister a listener function.
|
||||
* Listners are identified by the Event ID, Event VALUE and handler registered using listen().
|
||||
*
|
||||
*
|
||||
* @param id The Event ID used to register the listener.
|
||||
* @param value The Event VALUE used to register the listener.
|
||||
* @param handler The function used to register the listener.
|
||||
|
@ -158,21 +158,21 @@ class MicroBitMessageBus : public MicroBitComponent
|
|||
*
|
||||
*
|
||||
* Example:
|
||||
* @code
|
||||
* @code
|
||||
* void onButtonBClick()
|
||||
* {
|
||||
* //do something
|
||||
* }
|
||||
*
|
||||
* uBit.MessageBus.ignore(MICROBIT_ID_BUTTON_B, MICROBIT_BUTTON_EVT_CLICK, onButtonBClick);
|
||||
* uBit.MessageBus.ignore(MICROBIT_ID_BUTTON_B, MICROBIT_BUTTON_EVT_CLICK, onButtonBClick);
|
||||
* @endcode
|
||||
*/
|
||||
int ignore(int id, int value, void (*handler)(MicroBitEvent));
|
||||
|
||||
|
||||
/**
|
||||
* Unregister a listener function.
|
||||
* Listners are identified by the Event ID, Event VALUE and handler registered using listen().
|
||||
*
|
||||
*
|
||||
* @param id The Event ID used to register the listener.
|
||||
* @param value The Event VALUE used to register the listener.
|
||||
* @param handler The function used to register the listener.
|
||||
|
@ -180,13 +180,13 @@ class MicroBitMessageBus : public MicroBitComponent
|
|||
* @return MICROBIT_OK on success MICROBIT_INVALID_PARAMETER
|
||||
*
|
||||
* Example:
|
||||
* @code
|
||||
* @code
|
||||
* void onButtonBClick(void *arg)
|
||||
* {
|
||||
* //do something
|
||||
* }
|
||||
*
|
||||
* uBit.MessageBus.ignore(MICROBIT_ID_BUTTON_B, MICROBIT_BUTTON_EVT_CLICK, onButtonBClick);
|
||||
* uBit.MessageBus.ignore(MICROBIT_ID_BUTTON_B, MICROBIT_BUTTON_EVT_CLICK, onButtonBClick);
|
||||
* @endcode
|
||||
*/
|
||||
int ignore(int id, int value, void (*handler)(MicroBitEvent, void*));
|
||||
|
@ -194,7 +194,7 @@ class MicroBitMessageBus : public MicroBitComponent
|
|||
/**
|
||||
* Unregister a listener function.
|
||||
* Listners are identified by the Event ID, Event VALUE and handler registered using listen().
|
||||
*
|
||||
*
|
||||
* @param id The Event ID used to register the listener.
|
||||
* @param value The Event VALUE used to register the listener.
|
||||
* @param handler The function used to register the listener.
|
||||
|
@ -202,15 +202,15 @@ class MicroBitMessageBus : public MicroBitComponent
|
|||
* @return MICROBIT_OK on success MICROBIT_INVALID_PARAMETER
|
||||
*
|
||||
* Example:
|
||||
* @code
|
||||
*
|
||||
* @code
|
||||
*
|
||||
* void SomeClass::onButtonBClick()
|
||||
* {
|
||||
* //do something
|
||||
* }
|
||||
*
|
||||
* SomeClass s = new SomeClass();
|
||||
* uBit.MessageBus.ignore(MICROBIT_ID_BUTTON_B, MICROBIT_BUTTON_EVT_CLICK, s, &SomeClass::onButtonBClick);
|
||||
* uBit.MessageBus.ignore(MICROBIT_ID_BUTTON_B, MICROBIT_BUTTON_EVT_CLICK, s, &SomeClass::onButtonBClick);
|
||||
* @endcode
|
||||
*/
|
||||
template <typename T>
|
||||
|
@ -223,6 +223,11 @@ class MicroBitMessageBus : public MicroBitComponent
|
|||
*/
|
||||
MicroBitListener *elementAt(int n);
|
||||
|
||||
/**
|
||||
* Destructor for MicroBitMessageBus, so that we deregister ourselves as an idleComponent
|
||||
*/
|
||||
~MicroBitMessageBus();
|
||||
|
||||
private:
|
||||
|
||||
/**
|
||||
|
@ -250,7 +255,7 @@ class MicroBitMessageBus : public MicroBitComponent
|
|||
MicroBitEventQueueItem *evt_queue_tail; // Tail of queued events to be processed.
|
||||
uint16_t nonce_val; // The last nonce issued.
|
||||
uint16_t queueLength; // The number of events currently waiting to be processed.
|
||||
|
||||
|
||||
void queueEvent(MicroBitEvent &evt);
|
||||
MicroBitEventQueueItem* dequeueEvent();
|
||||
|
||||
|
@ -262,10 +267,10 @@ class MicroBitMessageBus : public MicroBitComponent
|
|||
* A registration function to allow C++ member funcitons (methods) to be registered as an event
|
||||
* listener.
|
||||
*
|
||||
* @param id The source of messages to listen for. Events sent from any other IDs will be filtered.
|
||||
* @param id The source of messages to listen for. Events sent from any other IDs will be filtered.
|
||||
* Use MICROBIT_ID_ANY to receive events from all components.
|
||||
*
|
||||
* @param value The value of messages to listen for. Events with any other values will be filtered.
|
||||
* @param value The value of messages to listen for. Events with any other values will be filtered.
|
||||
* Use MICROBIT_EVT_ANY to receive events of any value.
|
||||
*
|
||||
* @param object The object on which the method should be invoked.
|
||||
|
@ -291,7 +296,7 @@ int MicroBitMessageBus::listen(uint16_t id, uint16_t value, T* object, void (T::
|
|||
/**
|
||||
* Unregister a listener function.
|
||||
* Listners are identified by the Event ID, Event VALUE and handler registered using listen().
|
||||
*
|
||||
*
|
||||
* @param id The Event ID used to register the listener.
|
||||
* @param value The Event VALUE used to register the listener.
|
||||
* @param handler The function used to register the listener.
|
||||
|
@ -299,13 +304,13 @@ int MicroBitMessageBus::listen(uint16_t id, uint16_t value, T* object, void (T::
|
|||
* @return MICROBIT_OK on success MICROBIT_INVALID_PARAMETER
|
||||
*
|
||||
* Example:
|
||||
* @code
|
||||
* @code
|
||||
* void onButtonBClick(void *arg)
|
||||
* {
|
||||
* //do something
|
||||
* }
|
||||
*
|
||||
* uBit.MessageBus.ignore(MICROBIT_ID_BUTTON_B, MICROBIT_BUTTON_EVT_CLICK, onButtonBClick);
|
||||
* uBit.MessageBus.ignore(MICROBIT_ID_BUTTON_B, MICROBIT_BUTTON_EVT_CLICK, onButtonBClick);
|
||||
* @endcode
|
||||
*/
|
||||
template <typename T>
|
||||
|
@ -322,5 +327,3 @@ int MicroBitMessageBus::ignore(uint16_t id, uint16_t value, T* object, void (T::
|
|||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "microbit-dal",
|
||||
"version": "1.4.4",
|
||||
"version": "1.4.6",
|
||||
"license": "Apache2",
|
||||
"description": "The runtime library for the BBC micro:bit, developed by Lancaster University",
|
||||
"keywords": [
|
||||
|
@ -21,4 +21,4 @@
|
|||
"extraIncludes": [
|
||||
"inc"
|
||||
]
|
||||
}
|
||||
}
|
|
@ -5,7 +5,7 @@
|
|||
*/
|
||||
void panic(int statusCode)
|
||||
{
|
||||
uBit.panic(statusCode);
|
||||
uBit.panic(statusCode);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -43,30 +43,30 @@ void bleDisconnectionCallback(const Gap::DisconnectionCallbackParams_t *reason)
|
|||
{
|
||||
(void) reason; /* -Wunused-param */
|
||||
|
||||
uBit.ble->startAdvertising();
|
||||
uBit.ble->startAdvertising();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
* Constructor.
|
||||
* Create a representation of a MicroBit device as a global singleton.
|
||||
* @param messageBus callback function to receive MicroBitMessageBus events.
|
||||
*
|
||||
* Exposed objects:
|
||||
* @code
|
||||
* @code
|
||||
* uBit.systemTicker; //the Ticker callback that performs routines like updating the display.
|
||||
* uBit.MessageBus; //The message bus where events are fired.
|
||||
* uBit.display; //The display object for the LED matrix.
|
||||
* uBit.buttonA; //The buttonA object for button a.
|
||||
* uBit.buttonB; //The buttonB object for button b.
|
||||
* uBit.buttonAB; //The buttonAB object for button a+b multi press.
|
||||
* uBit.buttonAB; //The buttonAB object for button a+b multi press.
|
||||
* uBit.resetButton; //The resetButton used for soft resets.
|
||||
* uBit.accelerometer; //The object that represents the inbuilt accelerometer
|
||||
* uBit.compass; //The object that represents the inbuilt compass(magnetometer)
|
||||
* uBit.io.P*; //Where P* is P0 to P16, P19 & P20 on the edge connector
|
||||
* @endcode
|
||||
*/
|
||||
MicroBit::MicroBit() :
|
||||
MicroBit::MicroBit() :
|
||||
flags(0x00),
|
||||
i2c(MICROBIT_PIN_SDA, MICROBIT_PIN_SCL),
|
||||
serial(USBTX, USBRX),
|
||||
|
@ -74,7 +74,7 @@ MicroBit::MicroBit() :
|
|||
display(MICROBIT_ID_DISPLAY, MICROBIT_DISPLAY_WIDTH, MICROBIT_DISPLAY_HEIGHT),
|
||||
buttonA(MICROBIT_ID_BUTTON_A,MICROBIT_PIN_BUTTON_A, MICROBIT_BUTTON_SIMPLE_EVENTS),
|
||||
buttonB(MICROBIT_ID_BUTTON_B,MICROBIT_PIN_BUTTON_B, MICROBIT_BUTTON_SIMPLE_EVENTS),
|
||||
buttonAB(MICROBIT_ID_BUTTON_AB,MICROBIT_ID_BUTTON_A,MICROBIT_ID_BUTTON_B),
|
||||
buttonAB(MICROBIT_ID_BUTTON_AB,MICROBIT_ID_BUTTON_A,MICROBIT_ID_BUTTON_B),
|
||||
accelerometer(MICROBIT_ID_ACCELEROMETER, MMA8653_DEFAULT_ADDR),
|
||||
compass(MICROBIT_ID_COMPASS, MAG3110_DEFAULT_ADDR),
|
||||
thermometer(MICROBIT_ID_THERMOMETER),
|
||||
|
@ -86,25 +86,25 @@ MicroBit::MicroBit() :
|
|||
MICROBIT_ID_IO_P15,MICROBIT_ID_IO_P16,MICROBIT_ID_IO_P19,
|
||||
MICROBIT_ID_IO_P20),
|
||||
bleManager()
|
||||
{
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Post constructor initialisation method.
|
||||
* After *MUCH* pain, it's noted that the BLE stack can't be brought up in a
|
||||
* After *MUCH* pain, it's noted that the BLE stack can't be brought up in a
|
||||
* static context, so we bring it up here rather than in the constructor.
|
||||
* n.b. This method *must* be called in main() or later, not before.
|
||||
*
|
||||
* Example:
|
||||
* @code
|
||||
* @code
|
||||
* uBit.init();
|
||||
* @endcode
|
||||
*/
|
||||
void MicroBit::init()
|
||||
{
|
||||
{
|
||||
//add the display to the systemComponent array
|
||||
addSystemComponent(&uBit.display);
|
||||
|
||||
|
||||
//add the compass and accelerometer to the idle array
|
||||
addIdleComponent(&uBit.accelerometer);
|
||||
addIdleComponent(&uBit.compass);
|
||||
|
@ -114,14 +114,14 @@ void MicroBit::init()
|
|||
seedRandom();
|
||||
|
||||
#if CONFIG_ENABLED(MICROBIT_BLE_ENABLED)
|
||||
// Start the BLE stack.
|
||||
// Start the BLE stack.
|
||||
bleManager.init(this->getName(), this->getSerial());
|
||||
|
||||
|
||||
ble = bleManager.ble;
|
||||
#endif
|
||||
|
||||
// Start refreshing the Matrix Display
|
||||
systemTicker.attach(this, &MicroBit::systemTick, MICROBIT_DISPLAY_REFRESH_PERIOD);
|
||||
systemTicker.attach(this, &MicroBit::systemTick, MICROBIT_DISPLAY_REFRESH_PERIOD);
|
||||
|
||||
// Register our compass calibration algorithm.
|
||||
MessageBus.listen(MICROBIT_ID_COMPASS, MICROBIT_COMPASS_EVT_CALIBRATE, this, &MicroBit::compassCalibrator, MESSAGE_BUS_LISTENER_IMMEDIATE);
|
||||
|
@ -146,7 +146,7 @@ void MicroBit::compassCalibrator(MicroBitEvent)
|
|||
const int PIXEL2_THRESHOLD = 800;
|
||||
|
||||
Matrix4 X(PERIMETER_POINTS, 4);
|
||||
Point perimeter[PERIMETER_POINTS] = {{1,0 |