Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NRF52LEDMatrix::rotateTo #227

Merged
merged 1 commit into from
Sep 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion inc/NRF52LedMatrix.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ namespace codal
uint8_t timeslots; // The total number of timeslots used by the driver (includes light sensing).
DisplayMode mode; // The currnet display mode being used.
bool enabled; // Whether or not the display is enabled.
uint8_t rotation; // DisplayRotation

const MatrixMap &matrixMap; // Data structure that maps screen x/y pixels into GPIO pins.
NRFLowLevelTimer &timer; // The timer module used to drive this LEDMatrix.
Expand All @@ -63,7 +64,6 @@ namespace codal
int8_t gpiote[NRF52_LED_MATRIX_MAXIMUM_COLUMNS]; // GPIOTE channels used by output columns.
int8_t ppi[NRF52_LED_MATRIX_MAXIMUM_COLUMNS]; // PPI channels used by output columns.


public:
/**
* Configure the next frame to be drawn.
Expand Down Expand Up @@ -102,6 +102,17 @@ namespace codal
*/
DisplayMode getDisplayMode();

/**
* Rotates the display to the given position.
*
* Axis aligned values only.
*
* @code
* display.rotateTo(DISPLAY_ROTATION_180); //rotates 180 degrees from original orientation
* @endcode
*/
void rotateTo(DisplayRotation position);

/**
* Enables the display, should only be called if the display is disabled.
*
Expand Down
34 changes: 33 additions & 1 deletion source/NRF52LedMatrix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ static void display_irq(uint16_t mask)
*/
NRF52LEDMatrix::NRF52LEDMatrix(NRFLowLevelTimer &displayTimer, const MatrixMap &map, uint16_t id, DisplayMode mode) : Display(map.width, map.height, id), matrixMap(map), timer(displayTimer)
{
rotation = MATRIX_DISPLAY_ROTATION_0;
enabled = false;
strobeRow = 0;
instance = this;
Expand Down Expand Up @@ -127,6 +128,20 @@ DisplayMode NRF52LEDMatrix::getDisplayMode()
return this->mode;
}

/**
* Rotates the display to the given position.
*
* Axis aligned values only.
*
* @code
* display.rotateTo(MATRIX_DISPLAY_ROTATION_180); //rotates 180 degrees from original orientation
* @endcode
*/
void NRF52LEDMatrix::rotateTo(DisplayRotation rotation)
{
this->rotation = rotation;
}

/**
* Enables the display, should only be called if the display is disabled.
*
Expand Down Expand Up @@ -230,7 +245,24 @@ void NRF52LEDMatrix::render()

for (int column = 0; column < matrixMap.columns; column++)
{
value = screenBuffer[p->y * width + p->x];
switch ( this->rotation)
{
case MATRIX_DISPLAY_ROTATION_0:
value = screenBuffer[ p->y * width + p->x];
break;
case MATRIX_DISPLAY_ROTATION_90:
value = screenBuffer[ p->x * width + width - 1 - p->y];
break;
case MATRIX_DISPLAY_ROTATION_180:
value = screenBuffer[ (height - 1 - p->y) * width + width - 1 - p->x];
break;
case MATRIX_DISPLAY_ROTATION_270:
value = screenBuffer[ ( height - 1 - p->x) * width + p->y];
break;
default:
value = screenBuffer[ p->y * width + p->x];
break;
}

// Clip pixels to full or zero brightness if in black and white mode.
if (mode == DISPLAY_MODE_BLACK_AND_WHITE || mode == DISPLAY_MODE_BLACK_AND_WHITE_LIGHT_SENSE)
Expand Down