Skip to content

Commit 3562104

Browse files
committed
Init. Servo
1 parent 3304fb4 commit 3562104

File tree

7 files changed

+416
-1
lines changed

7 files changed

+416
-1
lines changed

src/components/pwm/hardware.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ bool PWMHardware::WriteDutyCycle(uint32_t duty) {
9696
return false;
9797
}
9898
bool did_write = false;
99-
#ifdef defined(ARDUINO_ESP8266_ADAFRUIT_HUZZAH) && defined(STATUS_LED_PIN)
99+
#if defined(ARDUINO_ESP8266_ADAFRUIT_HUZZAH) && defined(STATUS_LED_PIN)
100100
// Adafruit Feather ESP8266's analogWrite() gets inverted since the builtin
101101
// LED is reverse-wired
102102
_duty_cycle = 255 - duty;
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/*!
2+
* @file src/components/servo/controller.cpp
3+
*
4+
* Controller for the servo API
5+
*
6+
* Adafruit invests time and resources providing this open source code,
7+
* please support Adafruit and open-source hardware by purchasing
8+
* products from Adafruit!
9+
*
10+
* Copyright (c) Brent Rubell 2025 for Adafruit Industries.
11+
*
12+
* BSD license, all text here must be included in any redistribution.
13+
*
14+
*/
15+
#include "controller.h"
16+
17+
/**************************************************************************/
18+
/*!
19+
@brief Constructor
20+
*/
21+
/**************************************************************************/
22+
ServoController::ServoController() {
23+
24+
}
25+
26+
/**************************************************************************/
27+
/*!
28+
@brief Destructor
29+
*/
30+
/**************************************************************************/
31+
ServoController::~ServoController() {
32+
33+
}
34+
35+
/**************************************************************************/
36+
/*!
37+
@brief Handles a ServoAdd message
38+
@param stream
39+
pb_istream_t to decode from
40+
@returns True if successful, False otherwise
41+
*/
42+
/**************************************************************************/
43+
bool ServoController::Handle_Servo_Add(pb_istream_t *stream) {
44+
45+
}
46+
47+
/**************************************************************************/
48+
/*!
49+
@brief Handles a ServoWrite message
50+
@param stream
51+
pb_istream_t to decode from
52+
@returns True if successful, False otherwise
53+
*/
54+
/**************************************************************************/
55+
bool ServoController::Handle_Servo_Write(pb_istream_t *stream) {
56+
57+
}
58+
59+
/**************************************************************************/
60+
/*!
61+
@brief Handles a ServoRemove message
62+
@param stream
63+
pb_istream_t to decode from
64+
@returns True if successful, False otherwise
65+
*/
66+
/**************************************************************************/
67+
bool ServoController::Handle_Servo_Remove(pb_istream_t *stream) {
68+
69+
}

src/components/servo/controller.h

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*!
2+
* @file src/components/servo/controller.h
3+
*
4+
* Controller for the servo API
5+
*
6+
* Adafruit invests time and resources providing this open source code,
7+
* please support Adafruit and open-source hardware by purchasing
8+
* products from Adafruit!
9+
*
10+
* Copyright (c) Brent Rubell 2025 for Adafruit Industries.
11+
*
12+
* BSD license, all text here must be included in any redistribution.
13+
*
14+
*/
15+
#ifndef WS_SERVO_CONTROLLER_H
16+
#define WS_SERVO_CONTROLLER_H
17+
#include "Wippersnapper_V2.h"
18+
#include "hardware.h"
19+
#include "model.h"
20+
21+
#ifdef ARDUINO_ARCH_RP2040
22+
#define MAX_SERVOS 8 ///< Maximum number of servo objects for RP2040, https://arduino-pico.readthedocs.io/en/latest/servo.html
23+
#else
24+
#define MAX_SERVOS 16 ///< Maximum number of servo objects
25+
#endif
26+
#define MIN_SERVO_PULSE_WIDTH 500 ///< Default min. servo pulse width of 500uS
27+
28+
class Wippersnapper_V2; // Forward declaration
29+
class ServoModel; // Forward declaration
30+
class ServoHardware; // Forward declaration
31+
32+
/**************************************************************************/
33+
/*!
34+
@brief Routes messages using the servo.proto API to the
35+
appropriate hardware and model classes, controls and tracks
36+
the state of the hardware's Servo pins.
37+
*/
38+
/**************************************************************************/
39+
class ServoController {
40+
public:
41+
ServoController();
42+
~ServoController();
43+
bool Handle_Servo_Add(pb_istream_t *stream);
44+
bool Handle_Servo_Write(pb_istream_t *stream);
45+
bool Handle_Servo_Remove(pb_istream_t *stream);
46+
private:
47+
ServoModel *_servo_model;
48+
ServoHardware *_servo_hardware[MAX_SERVOS] = {nullptr};
49+
};
50+
extern Wippersnapper_V2 WsV2; ///< Wippersnapper V2 instance
51+
#endif // WS_SERVO_CONTROLLER_H

