microbit: added new display mode, and accessor

This commit introduces a new display mode,
DISPLAY_MODE_BLACK_AND_WHITE_LIGHT_SENSE, where the 4th render in
every “frame” is dropped allowing for other components that use the
display to use this dropped frame for processing. This is in
preparation for Light Sensing on the 5x5 LED matrix.

An accessor has also been added to MicroBitDisplay to check the current
display mode!
master
James Devine 2016-01-29 14:03:24 +00:00
parent 6939ad25d9
commit 6f812aa474
2 changed files with 63 additions and 7 deletions

View File

@ -12,6 +12,7 @@
*/
#define MICROBIT_DISPLAY_EVT_ANIMATION_COMPLETE 1
#define MICROBIT_DISPLAY_EVT_FREE 2
#define MICROBIT_DISPLAY_EVT_LIGHT_SENSE 4
/**
* I/O configurations for common devices.
@ -43,6 +44,7 @@
#define MICROBIT_DISPLAY_COLUMN_COUNT 9
#define MICROBIT_DISPLAY_COLUMN_PINS P0_4, P0_5, P0_6, P0_7, P0_8, P0_9, P0_10, P0_11, P0_12
#define MICROBIT_DISPLAY_COLUMN_START P0_4
#define MICROBIT_DISPLAY_ROW_START P0_13
#endif
//
@ -55,6 +57,8 @@
#define MICROBIT_DISPLAY_GREYSCALE_BIT_DEPTH 8
#define MICROBIT_DISPLAY_ANIMATE_DEFAULT_POS -255
#define MICROBIT_DISPLAY_ROW_RESET 0x20
#include "mbed.h"
#include "ManagedString.h"
#include "MicroBitComponent.h"
@ -73,7 +77,8 @@ enum AnimationMode {
enum DisplayMode {
DISPLAY_MODE_BLACK_AND_WHITE,
DISPLAY_MODE_GREYSCALE
DISPLAY_MODE_GREYSCALE,
DISPLAY_MODE_BLACK_AND_WHITE_LIGHT_SENSE
};
enum DisplayRotation {
@ -185,6 +190,12 @@ class MicroBitDisplay : public MicroBitComponent
*/
void render();
/**
* Renders the current image, and drops the fourth frame to allow for
* sensors that require the display to operate.
*/
void renderWithLightSense();
/**
* Translates a bit mask into a timer interrupt that gives the appearence of greyscale.
*/
@ -473,7 +484,7 @@ 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)
* @param mode The mode to swap the display into. (can be either DISPLAY_MODE_GREYSCALE, DISPLAY_MODE_BLACK_AND_WHITE, DISPLAY_MODE_BLACK_AND_WHITE_LIGHT_SENSE)
*
* Example:
* @code
@ -482,6 +493,12 @@ public:
*/
void setDisplayMode(DisplayMode mode);
/**
* Gets the mode of the display.
* @return the current mode of the display
*/
int getDisplayMode();
/**
* Fetches the current brightness of this display.
* @return the brightness of this display, in the range 0..255.

View File

@ -34,7 +34,7 @@ MicroBitDisplay::MicroBitDisplay(uint16_t id, uint8_t x, uint8_t y) :
this->width = x;
this->height = y;
this->strobeRow = 0;
this->strobeBitMsk = 0x20;
this->strobeBitMsk = MICROBIT_DISPLAY_ROW_RESET;
this->rotation = MICROBIT_DISPLAY_ROTATION_0;
this->greyscaleBitMsk = 0x01;
this->timingCount = 0;
@ -58,6 +58,12 @@ void MicroBitDisplay::systemTick()
if(!(uBit.flags & MICROBIT_FLAG_DISPLAY_RUNNING))
return;
if(mode == DISPLAY_MODE_BLACK_AND_WHITE_LIGHT_SENSE)
{
renderWithLightSense();
return;
}
// Move on to the next row.
strobeBitMsk <<= 1;
strobeRow++;
@ -65,7 +71,7 @@ void MicroBitDisplay::systemTick()
//reset the row counts and bit mask when we have hit the max.
if(strobeRow == MICROBIT_DISPLAY_ROW_COUNT){
strobeRow = 0;
strobeBitMsk = 0x20;
strobeBitMsk = MICROBIT_DISPLAY_ROW_RESET;
}
if(mode == DISPLAY_MODE_BLACK_AND_WHITE)
@ -146,6 +152,30 @@ void MicroBitDisplay::render()
renderFinish();
}
void MicroBitDisplay::renderWithLightSense()
{
//reset the row counts and bit mask when we have hit the max.
if(strobeRow == MICROBIT_DISPLAY_ROW_COUNT + 1)
{
MicroBitEvent(id, MICROBIT_DISPLAY_EVT_LIGHT_SENSE);
strobeRow = 0;
strobeBitMsk = MICROBIT_DISPLAY_ROW_RESET;
}
else
{
render();
this->animationUpdate();
// Move on to the next row.
strobeBitMsk <<= 1;
strobeRow++;
}
}
void MicroBitDisplay::renderGreyscale()
{
int coldata = 0;
@ -883,7 +913,7 @@ int MicroBitDisplay::setBrightness(int b)
/**
* 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)
* @param mode The mode to swap the display into. (can be either DISPLAY_MODE_GREYSCALE, DISPLAY_MODE_BLACK_AND_WHITE, DISPLAY_MODE_BLACK_AND_WHITE_LIGHT_SENSE)
*
* Example:
* @code
@ -895,6 +925,15 @@ void MicroBitDisplay::setDisplayMode(DisplayMode mode)
this->mode = mode;
}
/**
* Gets the mode of the display.
* @return the current mode of the display
*/
int MicroBitDisplay::getDisplayMode()
{
return this->mode;
}
/**
* Fetches the current brightness of this display.
* @return the brightness of this display, in the range 0..255.
@ -992,7 +1031,7 @@ void MicroBitDisplay::error(int statusCode)
disable(); //relinquish PWMOut's control
uint8_t strobeRow = 0;
uint8_t strobeBitMsk = 0x20;
uint8_t strobeBitMsk = MICROBIT_DISPLAY_ROW_RESET;
//point to the font stored in Flash
const unsigned char * fontLocation = MicroBitFont::defaultFont;
@ -1019,7 +1058,7 @@ void MicroBitDisplay::error(int statusCode)
if(strobeRow == 3)
{
strobeRow = 0;
strobeBitMsk = 0x20;
strobeBitMsk = MICROBIT_DISPLAY_ROW_RESET;
}
// Calculate the bitpattern to write.