Uniot Core
0.8.1
Loading...
Searching...
No Matches
GpioRegister.h
Go to the documentation of this file.
1/*
2 * This is a part of the Uniot project.
3 * Copyright (C) 2016-2024 Uniot <contact@uniot.io>
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19#pragma once
20
21#include <Arduino.h>
22#include <DefaultPrimitives.h>
23
24#include "Register.h"
25
26namespace uniot {
27
38class GpioRegister : public Register<uint8_t> {
39 public:
45 GpioRegister() : Register<uint8_t>() {}
46
51
55 GpioRegister(GpioRegister const&) = delete;
56
60 void operator=(GpioRegister const&) = delete;
61
71 template <typename... Args>
72 void setDigitalInput(uint8_t first, Args... args) {
73 setRegisterVariadic(primitive::name::dread, first, args...);
74 }
75
85 template <typename... Args>
86 void setDigitalOutput(uint8_t first, Args... args) {
87 setRegisterVariadic(primitive::name::dwrite, first, args...);
88 }
89
100 template <typename... Args>
101 void setAnalogInput(uint8_t first, Args... args) {
102 setRegisterVariadic(primitive::name::aread, first, args...);
103 }
104
115 template <typename... Args>
116 void setAnalogOutput(uint8_t first, Args... args) {
117 setRegisterVariadic(primitive::name::awrite, first, args...);
118 }
119
120 protected:
133 virtual void _processRegister(const String& name, const uint8_t& value) override {
134 if (name == primitive::name::dread) {
135 pinMode(value, INPUT);
136 } else if (name == primitive::name::dwrite) {
137 pinMode(value, OUTPUT);
138 } else if (name == primitive::name::aread) {
139 pinMode(value, INPUT);
140 } else if (name == primitive::name::awrite) {
141 pinMode(value, OUTPUT);
142 }
143 }
144
145 private:
157 template <typename... Args>
158 void setRegisterVariadic(const String& name, uint8_t first, Args... args) {
159 uint8_t pins[] = {first, static_cast<uint8_t>(args)...};
160 size_t count = sizeof...(args) + 1;
161 setRegister(name, pins, count);
162 }
163};
164
165} // namespace uniot
Defines string constants for Lisp primitive function names.
void operator=(GpioRegister const &)=delete
Deleted assignment operator to prevent assignment.
virtual void _processRegister(const String &name, const uint8_t &value) override
Override method to process register values.
Definition GpioRegister.h:133
void setAnalogOutput(uint8_t first, Args... args)
Configure pins as analog outputs.
Definition GpioRegister.h:116
void setAnalogInput(uint8_t first, Args... args)
Configure pins as analog inputs.
Definition GpioRegister.h:101
~GpioRegister()
Destructor.
Definition GpioRegister.h:50
GpioRegister(GpioRegister const &)=delete
Deleted copy constructor to prevent copying.
void setDigitalInput(uint8_t first, Args... args)
Configure pins as digital inputs.
Definition GpioRegister.h:72
GpioRegister()
Default constructor.
Definition GpioRegister.h:45
void setDigitalOutput(uint8_t first, Args... args)
Configure pins as digital outputs.
Definition GpioRegister.h:86
bool setRegister(const String &name, const uint8_t *values, size_t count)
Definition Register.h:96
Register(Register const &)=delete
constexpr const char * dread
Primitive for digital read operations.
Definition DefaultPrimitives.h:59
constexpr const char * aread
Primitive for analog read operations.
Definition DefaultPrimitives.h:73
constexpr const char * awrite
Primitive for analog write operations.
Definition DefaultPrimitives.h:66
constexpr const char * dwrite
Primitive for digital write operations.
Definition DefaultPrimitives.h:52
Contains all classes and functions related to the Uniot Core.