Replaced newer struct-style initialisation of CompassSample in MicroBit.cpp
with the more traditional constructor-style initialisation, to enfore
C98 compliance.
Closes#74
The destructor for MicroBitButton didn't take into account the fact that
an instance can be destructed after registering a callback. This would then
result in a HardFault if an instance was destructed.
A clear repro case was registering a Touch input on a pin (abstracted as a button)
and swapping to a DigitalIn.
* Added a number of #defines to MicroBitPin.h which ultimately lead to retabulation of the #defines
* Added two new instance methods:
- setServoValue() which sets the default servo period (20ms) and accepts a value in the range
0 - 180, which maps to a duty cycle between 5% and 10% respectively. This
mapping is also configurable.
- setServoPulseUs() which accepts a pulse width in microseconds, and maps it onto the PWM
channel.
Based on the previous commit, the api for MicroBitPin
has two new accessor methods:
* getAnalogPeriodUs
* getAnalogPeriod
There are also whitespace changes in the MicroBitPin head file
as well as some minor textual changes.
This commit introduces an initial draft fix
for a bug where it would take two "setPeriods" for the
PWM class to update to the expected value.
This commit also adds three new methods to a DynamicPwm instance:
* write() - which is a lightweight wrapper around PwmOut write,
so that the value can be trapped. The trapping of the value
is necessary for the bug fix.
* getPeriod() - which returns the value of a static variable,
containing the current period shared across the pwm bus.
* getValue() - which returns a scaled value in the range 0-1024
representing the current duty cycle.
Dynamic pwm previously didn't round robin transient pwm channels,
and would therefore bias towards the first transient channel it found.
This update ensures that there is now an equal opportunity for all
channels to be considered for redirection.
Previously there would be the possibility of the period being reset
each time a new DynamicPwm was instantiated. This has now been
removed from the constructor, and the comments have been updated
Events listed recorded in MESEvents.h were enumerated from zero.
This is not ideal, as MicroBitMessageBus uses a code of zero for
MICROBIT_EVT_ANY - a wildcard mechanism to register interest in all events
from a given ID.
All event values recorded in MESEvents.h have therefore incremented.
There was a duplication in IDs for MICROBIT_ID_THERMOMETER and MICROBIT_ID_IO_P0
for the event bus. This has been rectified by appending the MICROBIT_ID_THERMOMETER
All internal uses of accelerometer sample values now updated to access the
data via accessor methods. This now ensures consistent use irrespective of
the coordinate system used.
declarations
Added missing operator new[] wrapper in MicroBitHeapAllocator.h
Ammended defualt microBitConfig.h to allocate 90% of available heap, rather
than 95%. this is to leave a little more heap for external libraries.
native printf() call.
The Matrix4::print() function is useful, but non essential for most
applications, and the underlying printf() call required cost an
additional 1K of RAM on first use, which is currently above the budget for
micro:bit.
An e-compass solution requires knowwlede two pieces of data to provide an
accurate heading:
- Accurate calibration of the magnetometer hardware so that reliable
measurements can be taken.
- Knowledge of the pitch and roll of of device, so that the correct
components of the X/Y and Z axis sensors of the magnetomer can be used
to sense the magnetic field in a horizontal plane regardless of the tilt
of the device.
This commit represent changes to the MicroBitAccelerometer and MicroBitCompass
classes to implemen tthese goals. More specifically, this commit provides:
- The introduciton of an interactive calibration 'game', that can rapidly
gather all the data required to calibrate the compass.
- An improved calibration algorithm based on a Least Mean Squares approach of
compass samples, as documened in Freescale Application Note AN4248.
- The inclusion of a simple Matrix4 class to enable efficient Least Mean
Squares implementation.
- A change from asynchronous to synchronous calibration of the compass when
first used. This is in repsonse to a feature request for this from users
and high level languages using microbit-dal.
- Support for detemrining tilt and roll angle in MicroBitAccelerometer
- Support for multiple co-ordinate spaces in MicroBitAccelerometer and
MicroBitCompass. Data can now be read in either RAW (unaltered) data.
MICORBIT_SIMPLE_CARTESIAN (as used previously) or NORTH_EAST_DOWN
(the industry convention in mobile phones, tablets and aviation)
- Implementation of a tilt compensated algorithm, used when determining
device heading.
Freefall now detected when the net force on the device drops below 0.4g,
rather than 0.2g as previously defined. This improves sensitivity, without
generating false positives under common use.
Also correction of minor typos / layout errors.
- updated acceleration threshold event names to reflect numeric values e.g.
GESTURE_3G, GESTURE_6G, GESTURE_8G.
- Add scoping to elements of SimpleGesture enum.
- Code scrub of code layout caused by editor with incorrect configuration.
- rename of internal state variables and functions to better reflect use.
- added clarification to some comments.
Whilst Android devices permit explicit initiation of the BLE pairing process,
IOS based devices are only capable of implicit initiation of pairing based
on accessing a protected characteristic. Adding read capability to the
ControlPoint characteristic provides a safe and convenient way for IOS devices
to initiate pairing.