Skip to content

Commit 58e88b9

Browse files
committed
Added front light API
1 parent 431489a commit 58e88b9

File tree

3 files changed

+57
-5
lines changed

3 files changed

+57
-5
lines changed

src/FastEPD.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,16 @@ int FASTEPD::loadG5Image(const uint8_t *pG5, int x, int y, int iFG, int iBG, flo
5858
return bbepLoadG5(&_state, pG5, x, y, iFG, iBG, fScale);
5959
}
6060

61+
void FASTEPD::setPasses(uint8_t iPartialPasses, uint8_t iFullPasses)
62+
{
63+
if (iPartialPasses > 0 && iPartialPasses < 15) { // reasonable numbers
64+
_state.iPartialPasses = iPartialPasses;
65+
}
66+
if (iFullPasses > 0 && iFullPasses < 15) { // reasonable numbers
67+
_state.iFullPasses = iFullPasses;
68+
}
69+
} /* setPasses() */
70+
6171
int FASTEPD::setRotation(int iAngle)
6272
{
6373
return bbepSetRotation(&_state, iAngle);
@@ -247,6 +257,15 @@ static uint8_t u8Unicode0, u8Unicode1;
247257
return 1;
248258
} /* write() */
249259

260+
void FASTEPD::setBrightness(uint8_t led1, uint8_t led2)
261+
{
262+
bbepSetBrightness(&_state, led1, led2);
263+
}
264+
void FASTEPD::initLights(uint8_t led1, uint8_t led2)
265+
{
266+
bbepInitLights(&_state, led1, led2);
267+
} /* initLights() */
268+
250269
int FASTEPD::initCustomPanel(BBPANELDEF *pPanel, BBPANELPROCS *pProcs)
251270
{
252271
_state.iPanelType = BB_PANEL_CUSTOM;

src/FastEPD.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,9 +178,11 @@ typedef struct tag_fastepdstate
178178
int iPanelType;
179179
uint8_t wrap, last_error, pwr_on, mode;
180180
uint8_t shift_data, anti_alias;
181+
uint8_t u8LED1, u8LED2;
181182
int iCursorX, iCursorY;
182183
int width, height, native_width, native_height;
183184
int rotation;
185+
int iPartialPasses, iFullPasses;
184186
int iScreenOffset, iOrientation;
185187
int iFG, iBG; //current color
186188
int iFont, iFlags;
@@ -209,6 +211,8 @@ class FASTEPD
209211
public:
210212
FASTEPD() {memset(&_state, 0, sizeof(_state)); _state.iFont = FONT_8x8; _state.iFG = BBEP_BLACK;}
211213
int initPanel(int iPanelType);
214+
void initLights(uint8_t led1, uint8_t led2 = 0xff);
215+
void setBrightness(uint8_t led1, uint8_t led2 = 0);
212216
int initCustomPanel(BBPANELDEF *pPanel, BBPANELPROCS *pProcs);
213217
int setPanelSize(int iPanel);
214218
int setCustomMatrix(const uint8_t *pMatrix, size_t matrix_size);
@@ -226,6 +230,7 @@ class FASTEPD
226230
int fullUpdate(bool bFast = false, bool bKeepOn = false, BBEPRECT *pRect = NULL);
227231
int partialUpdate(bool bKeepOn, int iStartRow = 0, int iEndRow = 4095);
228232
int smoothUpdate(bool bKeepOn, uint8_t u8Color);
233+
void setPasses(uint8_t iPartialPasses, uint8_t iFullPasses = 5);
229234
int setRotation(int iAngle);
230235
int getRotation(void) { return _state.rotation;}
231236
void backupPlane(void);

src/FastEPD.inl

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1122,6 +1122,8 @@ int bbepIOInit(FASTEPDSTATE *pState)
11221122
#endif
11231123
int rc = (*(pState->pfnIOInit))(pState);
11241124
if (rc != BBEP_SUCCESS) return rc;
1125+
pState->iPartialPasses = 4; // N.B. The default number of passes for partial updates
1126+
pState->iFullPasses = 5; // the default number of passes for smooth and full updates
11251127
// Initialize the ESP32 LCD API to drive parallel data at high speed
11261128
// The code forces the use of a D/C pin, so we must assign it to an unused GPIO on each device
11271129
s3_bus_config.dc_gpio_num = (gpio_num_t)pState->panelDef.ioDCDummy;
@@ -1245,6 +1247,32 @@ int bbepSetPanelSize(FASTEPDSTATE *pState, int width, int height, int flags) {
12451247
return BBEP_SUCCESS;
12461248
} /* setPanelSize() */
12471249

1250+
//
1251+
// Set the individual brightness of the 1 or 2 front lights
1252+
//
1253+
void bbepSetBrightness(FASTEPDSTATE *pState, uint8_t led1, uint8_t led2)
1254+
{
1255+
ledcWrite(pState->u8LED1, led1); // PWM (0-255)
1256+
if (pState->u8LED2 != 0xff) {
1257+
ledcWrite(pState->u8LED2, led2);
1258+
}
1259+
} /* bbepSetBrightness() */
1260+
1261+
//
1262+
// Initialize the front light(s) if present
1263+
//
1264+
void bbepInitLights(FASTEPDSTATE *pState, uint8_t led1, uint8_t led2)
1265+
{
1266+
pState->u8LED1 = led1;
1267+
pState->u8LED2 = led2;
1268+
ledcAttach(led1, 5000, 8); // attach pin to channel 0
1269+
ledcWrite(led1, 0); // set to off to start
1270+
if (led2 != 0xff) {
1271+
ledcAttach(led2, 5000, 8);
1272+
ledcWrite(led2, 0); // set to off
1273+
}
1274+
} /* bbepInitLights() */
1275+
12481276
//
12491277
// Initialize the panel based on the constant name
12501278
// Each name points to a configuration with info about the PCB and possibly a display
@@ -1468,8 +1496,8 @@ int bbepSmoothUpdate(FASTEPDSTATE *pState, bool bKeepOn, uint8_t u8Color)
14681496
}
14691497
}
14701498
} // for i
1471-
// Write 5 passes of the black data to the whole display
1472-
for (pass = 0; pass < 5; pass++) {
1499+
// Write N passes of the black data to the whole display
1500+
for (pass = 0; pass < pState->iFullPasses; pass++) {
14731501
bbepRowControl(pState, ROW_START);
14741502
for (i = 0; i < pState->native_height; i++) {
14751503
s = &pState->pTemp[i * (pState->native_width / 4)];
@@ -1607,8 +1635,8 @@ int bbepFullUpdate(FASTEPDSTATE *pState, bool bFast, bool bKeepOn, BBEPRECT *pRe
16071635
}
16081636
//vTaskDelay(0);
16091637
} // for i
1610-
// Write 5 passes of the black data to the whole display
1611-
for (pass = 0; pass < 5; pass++) {
1638+
// Write N passes of the black data to the whole display
1639+
for (pass = 0; pass < pState->iFullPasses; pass++) {
16121640
bbepRowControl(pState, ROW_START);
16131641
for (i = 0; i < pState->native_height; i++) {
16141642
s = &pState->pTemp[i * (pState->native_width / 4)];
@@ -1741,7 +1769,7 @@ int bbepPartialUpdate(FASTEPDSTATE *pState, bool bKeepOn, int iStartLine, int iE
17411769
iStartLine = iEndLine;
17421770
iEndLine = i;
17431771
}
1744-
for (pass = 0; pass < 4; pass++) { // each pass is about 32ms
1772+
for (pass = 0; pass < pState->iPartialPasses; pass++) { // each pass is about 32ms
17451773
uint8_t *dp = pState->pTemp;
17461774
int iDelta = pState->native_width / 4; // 2 bits per pixel
17471775
int iSkipped = 0;

0 commit comments

Comments
 (0)