-
Notifications
You must be signed in to change notification settings - Fork 14
/
LedDriverPowerShiftRegister.cpp
132 lines (116 loc) · 3.49 KB
/
LedDriverPowerShiftRegister.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
/**
* LedDriverPowerShiftRegister
* Implementierung auf der Basis von TPICB595N.
*
* @mc Arduino/RBBB
* @autor Christian Aschoff / caschoff _AT_ mac _DOT_ com
* @version 1.3
* @created 13.8.2013
* @updated 16.2.2015
*
* Versionshistorie:
* V 1.0: - Erstellt.
* V 1.1: - Anpassung auf Helligkeit 0-100%
* V 1.2: - Getter fuer Helligkeit nachgezogen.
* V 1.3: - Unterstuetzung fuer die alte Arduino-IDE (bis 1.0.6) entfernt.
*/
#include "LedDriverPowerShiftRegister.h"
// #define DEBUG
#include "Debug.h"
#include "Configuration.h"
/**
* Initialisierung.
*
* @param data Pin, an dem die Data-Line haengt.
* @param clock Pin, an dem die Clock-Line haengt.
* @param latch Pin, an dem die Latch-Line haengt.
* @param outputEnable Pin, an dem OutputEnable haengt.
*/
LedDriverPowerShiftRegister::LedDriverPowerShiftRegister(byte data, byte clock, byte latch, byte outputEnable) {
_outputEnable = outputEnable;
_shiftRegister = new ShiftRegister(data, clock, latch);
_brightnessInPercent = 100;
}
/**
* init() wird im Hauptprogramm in init() aufgerufen.
* Hier sollten die LED-Treiber in eine definierten
* Ausgangszustand gebracht werden.
*/
void LedDriverPowerShiftRegister::init() {
}
void LedDriverPowerShiftRegister::printSignature() {
DEBUG_PRINTLN(F("Power Shift Register (TPICB595N)"));
}
/**
* Den Bildschirm-Puffer auf die LED-Matrix schreiben.
*
* @param onChange: TRUE, wenn es Aenderungen in dem Bildschirm-Puffer gab,
* FALSE, wenn es ein Refresh-Aufruf war.
*/
void LedDriverPowerShiftRegister::writeScreenBufferToMatrix(word matrix[16], boolean onChange, eColors a_color) {
if (onChange) {
_shiftRegister->prepareShiftregisterWrite();
// die letzten 6 Outputs sind frei - padding
for (byte p = 0; p < 6; p++) {
_shiftRegister->shiftOutABit(false);
}
// dann Ecken...
// unten links...
_shiftRegister->shiftOutABit(getPixelFromScreenBuffer(11, 3, matrix));
// unten rechts...
_shiftRegister->shiftOutABit(getPixelFromScreenBuffer(11, 2, matrix));
// oben rechts...
_shiftRegister->shiftOutABit(getPixelFromScreenBuffer(11, 1, matrix));
// oben links...
_shiftRegister->shiftOutABit(getPixelFromScreenBuffer(11, 0, matrix));
// dann weiter...
for (int x = 10; x >= 0; x--) {
for (int y = 9; y >= 0; y--) {
_shiftRegister->shiftOutABit(getPixelFromScreenBuffer(x, y, matrix));
}
}
_shiftRegister->finishShiftregisterWrite();
}
}
/**
* Die Helligkeit des Displays anpassen.
*
* @param brightnessInPercent Die Helligkeit.
*/
void LedDriverPowerShiftRegister::setBrightness(byte brightnessInPercent) {
// wegen eines fehlerhaften Platinen-Layouts geht die Helligkeit hier im Moment nicht.
}
/**
* Die aktuelle Helligkeit bekommen.
*/
byte LedDriverPowerShiftRegister::getBrightness() {
return _brightnessInPercent;
}
/**
* Anpassung der Groesse des Bildspeichers.
*
* @param linesToWrite Wieviel Zeilen aus dem Bildspeicher sollen
* geschrieben werden?
*/
void LedDriverPowerShiftRegister::setLinesToWrite(byte linesToWrite) {
}
/**
* Das Display ausschalten.
*/
void LedDriverPowerShiftRegister::shutDown() {
digitalWrite(_outputEnable, HIGH);
}
/**
* Das Display einschalten.
*/
void LedDriverPowerShiftRegister::wakeUp() {
digitalWrite(_outputEnable, LOW);
}
/**
* Den Dateninhalt des LED-Treibers loeschen.
*/
void LedDriverPowerShiftRegister::clearData() {
for (int sr = 0; sr < 15; sr++) {
_shiftRegister->shiftOut(0);
}
}