jandelgado / jled

Non-blocking LED controlling library for Arduino and friends.
MIT License
324 stars 51 forks source link

Multiple HALs #95

Closed troky closed 1 year ago

troky commented 2 years ago

Is it possible to implement multiple HALs ont he same board/project? For example, I have ESP32 board with PCA9635 I2C driver and I want to use them both using JLed library at the same time, e.g. some LEDs are connected to ESP32 pins, and some are connected to PCA9635.

I have created custom HAL class but I dont know how to instantiate both HALs at the same time.

jandelgado commented 2 years ago

I'll provide an example showing how to drive built-in ESP32 PWM's and an PCA9685 driver in the next days.

troky commented 2 years ago

Driving PCA9685 (creating new HAL) is not a problem. I want to have std::list of different HAL types.

jandelgado commented 2 years ago

Could you please provide an example what the exact problem is (code)?

troky commented 2 years ago

There is no (abstract) base class/interface that coul be used. For example: I need std:: list<JLedBase*>() where list elemnts can be JLed, JLed, etc... so I can cast JLed to JLedBase and call JLedBase->On() function etc...

jandelgado commented 2 years ago

There is intentionally no base class to keep the memory footprint low. But coincidentially I am working on a feature allowing to stuff different objects like JLed objects or JLedSequence objects recursively into a JLedSequence. I'll try to provide a branch that you can test in the next days.

troky commented 2 years ago

Well, for test, I de-templated your TLed class and made it abstract adding two virtual functions: analogWrite() and millis() and now I can create derived class from public TLed and implement those two funcions just like you do it in separate hal class. Problem solved... now I can have std::list<TLed *>()

github-actions[bot] commented 1 year ago

This issue is stale because it has been open 90 days with no activity. Remove stale label or comment or this will be closed in 5 days