blink1-lib  1.0.0
Blink1Device.hpp
Go to the documentation of this file.
1 
6 #pragma once
7 
8 #include <blink1-lib.h>
9 #include <functional>
10 #include <memory>
11 #include <optional>
12 
13 #include "PatternLine.hpp"
14 #include "PatternLineN.hpp"
15 #include "PlayState.hpp"
16 #include "RGB.hpp"
17 #include "RGBN.hpp"
18 
19 namespace blink1_lib {
20 
24  class Blink1Device {
25  std::unique_ptr<blink1_device, std::function<void(blink1_device*)>> device;
26  bool blocking{false};
27 
28  static void destroyBlinkDevice(blink1_device* device) noexcept;
29 
30  public:
35  enum class STRING_INIT_TYPE {
37  PATH,
39  SERIAL
40  };
41 
45  RGB clearColor{0, 0, 0};
46 
51  bool clearOnExit{false};
52 
56  Blink1Device() noexcept;
57 
61  explicit Blink1Device(const std::uint32_t id) noexcept;
62 
67  Blink1Device(const std::string& stringInitializer, const STRING_INIT_TYPE initType) noexcept;
68 
73  Blink1Device(const char* stringInitializer, const STRING_INIT_TYPE initType) noexcept;
74 
75  Blink1Device(const Blink1Device& other) = delete;
76  Blink1Device& operator=(const Blink1Device& other) = delete;
77 
81  ~Blink1Device();
82 
88  [[nodiscard]] bool good() const noexcept;
89 
96  [[nodiscard]] explicit operator bool() const noexcept;
97 
103  [[nodiscard]] std::optional<int> getVersion() const noexcept;
104 
121  bool fadeToRGB(const std::uint16_t fadeMillis, const RGB& rgb) noexcept;
122 
139  bool fadeToRGBN(const std::uint16_t fadeMillis, const RGBN& rgbn) noexcept;
140 
149  bool setRGB(const RGB& rgb) noexcept;
150 
159  bool setRGBN(const RGBN& rgbn) noexcept;
160 
173  [[nodiscard]] std::optional<PatternLine> readRGBWithFade(const std::uint8_t ledn) const noexcept;
174 
187  [[nodiscard]] std::optional<RGB> readRGB(const std::uint8_t ledn) const noexcept;
188 
198  bool play(const std::uint8_t pos) noexcept;
199 
209  bool playLoop(const std::uint8_t startpos, const std::uint8_t endpos, const std::uint8_t count) noexcept;
210 
216  bool stop() noexcept;
217 
223  [[nodiscard]] std::optional<PlayState> readPlayState() const noexcept;
224 
237  bool writePatternLine(const PatternLine& line, const std::uint8_t pos) noexcept;
238 
251  bool writePatternLineN(const PatternLineN& line, const std::uint8_t pos) noexcept;
252 
263  [[nodiscard]] std::optional<PatternLine> readPatternLine(const std::uint8_t pos) const noexcept;
264 
275  [[nodiscard]] std::optional<PatternLineN> readPatternLineN(const std::uint8_t pos) const noexcept;
276 
285  bool savePattern() noexcept;
286 
292  static void enableDegamma() noexcept;
293 
299  static void disableDegamma() noexcept;
300 
304  [[nodiscard]] static int vid() noexcept;
305 
309  [[nodiscard]] static int pid() noexcept;
310 
316  [[nodiscard]] std::optional<int> getCacheIndex() const noexcept;
317 
323  std::optional<int> clearCache() noexcept;
324 
330  [[nodiscard]] std::optional<std::string_view> getSerial() const noexcept;
331 
337  [[nodiscard]] std::optional<bool> isMk2() const noexcept;
338 
352  void setBlocking(bool blocking) noexcept;
353 
359  void setBlocking() noexcept;
360 
366  void setNonBlocking() noexcept;
367 
375  [[nodiscard]] bool isBlocking() const noexcept;
376  };
377 }
blink1_lib::Blink1Device::STRING_INIT_TYPE
STRING_INIT_TYPE
Definition: Blink1Device.hpp:35
blink1_lib::Blink1Device::play
bool play(const std::uint8_t pos) noexcept
blink1_lib::RGBN
Definition: RGBN.hpp:16
blink1_lib::Blink1Device::Blink1Device
Blink1Device() noexcept
RGBN.hpp
Header file for blink1_lib::RGBN.
blink1_lib::Blink1Device::pid
static int pid() noexcept
blink1_lib::Blink1Device::setBlocking
void setBlocking() noexcept
blink1_lib::Blink1Device::getVersion
std::optional< int > getVersion() const noexcept
PlayState.hpp
Header for blink1_lib::PlayState.
blink1_lib::Blink1Device::stop
bool stop() noexcept
blink1_lib::PatternLineN
Definition: PatternLineN.hpp:17
blink1_lib::Blink1Device::clearColor
RGB clearColor
Definition: Blink1Device.hpp:45
blink1_lib::Blink1Device::setNonBlocking
void setNonBlocking() noexcept
blink1_lib::Blink1Device::readRGB
std::optional< RGB > readRGB(const std::uint8_t ledn) const noexcept
blink1_lib::Blink1Device::clearCache
std::optional< int > clearCache() noexcept
blink1_lib::Blink1Device::STRING_INIT_TYPE::PATH
@ PATH
blink1_lib::Blink1Device::isBlocking
bool isBlocking() const noexcept
blink1_lib::Blink1Device::fadeToRGBN
bool fadeToRGBN(const std::uint16_t fadeMillis, const RGBN &rgbn) noexcept
blink1_lib::Blink1Device::getCacheIndex
std::optional< int > getCacheIndex() const noexcept
blink1_lib::Blink1Device::vid
static int vid() noexcept
blink1_lib::Blink1Device::savePattern
bool savePattern() noexcept
blink1_lib::Blink1Device
Definition: Blink1Device.hpp:24
blink1_lib::Blink1Device::isMk2
std::optional< bool > isMk2() const noexcept
blink1_lib::Blink1Device::readPlayState
std::optional< PlayState > readPlayState() const noexcept
blink1_lib
Definition: Blink1Device.hpp:19
blink1_lib::Blink1Device::setRGBN
bool setRGBN(const RGBN &rgbn) noexcept
blink1_lib::Blink1Device::readPatternLineN
std::optional< PatternLineN > readPatternLineN(const std::uint8_t pos) const noexcept
blink1_lib::Blink1Device::enableDegamma
static void enableDegamma() noexcept
PatternLineN.hpp
Header file for blink1_lib::PatternLineN.
PatternLine.hpp
Header file for blink1_lib::PatternLine.
blink1_lib::Blink1Device::writePatternLineN
bool writePatternLineN(const PatternLineN &line, const std::uint8_t pos) noexcept
blink1_lib::Blink1Device::playLoop
bool playLoop(const std::uint8_t startpos, const std::uint8_t endpos, const std::uint8_t count) noexcept
blink1_lib::PatternLine
Definition: PatternLine.hpp:18
blink1_lib::RGB
Definition: RGB.hpp:16
blink1_lib::Blink1Device::good
bool good() const noexcept
blink1_lib::Blink1Device::clearOnExit
bool clearOnExit
Definition: Blink1Device.hpp:51
blink1_lib::Blink1Device::writePatternLine
bool writePatternLine(const PatternLine &line, const std::uint8_t pos) noexcept
blink1_lib::Blink1Device::fadeToRGB
bool fadeToRGB(const std::uint16_t fadeMillis, const RGB &rgb) noexcept
blink1_lib::PlayState
Definition: PlayState.hpp:16
RGB.hpp
Header file for blink1_lib::RGB.
blink1_lib::Blink1Device::setRGB
bool setRGB(const RGB &rgb) noexcept
blink1_lib::Blink1Device::readRGBWithFade
std::optional< PatternLine > readRGBWithFade(const std::uint8_t ledn) const noexcept
blink1_lib::Blink1Device::readPatternLine
std::optional< PatternLine > readPatternLine(const std::uint8_t pos) const noexcept
blink1_lib::Blink1Device::STRING_INIT_TYPE::SERIAL
@ SERIAL
blink1_lib::Blink1Device::getSerial
std::optional< std::string_view > getSerial() const noexcept
blink1_lib::Blink1Device::disableDegamma
static void disableDegamma() noexcept