forked from jandelgado/jled
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* new custom hal example * prepare release * fix goveralls invocation
- Loading branch information
1 parent
75c093c
commit 7219c3a
Showing
8 changed files
with
75 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// JLed custom HAL example. | ||
// Copyright 2019 by Jan Delgado. All rights reserved. | ||
// https://github.com/jandelgado/jled | ||
|
||
// we include jled_base.h instead of "jled.h" since we define our own JLed | ||
// class using our custom HAL. | ||
#include <jled_base.h> | ||
|
||
// a custom HAL for the Arduino, inverting output and ticking with half | ||
// the speed. | ||
class CustomHal : jled::JLedHal { | ||
private: | ||
template <typename T, typename B> | ||
friend class jled::TJLed; | ||
CustomHal() {} | ||
|
||
public: | ||
explicit CustomHal(uint8_t pin) noexcept : pin_(pin) {} | ||
|
||
void analogWrite(uint8_t val) const { | ||
// some platforms, e.g. STM need lazy initialization | ||
if (!setup_) { | ||
::pinMode(pin_, OUTPUT); | ||
setup_ = true; | ||
} | ||
::analogWrite(pin_, 255 - val); | ||
} | ||
|
||
uint32_t millis() const { return ::millis() >> 1; } | ||
|
||
private: | ||
mutable bool setup_ = false; | ||
uint8_t pin_; | ||
}; | ||
|
||
class JLed : public jled::TJLed<CustomHal, JLed> { | ||
using jled::TJLed<CustomHal, JLed>::TJLed; | ||
}; | ||
|
||
// uses above defined CustomHal | ||
auto led = JLed(LED_BUILTIN).Blink(1000, 1000).Repeat(5); | ||
|
||
void setup() {} | ||
|
||
void loop() { led.Update(); } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters