2021-03-29 08:10:55 +00:00
|
|
|
#include <Arduino.h>
|
2019-05-10 05:17:29 +00:00
|
|
|
#include "./Input.h"
|
|
|
|
#include "./MainLoop.h"
|
|
|
|
|
2021-03-29 08:10:55 +00:00
|
|
|
CRGB
|
2019-05-10 05:17:29 +00:00
|
|
|
Variant::asRGB() const
|
|
|
|
{
|
2021-03-29 08:10:55 +00:00
|
|
|
return CRGB(m_value.asRGB[0], m_value.asRGB[1], m_value.asRGB[2]);
|
2019-05-10 05:17:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const char*
|
|
|
|
Variant::asString() const
|
|
|
|
{
|
|
|
|
return m_value.asString;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
Variant::asInt() const
|
|
|
|
{
|
|
|
|
return m_value.asInt;
|
|
|
|
}
|
|
|
|
|
2022-06-11 09:02:27 +00:00
|
|
|
bool
|
|
|
|
Variant::asBool() const
|
|
|
|
{
|
|
|
|
return (bool)m_value.asInt;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
InputSource::init()
|
|
|
|
{
|
|
|
|
#ifdef CONFIG_THREADED_INPUTS
|
|
|
|
m_queue = xQueueCreate(32, sizeof(InputEvent));
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef CONFIG_THREADED_INPUTS
|
|
|
|
void
|
|
|
|
InputSource::readThread(void* data)
|
|
|
|
{
|
|
|
|
InputSource* self = static_cast<InputSource*>(data);
|
|
|
|
while(true) {
|
|
|
|
InputEvent evt = self->read();
|
|
|
|
if (evt.intent != InputEvent::None) {
|
|
|
|
xQueueSend(m_queue, &evt, 0)
|
|
|
|
}
|
|
|
|
taskYIELD();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
void
|
|
|
|
InputSource::onStart()
|
|
|
|
{
|
|
|
|
#ifdef CONFIG_THREADED_INPUTS
|
|
|
|
m_threadLoop = MainLoop::instance();
|
|
|
|
xTaskCreate(
|
|
|
|
&InputSource::readThread,
|
|
|
|
name,
|
|
|
|
1000,
|
|
|
|
this,
|
|
|
|
1,
|
|
|
|
NULL
|
|
|
|
);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2019-05-10 05:17:29 +00:00
|
|
|
void
|
|
|
|
InputSource::loop()
|
|
|
|
{
|
2022-06-11 09:02:27 +00:00
|
|
|
#ifndef CONFIG_THREADED_INPUTS
|
2019-05-10 05:17:29 +00:00
|
|
|
MainLoop::instance()->dispatch(read());
|
2022-06-11 09:02:27 +00:00
|
|
|
#else
|
|
|
|
InputEvent evt;
|
|
|
|
xQueueReceive(m_queue, &evt, 0);
|
|
|
|
if (evt.intent != InputEvent::None) {
|
|
|
|
MainLoop::instance()->dispatch(evt);
|
|
|
|
}
|
|
|
|
#endif
|
2019-05-10 05:17:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
InputEvent
|
|
|
|
BufferedInputSource::read()
|
|
|
|
{
|
2021-03-28 21:50:31 +00:00
|
|
|
InputEvent ret;
|
|
|
|
m_eventQueue.take(ret);
|
2019-05-10 05:17:29 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
BufferedInputSource::setEvent(InputEvent &&evt)
|
|
|
|
{
|
2021-03-28 21:50:31 +00:00
|
|
|
m_eventQueue.insert(std::move(evt));
|
2019-05-10 05:17:29 +00:00
|
|
|
}
|
2021-03-28 01:19:55 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
BufferedInputSource::setEvent(InputEvent::Intent intent, Variant &&v)
|
|
|
|
{
|
2021-03-28 21:50:31 +00:00
|
|
|
m_eventQueue.insert(InputEvent{intent, std::move(v)});
|
2021-03-28 01:19:55 +00:00
|
|
|
}
|