Comments (6)
Yes, you can define you own custom HAL class, which controls access to the GPIO and the timer. I have assembled an example, which will be included in the examples of JLed.
Is this what you are looking for?
// 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();
}
from jled.
Yes, I modified the arduino_hal.h to change the millis(). I was wondering if this could be part of the API where you call a method to override millis() with your own function?
from jled.
The official, non-invasive, way would be to implement a custom HAL as shown above. This way, no modification of the lib is necessary.
from jled.
Wouldn't you still need to change the reference to arduino_hal.h in the code snippet below from jled.h to the custom HAL ?
#ifdef ESP32
#include "esp32_hal.h" // NOLINT
namespace jled {using JLedHalType = Esp32Hal;}
#elif ESP8266
#include "esp8266_hal.h" // NOLINT
namespace jled {using JLedHalType = Esp8266Hal;}
#else
#include "arduino_hal.h" // NOLINT
namespace jled {using JLedHalType = ArduinoHal;}
#endif
from jled.
No, because in the custom HAL example above, I included jled_base.h
instead of jled.h
and defined my own JLed
class. This is basically what is usually done in jled.h
, for convenience reasons.
from jled.
Hi, can we close the issue? The problem can be solved as described. In the meantime, I added an Custom-HAL example to the examples section.
br
Jan
from jled.
Related Issues (20)
- Blink twice HOT 2
- Evolution for non PWM pins HOT 2
- jled to control RGB? HOT 7
- times in millis should be 32bit values HOT 3
- Make fade-resolution choosable HOT 5
- Why is 'MinBrightness' not in red font HOT 2
- CTRL_ANODE HOT 4
- JLedSequence.Stop() not working HOT 1
- Question/Feature: Get current brightness HOT 11
- How to control 15 gpio pins HOT 8
- Return pin's previous state after Blink is over HOT 2
- Repeat() and DelayAfter() on the same effect in a sequence HOT 4
- Is there a way to use a single JLED to control a bicolor led? HOT 2
- Simulate PWM for all pins to enable PWM for all pins without hardware PWM HOT 1
- Update() not returning false for On() HOT 4
- Delay only working for low values HOT 3
- Multiple HALs HOT 7
- Change PWM base frequency HOT 4
- Question: How to pass to funtion HOT 2
- Minimum brightness HOT 8
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jled.