microbit: further formatting corrections
Corrected trailing whitespace, and tabulated lines with no content for: * MicroBitCompass.h (.cpp) * MicroBitDisplay.h (.cpp) * MicroBitMessageBus.h (.cpp)master
parent
d8240cfb74
commit
1cc814da60
|
@ -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,62 @@ 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();
|
||||
|
||||
|
||||
private:
|
||||
|
||||
|
||||
/**
|
||||
* Issues a standard, 2 byte I2C command write to the magnetometer.
|
||||
* Blocks the calling thread until complete.
|
||||
|
@ -339,7 +339,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 +350,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 +359,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,7 +557,7 @@ public:
|
|||
* Retreives the font object used for rendering characters on the display.
|
||||
*/
|
||||
MicroBitFont getFont();
|
||||
|
||||
|
||||
/**
|
||||
* Captures the bitmap currently being rendered on the display.
|
||||
*/
|
||||
|
@ -565,4 +565,3 @@ public:
|
|||
};
|
||||
|
||||
#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>
|
||||
|
@ -250,7 +250,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 +262,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 +291,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 +299,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 +322,3 @@ int MicroBitMessageBus::ignore(uint16_t id, uint16_t value, T* object, void (T::
|
|||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#include "MicroBit.h"
|
||||
|
||||
/**
|
||||
* 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
|
||||
|
@ -22,17 +22,17 @@ MicroBitCompass::MicroBitCompass(uint16_t id, uint16_t address) : average(), sam
|
|||
{
|
||||
this->id = id;
|
||||
this->address = address;
|
||||
|
||||
|
||||
// We presume the device calibrated until the average values are read.
|
||||
this->status = 0x01;
|
||||
|
||||
// Select 10Hz update rate, with oversampling, and enable the device.
|
||||
this->samplePeriod = 100;
|
||||
this->configure();
|
||||
|
||||
// Assume that we have no calibraiton information.
|
||||
|
||||
// Assume that we have no calibraiton information.
|
||||
status &= ~MICROBIT_COMPASS_STATUS_CALIBRATED;
|
||||
|
||||
|
||||
// Indicate that we're up and running.
|
||||
uBit.flags |= MICROBIT_FLAG_COMPASS_RUNNING;
|
||||
}
|
||||
|
@ -50,7 +50,7 @@ int MicroBitCompass::writeCommand(uint8_t reg, uint8_t value)
|
|||
uint8_t command[2];
|
||||
command[0] = reg;
|
||||
command[1] = value;
|
||||
|
||||
|
||||
return uBit.i2c.write(address, (const char *)command, 2);
|
||||
}
|
||||
|
||||
|
@ -100,7 +100,7 @@ int MicroBitCompass::read16(uint8_t reg)
|
|||
|
||||
cmd[0] = 0x00;
|
||||
cmd[1] = 0x00;
|
||||
|
||||
|
||||
result = uBit.i2c.read(address, (char *)cmd, 2);
|
||||
if (result !=0)
|
||||
return MICROBIT_I2C_ERROR;
|
||||
|
@ -132,10 +132,10 @@ int MicroBitCompass::read8(uint8_t reg)
|
|||
* 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
|
||||
|
@ -147,7 +147,7 @@ int MicroBitCompass::heading()
|
|||
float bearing;
|
||||
|
||||
if(status & MICROBIT_COMPASS_STATUS_CALIBRATING)
|
||||
return MICROBIT_CALIBRATION_IN_PROGRESS;
|
||||
return MICROBIT_CALIBRATION_IN_PROGRESS;
|
||||
|
||||
if(!(status & MICROBIT_COMPASS_STATUS_CALIBRATED))
|
||||
calibrate();
|
||||
|
@ -165,11 +165,11 @@ int MicroBitCompass::heading()
|
|||
float sinTheta = sin(theta);
|
||||
float cosTheta = cos(theta);
|
||||
|
||||
bearing = (360*atan2(z*sinPhi - y*cosPhi, x*cosTheta + y*sinTheta*sinPhi + z*sinTheta*cosPhi)) / (2*PI);
|
||||
bearing = (360*atan2(z*sinPhi - y*cosPhi, x*cosTheta + y*sinTheta*sinPhi + z*sinTheta*cosPhi)) / (2*PI);
|
||||
|
||||
if (bearing < 0)
|
||||
bearing += 360.0;
|
||||
|
||||
|
||||
return (int) bearing;
|
||||
}
|
||||
|
||||
|
@ -179,7 +179,7 @@ int MicroBitCompass::heading()
|
|||
*/
|
||||
void MicroBitCompass::idleTick()
|
||||
{
|
||||
// Poll interrupt line from accelerometer (Active HI).
|
||||
// Poll interrupt line from accelerometer (Active HI).
|
||||
// Interrupt is cleared on data read of MAG_OUT_X_MSB.
|
||||
if(int1)
|
||||
{
|
||||
|
@ -225,7 +225,7 @@ int MicroBitCompass::getX(MicroBitCoordinateSystem system)
|
|||
* @code
|
||||
* uBit.compass.getY();
|
||||
* @endcode
|
||||
*/
|
||||
*/
|
||||
int MicroBitCompass::getY(MicroBitCoordinateSystem system)
|
||||
{
|
||||
switch (system)
|
||||
|
@ -235,7 +235,7 @@ int MicroBitCompass::getY(MicroBitCoordinateSystem system)
|
|||
|
||||
case NORTH_EAST_DOWN:
|
||||
return (sample.x - average.x);
|
||||
|
||||
|
||||
case RAW:
|
||||
default:
|
||||
return sample.y;
|
||||
|
@ -250,7 +250,7 @@ int MicroBitCompass::getY(MicroBitCoordinateSystem system)
|
|||
* @code
|
||||
* uBit.compass.getZ();
|
||||
* @endcode
|
||||
*/
|
||||
*/
|
||||
int MicroBitCompass::getZ(MicroBitCoordinateSystem system)
|
||||
{
|
||||
switch (system)
|
||||
|
@ -273,7 +273,7 @@ int MicroBitCompass::getZ(MicroBitCoordinateSystem system)
|
|||
* @code
|
||||
* uBit.compass.getFieldStrength();
|
||||
* @endcode
|
||||
*/
|
||||
*/
|
||||
int MicroBitCompass::getFieldStrength()
|
||||
{
|
||||
double x = getX();
|
||||
|
@ -300,7 +300,7 @@ int MicroBitCompass::configure()
|
|||
if (result != MICROBIT_OK)
|
||||
return MICROBIT_I2C_ERROR;
|
||||
|
||||
// Wait for the part to enter standby mode...
|
||||
// Wait for the part to enter standby mode...
|
||||
while(1)
|
||||
{
|
||||
// Read the status of the part...
|
||||
|
@ -335,7 +335,7 @@ int MicroBitCompass::configure()
|
|||
if (result != MICROBIT_OK)
|
||||
return MICROBIT_I2C_ERROR;
|
||||
|
||||
|
||||
|
||||
// Bring the device online, with the requested sample frequency.
|
||||
result = writeCommand(MAG_CTRL_REG1, actualSampleRate->ctrl_reg1 | 0x01);
|
||||
if (result != MICROBIT_OK)
|
||||
|
@ -358,7 +358,7 @@ int MicroBitCompass::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 MicroBitCompass::getPeriod()
|
||||
|
@ -368,7 +368,7 @@ int MicroBitCompass::getPeriod()
|
|||
|
||||
|
||||
/**
|
||||
* 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:
|
||||
|
@ -381,7 +381,7 @@ int MicroBitCompass::whoAmI()
|
|||
uint8_t data;
|
||||
int result;
|
||||
|
||||
result = readCommand(MAG_WHOAMI, &data, 1);
|
||||
result = readCommand(MAG_WHOAMI, &data, 1);
|
||||
if (result != MICROBIT_OK)
|
||||
return MICROBIT_I2C_ERROR;
|
||||
|
||||
|
@ -389,7 +389,7 @@ int MicroBitCompass::whoAmI()
|
|||
}
|
||||
|
||||
/**
|
||||
* 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 MicroBitCompass::readTemperature()
|
||||
|
@ -406,10 +406,10 @@ int MicroBitCompass::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.
|
||||
*
|
||||
|
@ -453,7 +453,7 @@ int MicroBitCompass::calibrate()
|
|||
int MicroBitCompass::calibrateStart()
|
||||
{
|
||||
return calibrate();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform the asynchronous calibration of the compass.
|
||||
|
@ -463,7 +463,7 @@ int MicroBitCompass::calibrateStart()
|
|||
* @note *** PLEASE USE THE calibrate() FUNCTION INSTEAD ***
|
||||
*/
|
||||
void MicroBitCompass::calibrateAsync()
|
||||
{
|
||||
{
|
||||
calibrate();
|
||||
}
|
||||
|
||||
|
@ -472,20 +472,20 @@ void MicroBitCompass::calibrateAsync()
|
|||
* This will fire MICROBIT_COMPASS_EVT_CAL_END.
|
||||
*
|
||||
* @note *** THIS FUNCTION IS NOW DEPRECATED AND WILL BE REMOVED IN THE NEXT MAJOR RELEASE ***
|
||||
*/
|
||||
*/
|
||||
void MicroBitCompass::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 MicroBitCompass::setCalibration(CompassSample calibration)
|
||||
{
|
||||
average = calibration;
|
||||
|
@ -496,8 +496,8 @@ void MicroBitCompass::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 MicroBitCompass::getCalibration()
|
||||
{
|
||||
return average;
|
||||
|
@ -508,7 +508,7 @@ CompassSample MicroBitCompass::getCalibration()
|
|||
*/
|
||||
int MicroBitCompass::isCalibrated()
|
||||
{
|
||||
return status & MICROBIT_COMPASS_STATUS_CALIBRATED;
|
||||
return status & MICROBIT_COMPASS_STATUS_CALIBRATED;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -516,7 +516,7 @@ int MicroBitCompass::isCalibrated()
|
|||
*/
|
||||
int MicroBitCompass::isCalibrating()
|
||||
{
|
||||
return status & MICROBIT_COMPASS_STATUS_CALIBRATING;
|
||||
return status & MICROBIT_COMPASS_STATUS_CALIBRATING;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -524,7 +524,7 @@ int MicroBitCompass::isCalibrating()
|
|||
*/
|
||||
void MicroBitCompass::clearCalibration()
|
||||
{
|
||||
status &= ~MICROBIT_COMPASS_STATUS_CALIBRATED;
|
||||
status &= ~MICROBIT_COMPASS_STATUS_CALIBRATED;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -540,13 +540,13 @@ int MicroBitCompass::isIdleCallbackNeeded()
|
|||
const MAG3110SampleRateConfig MAG3110SampleRate[MAG3110_SAMPLE_RATES] = {
|
||||
{12500, 0x00}, // 80 Hz
|
||||
{25000, 0x20}, // 40 Hz
|
||||
{50000, 0x40}, // 20 Hz
|
||||
{100000, 0x60}, // 10 hz
|
||||
{200000, 0x80}, // 5 hz
|
||||
{400000, 0x88}, // 2.5 hz
|
||||
{800000, 0x90}, // 1.25 hz
|
||||
{1600000, 0xb0}, // 0.63 hz
|
||||
{3200000, 0xd0}, // 0.31 hz
|
||||
{6400000, 0xf0}, // 0.16 hz
|
||||
{12800000, 0xf8} // 0.08 hz
|
||||
{50000, 0x40}, // 20 Hz
|
||||
{100000, 0x60}, // 10 hz
|
||||
{200000, 0x80}, // 5 hz
|
||||
{400000, 0x88}, // 2.5 hz
|
||||
{800000, 0x90}, // 1.25 hz
|
||||
{1600000, 0xb0}, // 0.63 hz
|
||||
{3200000, 0xd0}, // 0.31 hz
|
||||
{6400000, 0xf0}, // 0.16 hz
|
||||
{12800000, 0xf8} // 0.08 hz
|
||||
};
|
||||
|
|
|
@ -17,19 +17,19 @@ const float timings[MICROBIT_DISPLAY_GREYSCALE_BIT_DEPTH] = {0.000010, 0.000047,
|
|||
*
|
||||
* @param x the width of the display in pixels.
|
||||
* @param y the height of the display in pixels.
|
||||
*
|
||||
*
|
||||
* Example:
|
||||
* @code
|
||||
* @code
|
||||
* MicroBitDisplay display(MICROBIT_ID_DISPLAY, 5, 5),
|
||||
* @endcode
|
||||
*/
|
||||
MicroBitDisplay::MicroBitDisplay(uint16_t id, uint8_t x, uint8_t y) :
|
||||
MicroBitDisplay::MicroBitDisplay(uint16_t id, uint8_t x, uint8_t y) :
|
||||
font(),
|
||||
image(x*2,y)
|
||||
{
|
||||
//set pins as output
|
||||
nrf_gpio_range_cfg_output(MICROBIT_DISPLAY_COLUMN_START,MICROBIT_DISPLAY_COLUMN_START + MICROBIT_DISPLAY_COLUMN_COUNT + MICROBIT_DISPLAY_ROW_COUNT);
|
||||
|
||||
|
||||
this->id = id;
|
||||
this->width = x;
|
||||
this->height = y;
|
||||
|
@ -38,46 +38,46 @@ MicroBitDisplay::MicroBitDisplay(uint16_t id, uint8_t x, uint8_t y) :
|
|||
this->rotation = MICROBIT_DISPLAY_ROTATION_0;
|
||||
this->greyscaleBitMsk = 0x01;
|
||||
this->timingCount = 0;
|
||||
|
||||
|
||||
this->setBrightness(MICROBIT_DISPLAY_DEFAULT_BRIGHTNESS);
|
||||
|
||||
this->mode = DISPLAY_MODE_BLACK_AND_WHITE;
|
||||
this->animationMode = ANIMATION_MODE_NONE;
|
||||
|
||||
|
||||
uBit.flags |= MICROBIT_FLAG_DISPLAY_RUNNING;
|
||||
}
|
||||
|
||||
/**
|
||||
* Internal frame update method, used to strobe the display.
|
||||
*
|
||||
* TODO: Write a more efficient, complementary variation of this method for the case where
|
||||
* TODO: Write a more efficient, complementary variation of this method for the case where
|
||||
* MICROBIT_DISPLAY_ROW_COUNT > MICROBIT_DISPLAY_COLUMN_COUNT.
|
||||
*/
|
||||
*/
|
||||
void MicroBitDisplay::systemTick()
|
||||
{
|
||||
{
|
||||
if(!(uBit.flags & MICROBIT_FLAG_DISPLAY_RUNNING))
|
||||
return;
|
||||
|
||||
// Move on to the next row.
|
||||
|
||||
// Move on to the next row.
|
||||
strobeBitMsk <<= 1;
|
||||
strobeRow++;
|
||||
|
||||
|
||||
//reset the row counts and bit mask when we have hit the max.
|
||||
if(strobeRow == MICROBIT_DISPLAY_ROW_COUNT){
|
||||
strobeRow = 0;
|
||||
strobeBitMsk = 0x20;
|
||||
strobeBitMsk = 0x20;
|
||||
}
|
||||
|
||||
|
||||
if(mode == DISPLAY_MODE_BLACK_AND_WHITE)
|
||||
render();
|
||||
|
||||
|
||||
if(mode == DISPLAY_MODE_GREYSCALE)
|
||||
{
|
||||
greyscaleBitMsk = 0x01;
|
||||
timingCount = 0;
|
||||
renderGreyscale();
|
||||
}
|
||||
|
||||
|
||||
// Update text and image animations if we need to.
|
||||
this->animationUpdate();
|
||||
}
|
||||
|
@ -87,60 +87,60 @@ void MicroBitDisplay::renderFinish()
|
|||
//kept inline to reduce overhead
|
||||
//clear the old bit pattern for this row.
|
||||
//clear port 0 4-7 and retain lower 4 bits
|
||||
nrf_gpio_port_write(NRF_GPIO_PORT_SELECT_PORT0, 0xF0 | (nrf_gpio_port_read(NRF_GPIO_PORT_SELECT_PORT0) & 0x0F));
|
||||
|
||||
nrf_gpio_port_write(NRF_GPIO_PORT_SELECT_PORT0, 0xF0 | (nrf_gpio_port_read(NRF_GPIO_PORT_SELECT_PORT0) & 0x0F));
|
||||
|
||||
// clear port 1 8-12 for the current row
|
||||
nrf_gpio_port_write(NRF_GPIO_PORT_SELECT_PORT1, strobeBitMsk | 0x1F);
|
||||
nrf_gpio_port_write(NRF_GPIO_PORT_SELECT_PORT1, strobeBitMsk | 0x1F);
|
||||
}
|
||||
|
||||
void MicroBitDisplay::render()
|
||||
{
|
||||
{
|
||||
// Simple optimisation. If display is at zero brightness, there's nothign to do.
|
||||
if(brightness == 0)
|
||||
return;
|
||||
|
||||
int coldata = 0;
|
||||
|
||||
|
||||
// Calculate the bitpattern to write.
|
||||
for (int i = 0; i<MICROBIT_DISPLAY_COLUMN_COUNT; i++)
|
||||
{
|
||||
int x = matrixMap[i][strobeRow].x;
|
||||
int y = matrixMap[i][strobeRow].y;
|
||||
int t = x;
|
||||
|
||||
int t = x;
|
||||
|
||||
if(rotation == MICROBIT_DISPLAY_ROTATION_90)
|
||||
{
|
||||
x = width - 1 - y;
|
||||
y = t;
|
||||
}
|
||||
|
||||
|
||||
if(rotation == MICROBIT_DISPLAY_ROTATION_180)
|
||||
{
|
||||
x = width - 1 - x;
|
||||
y = height - 1 - y;
|
||||
}
|
||||
|
||||
|
||||
if(rotation == MICROBIT_DISPLAY_ROTATION_270)
|
||||
{
|
||||
x = y;
|
||||
y = height - 1 - t;
|
||||
}
|
||||
|
||||
|
||||
if(image.getBitmap()[y*(width*2)+x])
|
||||
coldata |= (1 << i);
|
||||
}
|
||||
|
||||
|
||||
//write the new bit pattern
|
||||
//set port 0 4-7 and retain lower 4 bits
|
||||
nrf_gpio_port_write(NRF_GPIO_PORT_SELECT_PORT0, (~coldata<<4 & 0xF0) | (nrf_gpio_port_read(NRF_GPIO_PORT_SELECT_PORT0) & 0x0F));
|
||||
|
||||
nrf_gpio_port_write(NRF_GPIO_PORT_SELECT_PORT0, (~coldata<<4 & 0xF0) | (nrf_gpio_port_read(NRF_GPIO_PORT_SELECT_PORT0) & 0x0F));
|
||||
|
||||
//set port 1 8-12 for the current row
|
||||
nrf_gpio_port_write(NRF_GPIO_PORT_SELECT_PORT1, strobeBitMsk | (~coldata>>4 & 0x1F));
|
||||
nrf_gpio_port_write(NRF_GPIO_PORT_SELECT_PORT1, strobeBitMsk | (~coldata>>4 & 0x1F));
|
||||
|
||||
//timer does not have enough resolution for brightness of 1. 23.53 us
|
||||
if(brightness != MICROBIT_DISPLAY_MAXIMUM_BRIGHTNESS && brightness > MICROBIT_DISPLAY_MINIMUM_BRIGHTNESS)
|
||||
renderTimer.attach(this, &MicroBitDisplay::renderFinish, (((float)brightness) / ((float)MICROBIT_DISPLAY_MAXIMUM_BRIGHTNESS)) * (float)MICROBIT_DISPLAY_REFRESH_PERIOD);
|
||||
|
||||
|
||||
//this will take around 23us to execute
|
||||
if(brightness <= MICROBIT_DISPLAY_MINIMUM_BRIGHTNESS)
|
||||
renderFinish();
|
||||
|
@ -149,47 +149,47 @@ void MicroBitDisplay::render()
|
|||
void MicroBitDisplay::renderGreyscale()
|
||||
{
|
||||
int coldata = 0;
|
||||
|
||||
|
||||
// Calculate the bitpattern to write.
|
||||
for (int i = 0; i<MICROBIT_DISPLAY_COLUMN_COUNT; i++)
|
||||
{
|
||||
int x = matrixMap[i][strobeRow].x;
|
||||
int y = matrixMap[i][strobeRow].y;
|
||||
int t = x;
|
||||
|
||||
int t = x;
|
||||
|
||||
if(rotation == MICROBIT_DISPLAY_ROTATION_90)
|
||||
{
|
||||
x = width - 1 - y;
|
||||
y = t;
|
||||
}
|
||||
|
||||
|
||||
if(rotation == MICROBIT_DISPLAY_ROTATION_180)
|
||||
{
|
||||
x = width - 1 - x;
|
||||
y = height - 1 - y;
|
||||
}
|
||||
|
||||
|
||||
if(rotation == MICROBIT_DISPLAY_ROTATION_270)
|
||||
{
|
||||
x = y;
|
||||
y = height - 1 - t;
|
||||
}
|
||||
|
||||
|
||||
if(min(image.getBitmap()[y * (width * 2) + x],brightness) & greyscaleBitMsk)
|
||||
coldata |= (1 << i);
|
||||
}
|
||||
}
|
||||
//write the new bit pattern
|
||||
//set port 0 4-7 and retain lower 4 bits
|
||||
nrf_gpio_port_write(NRF_GPIO_PORT_SELECT_PORT0, (~coldata<<4 & 0xF0) | (nrf_gpio_port_read(NRF_GPIO_PORT_SELECT_PORT0) & 0x0F));
|
||||
|
||||
nrf_gpio_port_write(NRF_GPIO_PORT_SELECT_PORT0, (~coldata<<4 & 0xF0) | (nrf_gpio_port_read(NRF_GPIO_PORT_SELECT_PORT0) & 0x0F));
|
||||
|
||||
//set port 1 8-12 for the current row
|
||||
nrf_gpio_port_write(NRF_GPIO_PORT_SELECT_PORT1, strobeBitMsk | (~coldata>>4 & 0x1F));
|
||||
nrf_gpio_port_write(NRF_GPIO_PORT_SELECT_PORT1, strobeBitMsk | (~coldata>>4 & 0x1F));
|
||||
|
||||
if(timingCount > MICROBIT_DISPLAY_GREYSCALE_BIT_DEPTH-1)
|
||||
return;
|
||||
|
||||
greyscaleBitMsk <<= 1;
|
||||
|
||||
|
||||
renderTimer.attach(this,&MicroBitDisplay::renderGreyscale, timings[timingCount++]);
|
||||
}
|
||||
|
||||
|
@ -198,29 +198,29 @@ void MicroBitDisplay::renderGreyscale()
|
|||
*/
|
||||
void
|
||||
MicroBitDisplay::animationUpdate()
|
||||
{
|
||||
{
|
||||
// If there's no ongoing animation, then nothing to do.
|
||||
if (animationMode == ANIMATION_MODE_NONE)
|
||||
return;
|
||||
|
||||
animationTick += FIBER_TICK_PERIOD_MS;
|
||||
|
||||
|
||||
animationTick += FIBER_TICK_PERIOD_MS;
|
||||
|
||||
if(animationTick >= animationDelay)
|
||||
{
|
||||
animationTick = 0;
|
||||
|
||||
|
||||
if (animationMode == ANIMATION_MODE_SCROLL_TEXT)
|
||||
this->updateScrollText();
|
||||
|
||||
|
||||
if (animationMode == ANIMATION_MODE_PRINT_TEXT)
|
||||
this->updatePrintText();
|
||||
|
||||
if (animationMode == ANIMATION_MODE_SCROLL_IMAGE)
|
||||
this->updateScrollImage();
|
||||
|
||||
|
||||
if (animationMode == ANIMATION_MODE_ANIMATE_IMAGE)
|
||||
this->updateAnimateImage();
|
||||
|
||||
|
||||
if(animationMode == ANIMATION_MODE_PRINT_CHARACTER)
|
||||
{
|
||||
animationMode = ANIMATION_MODE_NONE;
|
||||
|
@ -243,18 +243,18 @@ void MicroBitDisplay::sendAnimationCompleteEvent()
|
|||
}
|
||||
|
||||
/**
|
||||
* Internal scrollText update method.
|
||||
* Internal scrollText update method.
|
||||
* Shift the screen image by one pixel to the left. If necessary, paste in the next char.
|
||||
*/
|
||||
*/
|
||||
void MicroBitDisplay::updateScrollText()
|
||||
{
|
||||
{
|
||||
image.shiftLeft(1);
|
||||
scrollingPosition++;
|
||||
|
||||
|
||||
if (scrollingPosition == width + MICROBIT_DISPLAY_SPACING)
|
||||
{
|
||||
{
|
||||
scrollingPosition = 0;
|
||||
|
||||
|
||||
image.print(scrollingChar < scrollingText.length() ? scrollingText.charAt(scrollingChar) : ' ',width,0);
|
||||
|
||||
if (scrollingChar > scrollingText.length())
|
||||
|
@ -268,36 +268,36 @@ void MicroBitDisplay::updateScrollText()
|
|||
}
|
||||
|
||||
/**
|
||||
* Internal printText update method.
|
||||
* Internal printText update method.
|
||||
* Paste in the next char in the string.
|
||||
*/
|
||||
*/
|
||||
void MicroBitDisplay::updatePrintText()
|
||||
{
|
||||
{
|
||||
image.print(printingChar < printingText.length() ? printingText.charAt(printingChar) : ' ',0,0);
|
||||
|
||||
if (printingChar > printingText.length())
|
||||
{
|
||||
animationMode = ANIMATION_MODE_NONE;
|
||||
animationMode = ANIMATION_MODE_NONE;
|
||||
|
||||
this->sendAnimationCompleteEvent();
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
printingChar++;
|
||||
}
|
||||
|
||||
/**
|
||||
* Internal scrollImage update method.
|
||||
* Internal scrollImage update method.
|
||||
* Paste the stored bitmap at the appropriate point.
|
||||
*/
|
||||
*/
|
||||
void MicroBitDisplay::updateScrollImage()
|
||||
{
|
||||
image.clear();
|
||||
{
|
||||
image.clear();
|
||||
|
||||
if ((image.paste(scrollingImage, scrollingImagePosition, 0, 0) == 0) && scrollingImageRendered)
|
||||
{
|
||||
animationMode = ANIMATION_MODE_NONE;
|
||||
this->sendAnimationCompleteEvent();
|
||||
animationMode = ANIMATION_MODE_NONE;
|
||||
this->sendAnimationCompleteEvent();
|
||||
|
||||
return;
|
||||
}
|
||||
|
@ -307,27 +307,27 @@ void MicroBitDisplay::updateScrollImage()
|
|||
}
|
||||
|
||||
/**
|
||||
* Internal animateImage update method.
|
||||
* Internal animateImage update method.
|
||||
* Paste the stored bitmap at the appropriate point and stop on the last frame.
|
||||
*/
|
||||
*/
|
||||
void MicroBitDisplay::updateAnimateImage()
|
||||
{
|
||||
{
|
||||
//wait until we have rendered the last position to give a continuous animation.
|
||||
if (scrollingImagePosition <= -scrollingImage.getWidth() + (MICROBIT_DISPLAY_WIDTH + scrollingImageStride) && scrollingImageRendered)
|
||||
{
|
||||
animationMode = ANIMATION_MODE_NONE;
|
||||
animationMode = ANIMATION_MODE_NONE;
|
||||