src/components/servo/hardware.cpp

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
/*!
2+
* @file src/components/servo/hardware.cpp
3+
*
4+
* Hardware for the servo.proto message.
5+
*
6+
* Adafruit invests time and resources providing this open source code,
7+
* please support Adafruit and open-source hardware by purchasing
8+
* products from Adafruit!
9+
*
10+
* Copyright (c) Brent Rubell 2025 for Adafruit Industries.
11+
*
12+
* BSD license, all text here must be included in any redistribution.
13+
*
14+
*/
15+
#include "hardware.h"
16+
17+
/**************************************************************************/
18+
/*!
19+
@brief Constructor
20+
*/
21+
/**************************************************************************/
22+
ServoHardware::ServoHardware() {
23+
24+
}
25+
26+
/**************************************************************************/
27+
/*!
28+
@brief Destructor
29+
*/
30+
/**************************************************************************/
31+
ServoHardware::~ServoHardware() {
32+
33+
}
34+
35+
/**************************************************************************/
36+
/*!
37+
@brief Attaches a pin to a servo
38+
@param pin
39+
The pin to attach
40+
@param frequency
41+
The servo frequency (in Hz)
42+
@param min_pulse_width
43+
The minimum pulse width (in microseconds)
44+
@param max_pulse_width
45+
The maximum pulse width (in microseconds)
46+
@returns True if successful, False otherwise
47+
*/
48+
/**************************************************************************/
49+
bool ServoHardware::AttachPin(uint8_t pin, uint32_t frequency, uint32_t min_pulse_width, uint32_t max_pulse_width) {
50+
51+
}
52+
53+
/**************************************************************************/
54+
/*!
55+
@brief Detaches a pin from a servo
56+
@returns True if successful, False otherwise
57+
*/
58+
/**************************************************************************/
59+
bool ServoHardware::DetachPin() {
60+
61+
}
62+
63+
/**************************************************************************/
64+
/*!
65+
@brief Writes a pulse width to the servo
66+
@param pulse_width
67+
The pulse width (in microseconds) to write
68+
@returns True if successful, False otherwise
69+
*/
70+
/**************************************************************************/
71+
bool ServoHardware::WritePulseWidth(uint32_t pulse_width) {
72+
73+
}
74+
75+
/**************************************************************************/
76+
/*!
77+
@brief Returns the pin number
78+
@returns The pin number
79+
*/
80+
/**************************************************************************/
81+
uint8_t ServoHardware::GetPin() {
82+
83+
}
84+
85+
#ifdef ARDUINO_ARCH_ESP32
86+
/**************************************************************************/
87+
/*!
88+
@brief Abstraction for ESP32's servo write API
89+
@param value
90+
The value to write
91+
@returns True if successful, False otherwise
92+
*/
93+
/**************************************************************************/
94+
bool ServoHardware::servoWrite(uint32_t value) {
95+
96+
}
97+
#endif

src/components/servo/hardware.h

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*!
2+
* @file src/components/servo/hardware.h
3+
*
4+
* Hardware for the servo.proto message.
5+
*
6+
* Adafruit invests time and resources providing this open source code,
7+
* please support Adafruit and open-source hardware by purchasing
8+
* products from Adafruit!
9+
*
10+
* Copyright (c) Brent Rubell 2025 for Adafruit Industries.
11+
*
12+
* BSD license, all text here must be included in any redistribution.
13+
*
14+
*/
15+
#ifndef WS_SERVO_HARDWARE_H
16+
#define WS_SERVO_HARDWARE_H
17+
#include "Wippersnapper_V2.h"
18+
19+
20+
/**************************************************************************/
21+
/*!
22+
@brief Interface for interacting with hardware's Servo API.
23+
*/
24+
/**************************************************************************/
25+
class ServoHardware {
26+
public:
27+
ServoHardware();
28+
~ServoHardware();
29+
private:
30+
};
31+
#endif // WS_SERVO_HARDWARE_H

