Skip to content

Commit

Permalink
Merge pull request #23 from AKJ7/dev
Browse files Browse the repository at this point in the history
Const correctness update
  • Loading branch information
AKJ7 committed Dec 31, 2023
2 parents ba26851 + 801c421 commit 86ecf1f
Show file tree
Hide file tree
Showing 11 changed files with 54 additions and 51 deletions.
54 changes: 28 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,40 +50,41 @@ void loop()
## API
```cpp
class TM1637 {
public:
static constexpr uint8_t TOTAL_DIGITS = 4;
TM1637(uint8_t clkPin, uint8_t dataPin) noexcept;
TM1637(const TM1637&) = delete;
TM1637& operator=(const TM1637&) = delete;
TM1637(uint8_t clkPin, uint8_t dataPin) noexcept: animator_(clkPin, dataPin, TOTAL_DIGITS) {};
TM1637(const TM1637 &) = delete;
TM1637 &operator=(const TM1637 &) = delete;
~TM1637() = default;
void begin();
inline void init();
inline Animator* refresh();
template <typename T>
inline void init();
inline Animator *refresh();
template<typename T>
typename type_traits::enable_if<
type_traits::is_string<T>::value ||
type_traits::is_floating_point<T>::value ||
type_traits::is_integral<T>::value,
Animator*>::type
type_traits::is_string<T>::value ||
type_traits::is_floating_point<T>::value ||
type_traits::is_integral<T>::value,
Animator *>::type
display(const T value, bool overflow = true, bool pad = false, uint8_t offset = 0);
Animator* displayRawBytes(const uint8_t* buffer, size_t size);
void offMode() const noexcept;
void onMode() const noexcept;
inline void colonOff() noexcept;
inline void colonOn() noexcept;
inline Animator* switchColon() noexcept;
void clearScreen() noexcept;
inline void setDp(uint8_t value) noexcept;
inline uint8_t getBrightness() const noexcept;
Animator *displayRawBytes(const uint8_t *buffer, size_t size);
inline Animator *offMode() noexcept;
inline Animator *onMode() noexcept;
inline Animator *colonOff() noexcept;
inline Animator *colonOn() noexcept;
inline Animator *switchColon() noexcept;
inline Animator *clearScreen() noexcept;
inline Animator *setDp(uint8_t value) noexcept;
inline uint8_t getBrightness() noexcept;
inline float getBrightnessPercent() const noexcept;
void changeBrightness(uint8_t value) noexcept;
void setBrightness(uint8_t value) noexcept;
inline Animator *setBrightnessPercent(float percent) noexcept;
inline Animator *changeBrightnessPercent(float percent) noexcept;
inline void setFloatDigitCount(unsigned count);
};
class Animator
{
public:
Animator(uint8_t clkPin, uint8_t dataPin, uint8_t totalDigits);
void blink(Tasker::duration_type delay);
void fadeOut(Tasker::duration_type delay);
Expand All @@ -92,6 +93,7 @@ public:
void off() const;
void on(DisplayControl_e brightness) const;
void reset(const String& value);
inline void resetAnimation() noexcept;
void clear();
void refresh();
}
Expand All @@ -106,18 +108,17 @@ struct DisplayDigit
DisplayDigit& setF();
DisplayDigit& setG();
DisplayDigit& setDot();
operator uint8_t();
void operator=(uint8_t rhs);
DisplayDigit& operator=(uint8_t rhs);
operator uint8_t() const;
}
```

## Test

Tested on my Arduino Uno. Should work on every controller board that supports the Arduino platform.


## Contribution
## Contributions

Since i am very lazy, feel free to contribute. Pull Requests get added faster ;-)

Expand All @@ -129,3 +130,4 @@ Many thanks to these contributors:
- [andrewerrington](https://github.com/andrewerrington)
- [jcmadrioso](https://github.com/jcmadrioso)
- [Kostyantyn Matviyevskyy](https://github.com/kostyamat)
- [vortigont](https://github.com/vortigont)
6 changes: 3 additions & 3 deletions examples/animation/animation.ino
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
Animator *>::type
display(const T value, bool overflow = true, bool pad = false, uint8_t offset = 0);
Animator *displayRawBytes(const uint8_t *buffer, size_t size);
inline Animator *offMode() const noexcept;
inline Animator *onMode() const noexcept;
inline Animator *offMode() noexcept;
inline Animator *onMode() noexcept;
inline Animator *colonOff() noexcept;
inline Animator *colonOn() noexcept;
inline Animator *switchColon() noexcept;
Expand Down Expand Up @@ -69,7 +69,7 @@
DisplayDigit& setG();
DisplayDigit& setDot();
DisplayDigit& operator=(uint8_t rhs);
operator uint8_t();
operator uint8_t() const;
}
*/

Expand Down
6 changes: 3 additions & 3 deletions examples/basic/basic.ino
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
Animator *>::type
display(const T value, bool overflow = true, bool pad = false, uint8_t offset = 0);
Animator *displayRawBytes(const uint8_t *buffer, size_t size);
inline Animator *offMode() const noexcept;
inline Animator *onMode() const noexcept;
inline Animator *offMode() noexcept;
inline Animator *onMode() noexcept;
inline Animator *colonOff() noexcept;
inline Animator *colonOn() noexcept;
inline Animator *switchColon() noexcept;
Expand Down Expand Up @@ -70,7 +70,7 @@
DisplayDigit& setG();
DisplayDigit& setDot();
DisplayDigit& operator=(uint8_t rhs);
operator uint8_t();
operator uint8_t() const;
}
*/

Expand Down
6 changes: 3 additions & 3 deletions examples/clock/clock.ino
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@
Animator *>::type
display(const T value, bool overflow = true, bool pad = false, uint8_t offset = 0);
Animator *displayRawBytes(const uint8_t *buffer, size_t size);
inline Animator *offMode() const noexcept;
inline Animator *onMode() const noexcept;
inline Animator *offMode() noexcept;
inline Animator *onMode() noexcept;
inline Animator *colonOff() noexcept;
inline Animator *colonOn() noexcept;
inline Animator *switchColon() noexcept;
Expand Down Expand Up @@ -87,7 +87,7 @@
DisplayDigit& setG();
DisplayDigit& setDot();
DisplayDigit& operator=(uint8_t rhs);
operator uint8_t();
operator uint8_t() const;
}
*/

Expand Down
6 changes: 3 additions & 3 deletions examples/counter/counter.ino
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
Animator *>::type
display(const T value, bool overflow = true, bool pad = false, uint8_t offset = 0);
Animator *displayRawBytes(const uint8_t *buffer, size_t size);
inline Animator *offMode() const noexcept;
inline Animator *onMode() const noexcept;
inline Animator *offMode() noexcept;
inline Animator *onMode() noexcept;
inline Animator *colonOff() noexcept;
inline Animator *colonOn() noexcept;
inline Animator *switchColon() noexcept;
Expand Down Expand Up @@ -71,7 +71,7 @@
DisplayDigit& setG();
DisplayDigit& setDot();
DisplayDigit& operator=(uint8_t rhs);
operator uint8_t();
operator uint8_t() const;
}
*/

