2014-01-20 00:36:09 -04:00
|
|
|
/*
|
|
|
|
* AP_ServoRelayEvent.h
|
|
|
|
*
|
|
|
|
* handle DO_SET_SERVO, DO_REPEAT_SERVO, DO_SET_RELAY and
|
|
|
|
* DO_REPEAT_RELAY commands
|
|
|
|
*/
|
2016-02-17 21:25:49 -04:00
|
|
|
#pragma once
|
2014-01-20 00:36:09 -04:00
|
|
|
|
2023-06-06 05:05:06 -03:00
|
|
|
#include "AP_ServoRelayEvents_config.h"
|
|
|
|
|
|
|
|
#if AP_SERVORELAYEVENTS_ENABLED
|
|
|
|
|
2015-08-11 03:28:45 -03:00
|
|
|
#include <AP_Param/AP_Param.h>
|
|
|
|
#include <AP_Relay/AP_Relay.h>
|
2014-01-20 00:36:09 -04:00
|
|
|
|
|
|
|
class AP_ServoRelayEvents {
|
|
|
|
public:
|
2019-06-27 20:46:05 -03:00
|
|
|
AP_ServoRelayEvents()
|
2023-06-06 05:05:06 -03:00
|
|
|
#if AP_RELAY_ENABLED
|
2019-06-27 20:46:05 -03:00
|
|
|
: type(EVENT_TYPE_RELAY)
|
2023-06-06 05:05:06 -03:00
|
|
|
#endif
|
2017-12-12 21:06:14 -04:00
|
|
|
{
|
2018-04-14 01:16:06 -03:00
|
|
|
_singleton = this;
|
2017-08-29 15:26:07 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Do not allow copies */
|
2022-09-30 06:50:43 -03:00
|
|
|
CLASS_NO_COPY(AP_ServoRelayEvents);
|
2014-01-20 00:36:09 -04:00
|
|
|
|
2018-04-14 01:16:06 -03:00
|
|
|
// get singleton instance
|
|
|
|
static AP_ServoRelayEvents *get_singleton() {
|
|
|
|
return _singleton;
|
|
|
|
}
|
|
|
|
|
2014-01-20 00:36:09 -04:00
|
|
|
bool do_set_servo(uint8_t channel, uint16_t pwm);
|
2023-06-06 05:05:06 -03:00
|
|
|
#if AP_RELAY_ENABLED
|
2014-01-20 00:36:09 -04:00
|
|
|
bool do_set_relay(uint8_t relay_num, uint8_t state);
|
2023-06-06 05:05:06 -03:00
|
|
|
#endif
|
2014-01-20 00:36:09 -04:00
|
|
|
bool do_repeat_servo(uint8_t channel, uint16_t servo_value, int16_t repeat, uint16_t delay_time_ms);
|
|
|
|
bool do_repeat_relay(uint8_t relay_num, int16_t count, uint32_t period_ms);
|
|
|
|
void update_events(void);
|
|
|
|
|
|
|
|
private:
|
2018-04-14 01:16:06 -03:00
|
|
|
|
|
|
|
static AP_ServoRelayEvents *_singleton;
|
|
|
|
|
2014-01-20 00:36:09 -04:00
|
|
|
// event control state
|
|
|
|
enum event_type {
|
2023-06-06 05:05:06 -03:00
|
|
|
#if AP_RELAY_ENABLED
|
2014-01-20 00:36:09 -04:00
|
|
|
EVENT_TYPE_RELAY=0,
|
2023-06-06 05:05:06 -03:00
|
|
|
#endif
|
2014-01-20 00:36:09 -04:00
|
|
|
EVENT_TYPE_SERVO=1
|
|
|
|
};
|
|
|
|
|
|
|
|
enum event_type type;
|
|
|
|
|
|
|
|
// when the event was started in ms
|
|
|
|
uint32_t start_time_ms;
|
|
|
|
|
|
|
|
// how long to delay the next firing of event in millis
|
|
|
|
uint16_t delay_ms;
|
|
|
|
|
|
|
|
// how many times to cycle : -1 (or -2) = forever, 2 = do one cycle, 4 = do two cycles
|
|
|
|
int16_t repeat;
|
|
|
|
|
|
|
|
// RC channel for servos, relay number for relays
|
|
|
|
uint8_t channel;
|
|
|
|
|
|
|
|
// PWM for servos
|
|
|
|
uint16_t servo_value;
|
|
|
|
};
|
2018-04-14 01:16:06 -03:00
|
|
|
|
|
|
|
namespace AP {
|
|
|
|
AP_ServoRelayEvents *servorelayevents();
|
|
|
|
};
|
2023-06-06 05:05:06 -03:00
|
|
|
|
|
|
|
#endif // AP_SERVORELAYEVENTS_ENABLED
|