2019-12-13 19:23:10 +01:00
|
|
|
#include "panel.hpp"
|
|
|
|
|
2019-12-14 00:40:23 +01:00
|
|
|
Panel::Panel(uint8_t pData, uint8_t pClock, uint8_t pLoad, int x, int y)
|
2019-12-13 23:10:20 +01:00
|
|
|
{
|
|
|
|
pinData = pData;
|
|
|
|
pinLoad = pLoad;
|
|
|
|
pinClock = pClock;
|
2019-12-14 00:40:23 +01:00
|
|
|
|
|
|
|
posX = x;
|
|
|
|
posY = y;
|
2019-12-13 23:10:20 +01:00
|
|
|
}
|
2019-12-13 19:23:10 +01:00
|
|
|
|
|
|
|
void Panel::init()
|
|
|
|
{
|
2019-12-13 23:10:20 +01:00
|
|
|
pinMode(pinData, OUTPUT);
|
|
|
|
pinMode(pinClock, OUTPUT);
|
|
|
|
pinMode(pinLoad, OUTPUT);
|
2023-04-24 21:52:33 +02:00
|
|
|
Serial.println(F("Panel init"));
|
2019-12-13 19:23:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void Panel::send_image(Image* img) {
|
2019-12-14 00:40:23 +01:00
|
|
|
int endY = posY + PANEL_HEIGHT;
|
|
|
|
int endX = posX + PANEL_WIDTH;
|
|
|
|
|
|
|
|
for (int y = posY; y < endY; y += 8) {
|
|
|
|
for (int x = posX; x < endX; x += 4) {
|
2023-04-24 21:52:33 +02:00
|
|
|
send_block(img, x, y);
|
2019-12-13 19:23:10 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
load();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Panel::clock() {
|
2019-12-13 23:10:20 +01:00
|
|
|
//PORTA |= (1 << PA2);
|
|
|
|
//PORTA &= ~(1 << PA2);
|
|
|
|
digitalWrite(pinClock, HIGH);
|
|
|
|
digitalWrite(pinClock, LOW);
|
2019-12-13 19:23:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void Panel::load() {
|
2019-12-13 23:10:20 +01:00
|
|
|
//PORTB |= (1 << PB0);
|
|
|
|
//PORTB &= ~(1 << PB0);
|
|
|
|
digitalWrite(pinLoad, HIGH);
|
|
|
|
digitalWrite(pinLoad, LOW);
|
2019-12-13 19:23:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Panel::send_block(Image* p, int x, int y) {
|
|
|
|
int order[32][2] = {
|
|
|
|
{ 1, 1 }, // 1
|
|
|
|
{ 1, 0 }, // 2
|
|
|
|
{ 0, 1 }, // 3
|
|
|
|
{ 1, 2 }, // 4
|
|
|
|
{ 0, 2 }, // 5
|
|
|
|
{ 1, 3 }, // 6
|
|
|
|
{ 0, 0 }, // 7
|
|
|
|
{ 0, 3 }, // 8
|
|
|
|
{ 0, 4 }, // 9
|
|
|
|
{ 1, 4 }, // 10
|
|
|
|
{ 0, 5 }, // 11
|
|
|
|
{ 1, 7 }, // 12
|
|
|
|
{ 1, 5 }, // 13
|
|
|
|
{ 0, 6 }, // 14
|
|
|
|
{ 1, 6 }, // 15
|
|
|
|
{ 0, 7 }, // 16
|
|
|
|
{ 3, 7 }, // 17
|
|
|
|
{ 2, 6 }, // 18
|
|
|
|
{ 2, 7 }, // 19
|
|
|
|
{ 3, 6 }, // 20
|
|
|
|
{ 2, 5 }, // 21
|
|
|
|
{ 3, 5 }, // 22
|
|
|
|
{ 3, 4 }, // 23
|
|
|
|
{ 2, 4 }, // 24
|
|
|
|
{ 3, 3 }, // 25
|
|
|
|
{ 2, 0 }, // 26
|
|
|
|
{ 3, 0 }, // 27
|
|
|
|
{ 2, 3 }, // 28
|
|
|
|
{ 3, 2 }, // 29
|
|
|
|
{ 2, 1 }, // 30
|
|
|
|
{ 3, 1 }, // 31
|
|
|
|
{ 2, 2 }, // 32
|
|
|
|
};
|
|
|
|
|
|
|
|
for (int n = 0; n < 32; n++) {
|
|
|
|
int x_offset = order[n][0];
|
|
|
|
int y_offset = order[n][1];
|
|
|
|
|
|
|
|
byte pixel = p->get_pixel(x + x_offset, y + y_offset);
|
|
|
|
|
2019-12-13 23:10:20 +01:00
|
|
|
/*if(pixel)
|
2019-12-13 19:23:10 +01:00
|
|
|
{
|
2019-12-13 23:10:20 +01:00
|
|
|
PORTB |= (1 << PB2);
|
2019-12-13 19:23:10 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-12-13 23:10:20 +01:00
|
|
|
PORTB &= ~(1 << PB2);
|
|
|
|
}*/
|
2019-12-13 19:23:10 +01:00
|
|
|
|
2019-12-13 23:10:20 +01:00
|
|
|
digitalWrite(pinData, pixel);
|
2019-12-13 19:23:10 +01:00
|
|
|
clock();
|
|
|
|
}
|
|
|
|
|
|
|
|
// 33 bit - kein pixel - senden
|
|
|
|
clock();
|
|
|
|
}
|
|
|
|
|