Expand Down
6 changes: 3 additions & 3 deletions examples/custom_digits/custom_digits.ino
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
Animator *>::type
display(const T value, bool overflow = true, bool pad = false, uint8_t offset = 0);
Animator *displayRawBytes(const uint8_t *buffer, size_t size);
inline Animator *offMode() const noexcept;
inline Animator *onMode() const noexcept;
inline Animator *offMode() noexcept;
inline Animator *onMode() noexcept;
inline Animator *colonOff() noexcept;
inline Animator *colonOn() noexcept;
inline Animator *switchColon() noexcept;
Expand Down Expand Up @@ -63,7 +63,7 @@
DisplayDigit& setG();
DisplayDigit& setDot();
DisplayDigit& operator=(uint8_t rhs);
operator uint8_t();
operator uint8_t() const;
}
*/

Expand Down
7 changes: 3 additions & 4 deletions examples/split_screen/split_screen.ino
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
Animator *>::type
display(const T value, bool overflow = true, bool pad = false, uint8_t offset = 0);
Animator *displayRawBytes(const uint8_t *buffer, size_t size);
inline Animator *offMode() const noexcept;
inline Animator *onMode() const noexcept;
inline Animator *offMode() noexcept;
inline Animator *onMode() noexcept;
inline Animator *colonOff() noexcept;
inline Animator *colonOn() noexcept;
inline Animator *switchColon() noexcept;
Expand Down Expand Up @@ -77,7 +77,7 @@
DisplayDigit& setG();
DisplayDigit& setDot();
DisplayDigit& operator=(uint8_t rhs);
operator uint8_t();
operator uint8_t() const;
}
*/

Expand Down Expand Up @@ -105,7 +105,6 @@ void setup()

void loop()
{

tm.displayRawBytes(degree, sizeof(degree));
tm.display(getTemperature(), false, false); // Display the random temperature starting at position 1 and fill the
// spots on the right with zeros
Expand Down
2 changes: 2 additions & 0 deletions keywords.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ setDp KEYWORD2
getBrightness KEYWORD2
changeBrightness KEYWORD2
setBrightness KEYWORD2
changeBrightnessPercent KEYWORD2
setFloatDigitCount KEYWORD2
blink KEYWORD2
fadeIn KEYWORD2
fadeOut KEYWORD2
Expand Down
4 changes: 2 additions & 2 deletions library.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
"name": "TM1637 Driver",
"frameworks": "arduino",
"platforms": ["avr", "espressif8266", "espressif32"],
"version": "2.2.0",
"version": "2.2.1",
"keywords": "tm1637, TM1637, Display, Animation",
"description": "Features: -Display integers, float, string with only one function. -Nonblocking animation: Blink, scrollLeft, fadeIn, fadeOut -Customizable offset, pad, overflow. -Custom raw value display. -Tunable brightness. -Screen clearing and splitting. Visit https://github.com/AKJ7/TM1637 for more information.",
"url": "https://github.com/AKJ7/TM1637",
"authors": [
{
"name": "AKJ",
"url": "https://github.com/AKJ7",
"email": " <akj123429@gmail.com>",
"email": "akj123429@gmail.com",
"maintainer": true
}
],
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=TM1637 Driver
version=2.2.0
version=2.2.1
author=AKJ <akj123429@gmail.com>
maintainer=AKJ <akj123429@gmail.com>
sentence=Feature-full and simple TM1637 library with nonblocking animation support
Expand Down
6 changes: 3 additions & 3 deletions src/TM1637.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ struct DisplayDigit {
* Allow implicit static casting to uint8_t
* @return Encoded digit in byte
*/
operator uint8_t() { return value; }
operator uint8_t() const { return value; }

/**
* Allow implicit conversion from uint8_t
Expand Down Expand Up @@ -234,7 +234,7 @@ class TM1637 {
* @brief Turn display off
* @return Instance of the current animator
*/
inline Animator *offMode() const noexcept {
inline Animator *offMode() noexcept {
animator_.off();
return &animator_;
};
Expand All @@ -243,7 +243,7 @@ class TM1637 {
* @brief Turn display on
* @return Instance of the current animator
*/
inline Animator *onMode() const noexcept {
inline Animator *onMode() noexcept {
animator_.on(animator_.brightness_);
return &animator_;
};
Expand Down

0 comments on commit 86ecf1f

Please sign in to comment.