1- #include " ScreenBuffer.h "
1+ #include < cstddef >
22#include < string.h>
3- #include < stddef.h>
4- #include " font.c"
3+ #include " device.h"
4+ #include " MonochromeScreenPatch.h"
5+ #include " ProgramVector.h"
6+ #include " PatchProcessor.h"
7+ #include " ServiceCall.h"
58
6- #if defined SSD1309
9+ #include " font.c " // todo load as resource
710
8- Colour ScreenBuffer::getPixel (unsigned int x, unsigned int y){
11+ PatchProcessor* getInitialisingPatchProcessor ();
12+
13+ static void onDrawCallback (uint8_t * pixels, uint16_t width, uint16_t height){
14+ MonochromeScreenPatch* patch = (MonochromeScreenPatch*)getInitialisingPatchProcessor ()->patch ;
15+ if (patch != NULL ){
16+ MonochromeScreenBuffer screen (width, height);
17+ screen.setBuffer (pixels);
18+ patch->processScreen (screen);
19+ }
20+ }
21+
22+ MonochromeScreenPatch::MonochromeScreenPatch (){
23+ void * drawArgs[] = {(void *)SYSTEM_FUNCTION_DRAW, (void *)&onDrawCallback};
24+ getProgramVector ()->serviceCall (OWL_SERVICE_REGISTER_CALLBACK, drawArgs, 2 );
25+ }
26+
27+ MonochromeScreenPatch::~MonochromeScreenPatch (){}
28+
29+ template <>
30+ Colour MonochromeScreenBuffer::getPixel (unsigned int x, unsigned int y){
931 if (x >= width || y >= height)
1032 return 0 ;
1133 uint8_t ucByteOffset = 0 ;
@@ -19,7 +41,8 @@ Colour ScreenBuffer::getPixel(unsigned int x, unsigned int y){
1941 // return pixels[y*width+x];
2042}
2143
22- void ScreenBuffer::setPixel (unsigned int x, unsigned int y, Colour c){
44+ template <>
45+ void MonochromeScreenBuffer::setPixel (unsigned int x, unsigned int y, Colour c){
2346 if (x < width && y < height){
2447 uint8_t ucByteOffset = 0 ;
2548 uint16_t usiArrayLoc = 0 ;
@@ -35,7 +58,8 @@ void ScreenBuffer::setPixel(unsigned int x, unsigned int y, Colour c){
3558 }
3659}
3760
38- void ScreenBuffer::invertPixel (unsigned int x, unsigned int y){
61+ template <>
62+ void MonochromeScreenBuffer::invertPixel (unsigned int x, unsigned int y){
3963 if (x < width && y < height){
4064 uint8_t ucByteOffset = 0 ;
4165 uint16_t usiArrayLoc = 0 ;
@@ -52,7 +76,8 @@ void ScreenBuffer::invertPixel(unsigned int x, unsigned int y){
5276 }
5377}
5478
55- void ScreenBuffer::fade (uint16_t steps){
79+ template <>
80+ void MonochromeScreenBuffer::fade (uint16_t steps){
5681 // for(unsigned int i=0; i<height*width; ++i)
5782 // pixels[i] =
5883 // (((pixels[i] & RED) >> steps) & RED) |
@@ -63,43 +88,9 @@ void ScreenBuffer::fade(uint16_t steps){
6388 // todo: update contrast setting
6489}
6590
66- void ScreenBuffer::fill (Colour c) {
91+ template <>
92+ void MonochromeScreenBuffer::fill (Colour c) {
6793 memset (pixels, c, height*width/8 );
6894 // for(unsigned int i=0; i<height*width; ++i)
6995 // pixels[i] = c;
7096}
71-
72- #elif defined SEPS114A
73-
74- Colour ScreenBuffer::getPixel (unsigned int x, unsigned int y){
75- if (x >= width || y >= height)
76- return 0 ;
77- return pixels[y*width+x];
78- }
79-
80- void ScreenBuffer::setPixel (unsigned int x, unsigned int y, Colour c){
81- if (x < width && y < height)
82- pixels[y*width+x] = c;
83- }
84-
85- void ScreenBuffer::invertPixel (unsigned int x, unsigned int y){
86- if (x < width && y < height)
87- pixels[y*width+x] ^= WHITE;
88- }
89-
90- void ScreenBuffer::fade (uint16_t steps){
91- for (int i=0 ; i<height*width; ++i)
92- pixels[i] =
93- (((pixels[i] & RED) >> steps) & RED) |
94- (((pixels[i] & GREEN) >> steps) & GREEN) |
95- (((pixels[i] & BLUE) >> steps) & BLUE);
96- }
97-
98- void ScreenBuffer::fill (Colour c) {
99- for (int i=0 ; i<height*width; ++i)
100- pixels[i] = c;
101- }
102-
103- #else
104- #error "Invalid screen configuration"
105- #endif
0 commit comments