CANTram Framework 1.0.1
Dieses Framework ermöglicht die Nutzung der CANTram Hardware, einer Mikrocontroller basierten mdoularen Steuerung.
Loading...
Searching...
No Matches
OutputDefinition.h
Go to the documentation of this file.
1#ifndef OUTPUTDEFINITION_H
2#define OUTPUTDEFINITION_H
3
4#include <Arduino.h>
5#include "Debug.h"
6
14
15class OutputProvider; // Forward declaration
16
25 public:
37 OutputDefinition(bool isShift, uint8_t pinOrBit, bool adc, bool pwm, bool inputOnly, OutputProvider* provider) :
38 isShift(isShift), pinOrBit(pinOrBit), adc(adc), pwm(pwm), inputOnly(inputOnly), provider(provider)
39 {}
40
41 enum ConfigurationMode {
42 MODE_INPUT,
43 MODE_OUTPUT,
44 MODE_PWM,
45 MODE_INPUT_PULLUP,
46 MODE_NONE
47 };
48 const String ConfigurationModeToString(ConfigurationMode mode) {
49 switch(mode) {
50 case MODE_INPUT: return "INPUT";
51 case MODE_OUTPUT: return "OUTPUT";
52 case MODE_PWM: return "PWM";
53 case MODE_INPUT_PULLUP: return "INPUT_PULLUP";
54 case MODE_NONE: return "NONE";
55 default: return "UNKNOWN";
56 }
57 }
58 const bool isShift;
59 const uint8_t pinOrBit;
60 const bool adc;
61 const bool pwm;
62 const bool inputOnly;
63 ConfigurationMode mode = MODE_NONE; //default to output mode
64
65 OutputProvider* provider;
66 bool initialValue = LOW;
67
74 String toString() {
75 return String("OutputDefinition(isShift=") + (isShift ? "true" : "false") +
76 ", pinOrBit=" + String(pinOrBit) +
77 ", adc=" + (adc ? "true" : "false") +
78 ", pwm=" + (pwm ? "true" : "false") +
79 ", inputOnly=" + (inputOnly ? "true" : "false") + ")";
80 }
81};
82
90 public:
98 virtual bool configureOutput(OutputDefinition* def, OutputDefinition::ConfigurationMode mode) = 0;
99
100
108 virtual bool setOutput(OutputDefinition* def, bool state) = 0; //Returns true if successful
109
117 virtual bool getOutput(OutputDefinition* def) = 0; //Returns current state
118
124 virtual void enableOutputs(bool state=true){ //Append this method in derived classes to actually enable the outputs
125 if(state == outputsEnabled){ //If state is already as requested, do nothing
126 return;
127 }
128 outputsEnabled = state;
129 INFO_PRINTLN("[OutputProvider] Outputs enabled set to: " + String(state));
130
131 }
132
136 virtual void disableOutputs(){
137 enableOutputs(false);
138 }
139 private:
140 bool outputsEnabled = false;
141 };
142
149 public:
158 virtual bool setPWM(OutputDefinition* def, uint16_t value) = 0; //Returns true if successful
159
166 virtual bool registerPWMChannel(OutputDefinition* def) = 0; //Returns true if successful
167};
168
169#endif
Logging and debug macro definitions for CANTramCore.
#define INFO_PRINTLN(x)
Print an info-level message with newline.
Definition Debug.h:137
Describes an available output (GPIO or shift register bit).
Definition OutputDefinition.h:24
String toString()
Create a human-readable string describing the OutputDefinition.
Definition OutputDefinition.h:74
OutputDefinition(bool isShift, uint8_t pinOrBit, bool adc, bool pwm, bool inputOnly, OutputProvider *provider)
Construct a new OutputDefinition instance.
Definition OutputDefinition.h:37
Abstract interface for providers that control outputs.
Definition OutputDefinition.h:89
virtual void enableOutputs(bool state=true)
Enable or disable all outputs managed by this provider.
Definition OutputDefinition.h:124
virtual bool setOutput(OutputDefinition *def, bool state)=0
Set the logical state of an output.
virtual bool configureOutput(OutputDefinition *def, OutputDefinition::ConfigurationMode mode)=0
Configure an output's direction/mode.
virtual void disableOutputs()
Disable all outputs managed by this provider.
Definition OutputDefinition.h:136
virtual bool getOutput(OutputDefinition *def)=0
Read the current logical state of an output.
Extended output provider interface for PWM-capable outputs.
Definition OutputDefinition.h:148
virtual bool registerPWMChannel(OutputDefinition *def)=0
Register/allocate a PWM channel for the given output.
virtual bool setPWM(OutputDefinition *def, uint16_t value)=0
Set a PWM value on the specified output.