src/components/servo/model.cpp

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
/*!
2+
* @file src/components/servo/model.cpp
3+
*
4+
* Model for the servo.proto message.
5+
*
6+
* Adafruit invests time and resources providing this open source code,
7+
* please support Adafruit and open-source hardware by purchasing
8+
* products from Adafruit!
9+
*
10+
* Copyright (c) Brent Rubell 2025 for Adafruit Industries.
11+
*
12+
* BSD license, all text here must be included in any redistribution.
13+
*
14+
*/
15+
#include "model.h"
16+
17+
/**************************************************************************/
18+
/*!
19+
@brief Constructor
20+
*/
21+
/**************************************************************************/
22+
ServoModel::ServoModel() {
23+
24+
}
25+
26+
/**************************************************************************/
27+
/*!
28+
@brief Destructor
29+
*/
30+
/**************************************************************************/
31+
ServoModel::~ServoModel() {
32+
33+
}
34+
35+
/**************************************************************************/
36+
/*!
37+
@brief Decodes a ServoAdd message from a pb_istream_t
38+
@param stream
39+
pb_istream_t to decode from
40+
@returns True if successful, False otherwise
41+
*/
42+
/**************************************************************************/
43+
bool ServoModel::DecodeServoAdd(pb_istream_t *stream) {
44+
45+
}
46+
47+
/**************************************************************************/
48+
/*!
49+
@brief Returns a pointer to the ServoAdd message
50+
@returns Pointer to ServoAdd message
51+
*/
52+
/**************************************************************************/
53+
wippersnapper_servo_ServoAdd *ServoModel::GetServoAddMsg() {
54+
55+
}
56+
57+
/**************************************************************************/
58+
/*!
59+
@brief Encodes a ServoAdded message
60+
@param pin_name
61+
Name of the pin
62+
@param did_attach
63+
True if a servo was attached to the pin successfully,
64+
False otherwise
65+
@returns True if successful, False otherwise
66+
*/
67+
/**************************************************************************/
68+
bool ServoModel::EncodeServoAdded(char *pin_name, bool did_attach) {
69+
70+
}
71+
72+
/**************************************************************************/
73+
/*!
74+
@brief Returns a pointer to the ServoAdded message
75+
@returns Pointer to ServoAdded message
76+
*/
77+
/**************************************************************************/
78+
wippersnapper_servo_ServoAdded *ServoModel::GetServoAddedMsg() {
79+
80+
}
81+
82+
/**************************************************************************/
83+
/*!
84+
@brief Decodes a ServoRemove message from a pb_istream_t
85+
@param stream
86+
pb_istream_t to decode from
87+
@returns True if successful, False otherwise
88+
*/
89+
/**************************************************************************/
90+
bool ServoModel::DecodeServoRemove(pb_istream_t *stream) {
91+
92+
}
93+
94+
/**************************************************************************/
95+
/*!
96+
@brief Returns a pointer to the ServoRemove message
97+
@returns Pointer to ServoRemove message
98+
*/
99+
/**************************************************************************/
100+
wippersnapper_servo_ServoRemove *ServoModel::GetServoRemoveMsg() {
101+
102+
}
103+
104+
/**************************************************************************/
105+
/*!
106+
@brief Decodes a ServoWrite message from a pb_istream_t
107+
@param stream
108+
pb_istream_t to decode from
109+
@returns True if successful, False otherwise
110+
*/
111+
/**************************************************************************/
112+
bool ServoModel::DecodeServoWrite(pb_istream_t *stream) {
113+
114+
}
115+
116+
/**************************************************************************/
117+
/*!
118+
@brief Returns a pointer to the ServoWrite message
119+
@returns Pointer to ServoWrite message
120+
*/
121+
/**************************************************************************/
122+
wippersnapper_servo_ServoWrite *ServoModel::GetServoWriteMsg() {
123+
124+
}

0 commit comments

Comments
 (0)