33#ifndef SMOOTH_PROGRESS_H
34#define SMOOTH_PROGRESS_H
36#define SMOOTH_PROGRESS_VER 1.0.0
41#if defined(LiquidCrystal_I2C_h)
42#define LCD_OBJ LiquidCrystal_I2C
44#elif defined(hd44780_I2Cexp_h)
45#define LCD_OBJ hd44780_I2Cexp
46#elif defined(hd44780_HC1627_I2C_h)
47#define LCD_OBJ hd44780_HC1627_I2C
48#elif defined(hd44780_I2Clcd_h)
49#define LCD_OBJ hd44780_I2Clcd
50#elif defined(FDB_LIQUID_CRYSTAL_I2C_H)
51#define LCD_OBJ LiquidCrystal_I2C
52#elif defined(LiquidCrystal_h)
53#define LCD_OBJ LiquidCrystal
55#define LCD_OBJ ERROR_NO_LCD_OBJ
56#error "No supported LiquidCrystal library included. Please check that the LiquidCrystal library is included BEFORE SmoothProgress.h"
60enum MemoryType { RAM = 0, FLASH = 1, DATA = 0, PROG = 1 };
62class __FlashBarStyleHelper;
63#define FBS(style) (reinterpret_cast<const __FlashBarStyleHelper *>(style))
81 inline const barstyle* unwrap()
const {
return bsp; }
86template <
class DISP = LCD_OBJ>
91 enum UDCharCode :
byte { ProgBarCharBlank = 0, ProgBarCharFull, ProgBarCharBegin, ProgBarCharEnd, ProgBarCharPartial };
109 BarDisplay(DISP& displ,
const inPROGMEM& wraped) : disp(displ), barStyle(wraped.unwrap()), styleMemPlacement(FLASH) { }
111 BarDisplay(DISP& displ,
const barstyle* bsp) : disp(displ), barStyle(bsp), styleMemPlacement(RAM) { }
112 BarDisplay(DISP& displ,
const __FlashBarStyleHelper* bspf) : disp(displ), barStyle(bspf), styleMemPlacement(FLASH) { }
142 styleMemPlacement = RAM;
152 barStyle = wraped.unwrap();
153 styleMemPlacement = FLASH;
163 if (styleMemPlacement == RAM)
165 return(barStyle->stylePar);
169 uint8_t m = pgm_read_byte(&(barStyle->stylePar));
207 createChar(ProgBarCharBlank, (barStyle->middleMask[barstyle::ORmask]));
209 createChar(ProgBarCharFull, barStyle->middleMask);
211 createChar(ProgBarCharBegin, barStyle->startMask);
213 createChar(ProgBarCharEnd, (barStyle->endMask[barstyle::ORmask]));
222 void makeChar(
byte udChr,
const uint8_t xMask[2][barstyle::CharPatRows], uint8_t mask)
const
224 uint8_t t[barstyle::CharPatRows];
225 if (styleMemPlacement == RAM)
231 uint8_t tao[2][barstyle::CharPatRows];
232 memcpy_P(tao, xMask, barstyle::CharPatRows << 1);
235 disp.createChar(udChr, t);
245 void makeCharMask(uint8_t out[barstyle::CharPatRows],
const uint8_t xMask[2][barstyle::CharPatRows], uint8_t mask)
const
249 for (
byte i = 0; i < barstyle::CharPatRows; i++, mask >>= 1)
251 out[i] = (mask & 1) ? (xMask[0][i] | xMask[1][i]) : xMask[1][i];
256 for (
byte i = 0; i < barstyle::CharPatRows; i++)
258 out[i] = (mask & xMask[0][i]) | xMask[1][i];
269 void createChar(
byte udChr,
const uint8_t bitMask[barstyle::CharPatRows])
const
271 if (styleMemPlacement == RAM)
273 disp.createChar(udChr,
const_cast<uint8_t*
>(bitMask));
277 uint8_t ta[barstyle::CharPatRows];
278 memcpy_P(ta, bitMask, barstyle::CharPatRows);
279 disp.createChar(udChr, ta);
289 void createChar(
byte udChr,
const uint8_t xMask[2][barstyle::CharPatRows])
const
291 if (styleMemPlacement == RAM)
293 uint8_t t[barstyle::CharPatRows];
294 for (
byte i = 0; i < barstyle::CharPatRows; i++)
296 t[i] = xMask[0][i] | xMask[1][i];
298 disp.createChar(udChr, t);
302 uint8_t tao[2][barstyle::CharPatRows];
303 memcpy_P(tao, xMask, barstyle::CharPatRows << 1);
304 for (
byte i = 0; i < barstyle::CharPatRows; i++)
306 tao[0][i] |= tao[1][i];
308 disp.createChar(udChr, tao[0]);
314 MemoryType styleMemPlacement;
330 BarPos(
byte _len,
byte _col,
byte _row,
byte _id = 0)
331 : par(
ProgBarPar{ _col, _row, _len, _id }) { }
368 inline uint8_t
col()
const
377 inline uint8_t
row()
const
396template <
class DISP >
400 ProgressBar(
byte _len,
byte _col,
byte _row,
byte _id = 0)
401 :
BarPos(_len, _col, _row, _id) { }
412 ProgressBar(DISP& disp,
byte _width,
byte _col,
byte _row,
byte _pbn = 0)
413 :
BarPos(_width, _col, _row, _pbn), barDisp(disp) { }
422 return par.len * (barStylePar.dir ? barstyle::CharPatRows : barstyle::CharPatCols) - barStylePar.startOffset - barStylePar.endOffset;
434 showProg(val + barDisp.styleStartOffset(), par.id);
453 const byte cellDim = barStylePar.dir ? barstyle::CharPatRows : barstyle::CharPatCols;
454 const byte rem = (cellDim - (val % cellDim));
455 uint8_t mask = barStylePar.dir ?
456 (barstyle::AllRows << rem) :
457 ((barstyle::AllCols << rem));
458 byte full = min(max(0, val / cellDim - 1), par.len - 2);
459 const byte partial = (val > cellDim && val < (par.len - 1) * cellDim);
460 byte blank = max(0, par.len - full - 2 - partial);
465 barDisp.makeChar(DISP::ProgBarCharPartial + n, barDisp.getStyle().startMask, mask);
469 barDisp.makeChar(DISP::ProgBarCharPartial + n, barDisp.getStyle().middleMask, mask);
471 if (val > (par.len - 1) * cellDim)
473 if (val >= par.len * cellDim)
475 mask = (barStylePar.dir ? barstyle::AllRows : barstyle::AllCols);
477 barDisp.makeChar(DISP::ProgBarCharPartial + n, barDisp.getStyle().endMask, mask);
480 barDisp.dsplay().setCursor(par.col, par.row);
481 barDisp.dsplay().write((val < cellDim) ? (DISP::ProgBarCharPartial + n) : DISP::ProgBarCharBegin);
489 barDisp.dsplay().setCursor(par.col, --crow);
491 barDisp.dsplay().write(DISP::ProgBarCharFull);
497 barDisp.dsplay().setCursor(par.col, --crow);
499 barDisp.dsplay().write(DISP::ProgBarCharPartial + n);
505 barDisp.dsplay().setCursor(par.col, --crow);
507 barDisp.dsplay().write(DISP::ProgBarCharBlank);
511 barDisp.dsplay().setCursor(par.col, --crow);
513 barDisp.dsplay().write((val > (par.len - 1) * cellDim) ? (DISP::ProgBarCharPartial + n) : DISP::ProgBarCharEnd);
Definition: SmoothProgress.h:88
void makeChar(byte udChr, const uint8_t xMask[2][barstyle::CharPatRows], uint8_t mask) const
Creates a user defined character in the CGRAM of the LCD display
Definition: SmoothProgress.h:222
barstyle::bspar stylePar() const
Access to the parameters of the style
Definition: SmoothProgress.h:161
int styleStartOffset() const
Returns the start offset (in pixels) of the progress bars
Definition: SmoothProgress.h:178
DISP & dsplay() const
Access to the display object for low level functions of the LCD
Definition: SmoothProgress.h:121
void setStyle(const barstyle &bs)
Sets the style of the progress bars on the display
Definition: SmoothProgress.h:139
void makeCharMask(uint8_t out[barstyle::CharPatRows], const uint8_t xMask[2][barstyle::CharPatRows], uint8_t mask) const
Prepares the bitmap for making the user defined character
Definition: SmoothProgress.h:245
void begin() const
Initializes the BarDisplay object with the progress bar style
Definition: SmoothProgress.h:204
BarDisplay(DISP &displ, const inPROGMEM &wraped)
BarDisplay constructor creates the object that bounds the LCD display to the bar style defined in the...
Definition: SmoothProgress.h:109
void createChar(byte udChr, const uint8_t bitMask[barstyle::CharPatRows]) const
Creates a user defined character in the CGRAM of the LCD display using the bitmap stored in bitMask a...
Definition: SmoothProgress.h:269
const barstyle & getStyle() const
Access to the bar style structure
Definition: SmoothProgress.h:130
void createChar(byte udChr, const uint8_t xMask[2][barstyle::CharPatRows]) const
Creates a user defined character in the CGRAM of the LCD display using the bitmaps stored in xMask ar...
Definition: SmoothProgress.h:289
uint8_t styleOrientation() const
Returns the orientation of the progress bar
Definition: SmoothProgress.h:196
void setStyle(const inPROGMEM &wraped)
Sets the style of the progress bars on the display
Definition: SmoothProgress.h:150
BarDisplay(DISP &displ, const barstyle &bs)
BarDisplay constructor creates the object that bounds the LCD display to the bar style defined in the...
Definition: SmoothProgress.h:100
int styleEndOffset() const
Returns the end offset (in pixels) of the progress bars
Definition: SmoothProgress.h:187
Class defining the position and the size of the progress bar on the display
Definition: SmoothProgress.h:321
uint8_t row() const
Returns the position of the progress bar on the display
Definition: SmoothProgress.h:377
BarPos(byte _len, byte _col, byte _row, byte _id=0)
Constructs the BarPos object representing the position and the size of the progress bar on the displa...
Definition: SmoothProgress.h:330
void setLength(int _len)
Sets the length of the progress bar
Definition: SmoothProgress.h:337
int getLength() const
Gets the length of the progress bar (in characters)
Definition: SmoothProgress.h:346
void setPosition(byte _col, byte _row)
Sets the position of the progress bar on the display the row and the column represents the position o...
Definition: SmoothProgress.h:358
uint8_t col() const
Returns the position of the progress bar on the display
Definition: SmoothProgress.h:368
Class representing a smooth progress bar
Definition: SmoothProgress.h:398
void showProg(int val, byte n)
Draws the horizontal progress bar on the LCD display
Definition: SmoothProgress.h:450
void showProgressPct(int val)
Draws the progress bar on the LCD display
Definition: SmoothProgress.h:442
ProgressBar(DISP &disp, byte _width, byte _col, byte _row, byte _pbn=0)
Creates horizontal ProgressBar object
Definition: SmoothProgress.h:412
unsigned int size() const
Returns the size of the progress bar in pixels (height for vertical, width for horizontal)
Definition: SmoothProgress.h:419
void showProgress(int val)
Draws the progress bar on the LCD display
Definition: SmoothProgress.h:430
Helper class to wrap the barstyle structure when passing the structure "object" to a function so that...
Definition: SmoothProgress.h:73
inPROGMEM(const barstyle &bs)
Wrapper to be used when passing the barstyle structure (as const reference) to the functions / constr...
Definition: SmoothProgress.h:80
Definition: SmoothProgress.h:384
Definition: barstyle.h:49
Structure holding the bit-masks and other data used for drawing the edges of the progress bar that de...
Definition: barstyle.h:40