Skip to content

Commit d450363

Browse files
committed
Update PBM preprocessor macros.
Define also preprocessor macros for LCD screen real sizes in pixels.
1 parent b3502d8 commit d450363

File tree

6 files changed

+77
-53
lines changed

6 files changed

+77
-53
lines changed

src/bin/daemon/LCDPlugins/LCDPlugin.cpp

Lines changed: 30 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ PBMFrame::PBMFrame(const uint16_t num)
3636
: _numFrames(num)
3737
{
3838
/* initialize PBM frame container */
39-
_PBMData.resize( (PBM_WIDTH / 8) * PBM_HEIGHT, 0 );
39+
_PBMData.resize( (DEFAULT_PBM_WIDTH / 8) * DEFAULT_PBM_HEIGHT, 0 );
4040
}
4141

4242
const bool PBMFrame::switchToNextFrame(const uint16_t currentFrameCounter)
@@ -167,7 +167,12 @@ void LCDPlugin::addPBMFrame(
167167
this->addPBMEmptyFrame(num);
168168

169169
try {
170-
this->readPBM(filePath.string(), _PBMFrames.back()._PBMData, PBM_WIDTH, PBM_HEIGHT);
170+
this->readPBM(
171+
filePath.string(),
172+
_PBMFrames.back()._PBMData,
173+
DEFAULT_PBM_WIDTH,
174+
DEFAULT_PBM_HEIGHT
175+
);
171176
}
172177
catch (const GLogiKExcept & e) {
173178
LOG(ERROR) << "exception while reading PBM file: " << filePath.string();
@@ -262,7 +267,7 @@ void LCDPlugin::drawProgressBarOnPBMFrame(
262267
const uint16_t PROGRESS_BAR_WIDTH = 102;
263268
const uint16_t PROGRESS_BAR_HEIGHT = 7;
264269

265-
if(PBMXPos + PROGRESS_BAR_WIDTH > (PBM_WIDTH - 1)) {
270+
if(PBMXPos + PROGRESS_BAR_WIDTH > (LCD_SCREEN_WIDTH - 1)) {
266271
std::ostringstream buffer(std::ios_base::app);
267272
buffer << "wrong progress bar X position : " << PBMXPos;
268273
GKSysLog(LOG_WARNING, WARNING, buffer.str());
@@ -332,7 +337,7 @@ void LCDPlugin::drawProgressBarOnPBMFrame(
332337
};
333338

334339
const uint16_t xByte = PBMXPos / 8;
335-
const uint16_t index = (PBM_WIDTH_IN_BYTES * PBMYPos) + xByte;
340+
const uint16_t index = (DEFAULT_PBM_WIDTH_IN_BYTES * PBMYPos) + xByte;
336341

337342
/* checking for out of range */
338343
frame.at(index+12);
@@ -348,9 +353,9 @@ void LCDPlugin::drawProgressBarOnPBMFrame(
348353
*/
349354
drawHorizontalLine(index);
350355
for(uint16_t i = 1; i < (PROGRESS_BAR_HEIGHT-1); ++i) {
351-
drawProgressBarLine(index + (PBM_WIDTH_IN_BYTES * i), i);
356+
drawProgressBarLine(index + (DEFAULT_PBM_WIDTH_IN_BYTES * i), i);
352357
}
353-
drawHorizontalLine(index + (PBM_WIDTH_IN_BYTES * (PROGRESS_BAR_HEIGHT-1)));
358+
drawHorizontalLine(index + (DEFAULT_PBM_WIDTH_IN_BYTES * (PROGRESS_BAR_HEIGHT-1)));
354359
}
355360
catch (const std::out_of_range& oor) {
356361
std::ostringstream buffer(std::ios_base::app);
@@ -365,35 +370,35 @@ void LCDPlugin::drawPadlockOnPBMFrame(
365370
const uint16_t PBMYPos)
366371
{
367372
const uint16_t xByte = PBMXPos / 8;
368-
const uint16_t index = (PBM_WIDTH_IN_BYTES * PBMYPos) + xByte;
373+
const uint16_t index = (DEFAULT_PBM_WIDTH_IN_BYTES * PBMYPos) + xByte;
369374

370375
PBMDataArray & frame = (*_itCurrentPBMFrame)._PBMData;
371376

372377
if( lockedPlugin ) {
373378
_everLocked = true;
374-
frame[index+(PBM_WIDTH_IN_BYTES * 0)] = 0b00000000;
375-
frame[index+(PBM_WIDTH_IN_BYTES * 1)] = 0b00110000;
376-
frame[index+(PBM_WIDTH_IN_BYTES * 2)] = 0b01001000;
377-
frame[index+(PBM_WIDTH_IN_BYTES * 3)] = 0b01111000;
378-
frame[index+(PBM_WIDTH_IN_BYTES * 4)] = 0b01111000;
379-
frame[index+(PBM_WIDTH_IN_BYTES * 5)] = 0b01111000;
379+
frame[index+(DEFAULT_PBM_WIDTH_IN_BYTES * 0)] = 0b00000000;
380+
frame[index+(DEFAULT_PBM_WIDTH_IN_BYTES * 1)] = 0b00110000;
381+
frame[index+(DEFAULT_PBM_WIDTH_IN_BYTES * 2)] = 0b01001000;
382+
frame[index+(DEFAULT_PBM_WIDTH_IN_BYTES * 3)] = 0b01111000;
383+
frame[index+(DEFAULT_PBM_WIDTH_IN_BYTES * 4)] = 0b01111000;
384+
frame[index+(DEFAULT_PBM_WIDTH_IN_BYTES * 5)] = 0b01111000;
380385
}
381386
else {
382387
if( _everLocked ) {
383-
frame[index+(PBM_WIDTH_IN_BYTES * 0)] = 0b00000110;
384-
frame[index+(PBM_WIDTH_IN_BYTES * 1)] = 0b00001001;
385-
frame[index+(PBM_WIDTH_IN_BYTES * 2)] = 0b00001000;
386-
frame[index+(PBM_WIDTH_IN_BYTES * 3)] = 0b01111000;
387-
frame[index+(PBM_WIDTH_IN_BYTES * 4)] = 0b01111000;
388-
frame[index+(PBM_WIDTH_IN_BYTES * 5)] = 0b01111000;
388+
frame[index+(DEFAULT_PBM_WIDTH_IN_BYTES * 0)] = 0b00000110;
389+
frame[index+(DEFAULT_PBM_WIDTH_IN_BYTES * 1)] = 0b00001001;
390+
frame[index+(DEFAULT_PBM_WIDTH_IN_BYTES * 2)] = 0b00001000;
391+
frame[index+(DEFAULT_PBM_WIDTH_IN_BYTES * 3)] = 0b01111000;
392+
frame[index+(DEFAULT_PBM_WIDTH_IN_BYTES * 4)] = 0b01111000;
393+
frame[index+(DEFAULT_PBM_WIDTH_IN_BYTES * 5)] = 0b01111000;
389394
}
390395
else {
391-
frame[index+(PBM_WIDTH_IN_BYTES * 0)] = 0;
392-
frame[index+(PBM_WIDTH_IN_BYTES * 1)] = 0;
393-
frame[index+(PBM_WIDTH_IN_BYTES * 2)] = 0;
394-
frame[index+(PBM_WIDTH_IN_BYTES * 3)] = 0;
395-
frame[index+(PBM_WIDTH_IN_BYTES * 4)] = 0;
396-
frame[index+(PBM_WIDTH_IN_BYTES * 5)] = 0;
396+
frame[index+(DEFAULT_PBM_WIDTH_IN_BYTES * 0)] = 0;
397+
frame[index+(DEFAULT_PBM_WIDTH_IN_BYTES * 1)] = 0;
398+
frame[index+(DEFAULT_PBM_WIDTH_IN_BYTES * 2)] = 0;
399+
frame[index+(DEFAULT_PBM_WIDTH_IN_BYTES * 3)] = 0;
400+
frame[index+(DEFAULT_PBM_WIDTH_IN_BYTES * 4)] = 0;
401+
frame[index+(DEFAULT_PBM_WIDTH_IN_BYTES * 5)] = 0;
397402
}
398403
}
399404
}

src/bin/daemon/LCDPlugins/PBM.hpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,15 @@
2525
#include <array>
2626
#include <vector>
2727

28-
#define PBM_HEIGHT 48
29-
#define PBM_WIDTH 160
30-
#define PBM_HEIGHT_IN_BYTES (PBM_HEIGHT / 8)
31-
#define PBM_WIDTH_IN_BYTES (PBM_WIDTH / 8)
32-
#define PBM_DATA_IN_BYTES ( PBM_WIDTH_IN_BYTES * PBM_HEIGHT )
28+
#define LCD_SCREEN_HEIGHT 43
29+
#define LCD_SCREEN_WIDTH 160
30+
31+
#define DEFAULT_PBM_HEIGHT 48
32+
#define DEFAULT_PBM_WIDTH 160
33+
#define DEFAULT_PBM_HEIGHT_IN_BYTES (DEFAULT_PBM_HEIGHT/8)
34+
#define DEFAULT_PBM_WIDTH_IN_BYTES (DEFAULT_PBM_WIDTH/8)
35+
36+
#define PBM_DATA_IN_BYTES (DEFAULT_PBM_WIDTH_IN_BYTES * DEFAULT_PBM_HEIGHT)
3337

3438
/* LCD header length */
3539
#define LCD_BUFFER_OFFSET 32

src/bin/daemon/LCDPlugins/PBMFont.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ PBMFont::~PBMFont()
112112

113113
const uint16_t PBMFont::getCenteredXPos(const std::string & string)
114114
{
115-
uint16_t XPos = PBM_WIDTH;
115+
uint16_t XPos = LCD_SCREEN_WIDTH;
116116
for(const char & c : string) {
117117
XPos -= (_charWidth - _fontLeftShift);
118118
// XXX
@@ -127,7 +127,7 @@ const uint16_t PBMFont::getCenteredXPos(const std::string & string)
127127

128128
const uint16_t PBMFont::getCenteredYPos(void)
129129
{
130-
uint16_t YPos = PBM_HEIGHT; // FIXME LCD_HEIGHT
130+
uint16_t YPos = LCD_SCREEN_HEIGHT;
131131
YPos -= _charHeight;
132132
return static_cast<uint16_t>(YPos/2);
133133
}
@@ -148,12 +148,12 @@ void PBMFont::printCharacterOnFrame(
148148
throw GLogiKExcept( warn.str() );
149149
}
150150

151-
if(PBMXPos >= (PBM_WIDTH - _charWidth)) {
151+
if(PBMXPos >= (LCD_SCREEN_WIDTH - _charWidth)) {
152152
std::ostringstream warn(_fontName, std::ios_base::app);
153153
warn << " font : pre-breaking write string loop : x : " << std::to_string(PBMXPos);
154154
throw GLogiKExcept( warn.str() );
155155
}
156-
if(PBMYPos >= (PBM_HEIGHT - _charHeight)) {
156+
if(PBMYPos >= (LCD_SCREEN_HEIGHT - _charHeight)) {
157157
std::ostringstream warn(_fontName, std::ios_base::app);
158158
warn << " font : pre-breaking write string loop : y : " << std::to_string(PBMYPos);
159159
throw GLogiKExcept( warn.str() );
@@ -180,7 +180,7 @@ void PBMFont::printCharacterOnFrame(
180180
for(uint16_t i = 0; i < _charHeight; i++) {
181181
for(uint16_t j = 0; j < _charBytes; j++) {
182182
const unsigned char c = this->getCharacterLine(i, j);
183-
index = (PBM_WIDTH_IN_BYTES * (PBMYPos+i)) + xByte + j;
183+
index = (DEFAULT_PBM_WIDTH_IN_BYTES * (PBMYPos+i)) + xByte + j;
184184

185185
frame.at(index) &= (0b11111111 << xModuloComp8);
186186
if(rightShift > 0) {

src/bin/daemon/LCDPlugins/fonts.hpp

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,11 @@
2424

2525
#include <cstdint>
2626

27-
#include "PBMFont.hpp"
2827
#include "PBM.hpp"
28+
#include "PBMFont.hpp"
29+
30+
#define DEFAULT_PBM_FONT_HEIGHT DEFAULT_PBM_HEIGHT
31+
#define DEFAULT_PBM_FONT_WIDTH DEFAULT_PBM_WIDTH
2932

3033
namespace GLogiK
3134
{
@@ -45,7 +48,13 @@ class FontMonospace85
4548
{
4649
public:
4750
FontMonospace85(void)
48-
: PBMFont("monospace85", PBM_WIDTH, PBM_HEIGHT, 5, 10) {};
51+
: PBMFont(
52+
"monospace85",
53+
DEFAULT_PBM_FONT_WIDTH,
54+
DEFAULT_PBM_FONT_HEIGHT,
55+
5,
56+
10
57+
) {};
4958
~FontMonospace85() = default;
5059

5160
protected:
@@ -59,7 +68,13 @@ class FontMonospace86
5968
{
6069
public:
6170
FontMonospace86(void)
62-
: PBMFont("monospace86", PBM_WIDTH, PBM_HEIGHT, 6, 10) {};
71+
: PBMFont(
72+
"monospace86",
73+
DEFAULT_PBM_FONT_WIDTH,
74+
DEFAULT_PBM_FONT_HEIGHT,
75+
6,
76+
10
77+
) {};
6378
~FontMonospace86() = default;
6479

6580
protected:

src/bin/daemon/LCDPlugins/systemMonitor.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,8 +243,8 @@ const PBMDataArray & SystemMonitor::getNextPBMFrame(
243243
const uint16_t FONT_CHAR_WIDTH = 5;
244244

245245
/* padded percentage string size is always 5 chars */
246-
const uint16_t PERC_POS_X = (PBM_WIDTH - 1) - (5 * FONT_CHAR_WIDTH);
247-
const uint16_t NET_POS_X = (PBM_WIDTH - 1) - (paddedRateString.size() * FONT_CHAR_WIDTH);
246+
const uint16_t PERC_POS_X = (LCD_SCREEN_WIDTH - 1) - (5 * FONT_CHAR_WIDTH);
247+
const uint16_t NET_POS_X = (LCD_SCREEN_WIDTH - 1) - (paddedRateString.size() * FONT_CHAR_WIDTH);
248248

249249
/* percent - max 5 chars */
250250
/* net rate - max 12 chars */

src/bin/daemon/LCDScreenPluginsManager.cpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -257,13 +257,13 @@ void LCDScreenPluginsManager::stopLCDPlugins(void) {
257257
* -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
258258
* A7 A6 A5 A4 A3 A2 A1 A0 B7 B6 B5 B4 B3 B2 B1 B0 . .
259259
* U7 U6 U5 U4 U3 U2 U1 U0 . . . . . . . . . . --->
260-
* . . . . . . . . . . . . . . . . . . ---> on PBM_WIDTH_IN_BYTES bytes
260+
* . . . . . . . . . . . . . . . . . . ---> on DEFAULT_PBM_WIDTH_IN_BYTES bytes
261261
* . . . . . . . . . . . . . . . . . . --->
262262
* . . . . . . . . . . . . . . . . . .
263263
* | | |
264264
* \ /
265265
* \ /
266-
* on PBM_HEIGHT bytes
266+
* on DEFAULT_PBM_HEIGHT bytes
267267
*
268268
* -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
269269
* LCD data binary format (without header). Description coming from libg15.
@@ -307,10 +307,10 @@ void LCDScreenPluginsManager::stopLCDPlugins(void) {
307307
*/
308308
void LCDScreenPluginsManager::dumpPBMDataIntoLCDBuffer(LCDDataArray & LCDBuffer, const PBMDataArray & PBMData)
309309
{
310-
for(unsigned int row = 0; row < PBM_HEIGHT_IN_BYTES; ++row) {
310+
for(unsigned int row = 0; row < DEFAULT_PBM_HEIGHT_IN_BYTES; ++row) {
311311
unsigned int LCDCol = 0;
312-
unsigned int indexOffset = (PBM_WIDTH * row);
313-
for(unsigned int PBMByte = 0; PBMByte < PBM_WIDTH_IN_BYTES; ++PBMByte) {
312+
unsigned int indexOffset = (DEFAULT_PBM_WIDTH * row);
313+
for(unsigned int PBMByte = 0; PBMByte < DEFAULT_PBM_WIDTH_IN_BYTES; ++PBMByte) {
314314

315315
for(int bit = 7; bit > -1; --bit) {
316316

@@ -324,14 +324,14 @@ void LCDScreenPluginsManager::dumpPBMDataIntoLCDBuffer(LCDDataArray & LCDBuffer,
324324
#endif
325325

326326
LCDBuffer[LCD_BUFFER_OFFSET + LCDCol + indexOffset] =
327-
(((PBMData[PBMByte + (PBM_WIDTH_IN_BYTES * 0) + indexOffset] >> bit) & 1) << 0 ) |
328-
(((PBMData[PBMByte + (PBM_WIDTH_IN_BYTES * 1) + indexOffset] >> bit) & 1) << 1 ) |
329-
(((PBMData[PBMByte + (PBM_WIDTH_IN_BYTES * 2) + indexOffset] >> bit) & 1) << 2 ) |
330-
(((PBMData[PBMByte + (PBM_WIDTH_IN_BYTES * 3) + indexOffset] >> bit) & 1) << 3 ) |
331-
(((PBMData[PBMByte + (PBM_WIDTH_IN_BYTES * 4) + indexOffset] >> bit) & 1) << 4 ) |
332-
(((PBMData[PBMByte + (PBM_WIDTH_IN_BYTES * 5) + indexOffset] >> bit) & 1) << 5 ) |
333-
(((PBMData[PBMByte + (PBM_WIDTH_IN_BYTES * 6) + indexOffset] >> bit) & 1) << 6 ) |
334-
(((PBMData[PBMByte + (PBM_WIDTH_IN_BYTES * 7) + indexOffset] >> bit) & 1) << 7 ) ;
327+
(((PBMData[PBMByte + (DEFAULT_PBM_WIDTH_IN_BYTES * 0) + indexOffset] >> bit) & 1) << 0 ) |
328+
(((PBMData[PBMByte + (DEFAULT_PBM_WIDTH_IN_BYTES * 1) + indexOffset] >> bit) & 1) << 1 ) |
329+
(((PBMData[PBMByte + (DEFAULT_PBM_WIDTH_IN_BYTES * 2) + indexOffset] >> bit) & 1) << 2 ) |
330+
(((PBMData[PBMByte + (DEFAULT_PBM_WIDTH_IN_BYTES * 3) + indexOffset] >> bit) & 1) << 3 ) |
331+
(((PBMData[PBMByte + (DEFAULT_PBM_WIDTH_IN_BYTES * 4) + indexOffset] >> bit) & 1) << 4 ) |
332+
(((PBMData[PBMByte + (DEFAULT_PBM_WIDTH_IN_BYTES * 5) + indexOffset] >> bit) & 1) << 5 ) |
333+
(((PBMData[PBMByte + (DEFAULT_PBM_WIDTH_IN_BYTES * 6) + indexOffset] >> bit) & 1) << 6 ) |
334+
(((PBMData[PBMByte + (DEFAULT_PBM_WIDTH_IN_BYTES * 7) + indexOffset] >> bit) & 1) << 7 ) ;
335335

336336
LCDCol++;
337337
}

0 commit comments

Comments
 (0)