ESPixelStick Firmware
Firmware for the ESPixelStick
Loading...
Searching...
No Matches
OutputServoPCA9685.hpp
Go to the documentation of this file.
1#pragma once
2/******************************************************************
3*
4* Project: ESPixelStick - An ESP8266 / ESP32 and E1.31 based pixel (And Serial!) driver
5* Orginal ESPixelStickproject by 2015 Shelby Merrick
6*
7*This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or(at your option) any later version.
8This program is distributed in the hope that it will be useful,
9but WITHOUT ANY WARRANTY; without even the implied warranty of
10MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11GNU General Public License for more details.
12<http://www.gnu.org/licenses/>
13*
14******************************************************************
15*
16* This is a derived class that converts data in the output buffer into
17* Servo States and then outputs on I2C
18*
19*/
20#include "ESPixelStick.h"
21#ifdef SUPPORT_OutputType_Servo_PCA9685
22
23#include "OutputCommon.hpp"
24#include <Adafruit_PWMServoDriver.h>
25
26class c_OutputServoPCA9685 : public c_OutputCommon
27{
28private:
29#define SERVO_PCA9685_OUTPUT_MIN_PULSE_WIDTH 650
30#define SERVO_PCA9685_OUTPUT_MAX_PULSE_WIDTH 2350
31
32 struct ServoPCA9685Channel_t
33 {
34 uint8_t Id = -1;
35 bool Enabled = false;
36 uint16_t MinLevel = SERVO_PCA9685_OUTPUT_MIN_PULSE_WIDTH;
37 uint16_t MaxLevel = SERVO_PCA9685_OUTPUT_MAX_PULSE_WIDTH;
38 uint16_t PreviousValue = 0;
39 bool IsReversed = false;
40 bool Is16Bit = false;
41 bool IsScaled = true;
42 uint8_t HomeValue = 0;
43
44 };
45
46public:
47
48 // These functions are inherited from c_OutputCommon
49 c_OutputServoPCA9685 (c_OutputMgr::e_OutputChannelIds OutputChannelId,
50 gpio_num_t outputGpio,
51 uart_port_t uart,
52 c_OutputMgr::e_OutputType outputType);
53 virtual ~c_OutputServoPCA9685 ();
54
55 // functions to be provided by the derived class
56 void Begin ();
57 bool SetConfig (ArduinoJson::JsonObject & jsonConfig);
58 void GetConfig (ArduinoJson::JsonObject & jsonConfig);
59 uint32_t Poll ();
60#if defined(ARDUINO_ARCH_ESP32)
61 bool RmtPoll () {return false;}
62#endif // defined(ARDUINO_ARCH_ESP32)
63 void GetDriverName (String& sDriverName);
64 void GetStatus (ArduinoJson::JsonObject & jsonStatus) { c_OutputCommon::BaseGetStatus (jsonStatus); }
65 uint32_t GetNumOutputBufferBytesNeeded () { return OutputBufferSize; };
67
68private:
69# define OM_SERVO_PCA9685_CHANNEL_LIMIT 16
70# define OM_SERVO_PCA9685_UPDATE_INTERVAL_NAME CN_updateinterval
71# define OM_SERVO_PCA9685_CHANNELS_NAME CN_channels
72# define OM_SERVO_PCA9685_CHANNEL_ENABLED_NAME CN_en
73# define OM_SERVO_PCA9685_CHANNEL_MINLEVEL_NAME CN_Min
74# define OM_SERVO_PCA9685_CHANNEL_MAXLEVEL_NAME CN_Max
75# define OM_SERVO_PCA9685_CHANNEL_GPIO_NAME CN_gid
76# define OM_SERVO_PCA9685_CHANNEL_ID_NAME CN_id
77# define OM_SERVO_PCA9685_CHANNEL_REVERSED CN_rev
78# define OM_SERVO_PCA9685_CHANNEL_16BITS CN_b16
79# define OM_SERVO_PCA9685_CHANNEL_SCALED CN_sca
80# define OM_SERVO_PCA9685_CHANNEL_HOME CN_hv
81# define SERVO_PCA9685_UPDATE_FREQUENCY 50
82
83 bool validate ();
84
85 // config data
86 ServoPCA9685Channel_t OutputList[OM_SERVO_PCA9685_CHANNEL_LIMIT];
87 Adafruit_PWMServoDriver * pwm = nullptr;
88 float UpdateFrequency = SERVO_PCA9685_UPDATE_FREQUENCY;
89
90 // non config data
91 String OutputName;
92 uint16_t Num_Channels = OM_SERVO_PCA9685_CHANNEL_LIMIT;
93
94}; // c_OutputServoPCA9685
95
96#endif // def SUPPORT_OutputType_Servo_PCA9685
Definition OutputCommon.hpp:31
virtual void GetDriverName(String &sDriverName)=0
get the name for the instantiated driver
virtual void Begin()
set up the operating environment based on the current config (or defaults)
Definition OutputCommon.hpp:43
virtual uint32_t GetNumOutputBufferChannelsServiced()=0
uint32_t OutputBufferSize
Definition OutputCommon.hpp:81
virtual void BaseGetStatus(ArduinoJson::JsonObject &jsonStatus)
Definition OutputCommon.cpp:68
virtual void GetStatus(ArduinoJson::JsonObject &jsonStatus)=0
virtual uint32_t Poll()=0
Call from loop(), renders output data.
virtual uint32_t GetNumOutputBufferBytesNeeded()=0
virtual bool SetConfig(ArduinoJson::JsonObject &jsonConfig)
Set a new config in the driver.
Definition OutputCommon.cpp:94
virtual void GetConfig(ArduinoJson::JsonObject &jsonConfig)
Get the current config used by the driver.
Definition OutputCommon.cpp:111
e_OutputChannelIds
Definition OutputMgr.hpp:67
e_OutputType
Definition OutputMgr.hpp:126