forked from RebelTechnology/OpenWare
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Graphics.cpp
65 lines (55 loc) · 1.52 KB
/
Graphics.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include "device.h"
#include "Graphics.h"
#include "errorhandlers.h"
#include "oled.h"
#include "callbacks.h"
#include "ProgramVector.h"
Graphics::Graphics() :
screen(OLED_WIDTH, OLED_HEIGHT),
drawCallback(defaultDrawCallback) {
screen.clear();
}
void Graphics::begin(ParameterController* pc, SPI_HandleTypeDef *spi) {
params = pc;
oled_init(spi);
screen.setBuffer(pixelbuffer);
screen.clear();
reset();
display();
}
void Graphics::display(){
oled_write(pixelbuffer, OLED_BUFFER_SIZE);
}
void Graphics::draw(){
params->draw(screen);
}
// static void defaultDrawCallback(uint8_t* pixels, uint16_t width, uint16_t height){
// graphics.screen.setBuffer(pixels);
// graphics.screen.clear();
// graphics.params->draw(graphics.screen);
// }
void Graphics::reset(){
drawCallback = defaultDrawCallback;
params->reset();
}
void Graphics::setCallback(void *callback){
if(callback == NULL)
drawCallback = defaultDrawCallback;
else
drawCallback = (void (*)(uint8_t*, uint16_t, uint16_t))callback;
}
__weak void defaultDrawCallback(uint8_t* pixels, uint16_t width, uint16_t height){
// doDefaultDrawCallback(graphics.screen);
ScreenBuffer screen = graphics.screen;
// draw title
screen.setTextSize(2);
screen.print(0, 16, graphics.params->getTitle());
// draw program message, if set
ProgramVector* pv = getProgramVector();
if(pv != NULL && pv->message != NULL){
screen.setTextSize(1);
screen.setTextWrap(true);
screen.print(0, 26, pv->message);
screen.setTextWrap(false);
}
}