Line data Source code
1 : /* 2 : * AP_ServoRelayEvent.h 3 : * 4 : * handle DO_SET_SERVO, DO_REPEAT_SERVO, DO_SET_RELAY and 5 : * DO_REPEAT_RELAY commands 6 : */ 7 : #pragma once 8 : 9 : #include "AP_ServoRelayEvents_config.h" 10 : 11 : #if AP_SERVORELAYEVENTS_ENABLED 12 : 13 : #include <AP_Param/AP_Param.h> 14 : #include <AP_Relay/AP_Relay.h> 15 : 16 : class AP_ServoRelayEvents { 17 : public: 18 2098 : AP_ServoRelayEvents() 19 : #if AP_RELAY_ENABLED 20 2098 : : type(EVENT_TYPE_RELAY) 21 : #endif 22 : { 23 2098 : _singleton = this; 24 2098 : } 25 : 26 : /* Do not allow copies */ 27 : CLASS_NO_COPY(AP_ServoRelayEvents); 28 : 29 : // get singleton instance 30 832 : static AP_ServoRelayEvents *get_singleton() { 31 832 : return _singleton; 32 : } 33 : 34 : bool do_set_servo(uint8_t channel, uint16_t pwm); 35 : #if AP_RELAY_ENABLED 36 : bool do_set_relay(uint8_t relay_num, uint8_t state); 37 : #endif 38 : bool do_repeat_servo(uint8_t channel, uint16_t servo_value, int16_t repeat, uint16_t delay_time_ms); 39 : #if AP_RELAY_ENABLED 40 : bool do_repeat_relay(uint8_t relay_num, int16_t count, uint32_t period_ms); 41 : #endif 42 : void update_events(void); 43 : 44 : private: 45 : 46 : static AP_ServoRelayEvents *_singleton; 47 : 48 : // event control state 49 : enum event_type { 50 : #if AP_RELAY_ENABLED 51 : EVENT_TYPE_RELAY=0, 52 : #endif 53 : EVENT_TYPE_SERVO=1 54 : }; 55 : 56 : enum event_type type; 57 : 58 : // when the event was started in ms 59 : uint32_t start_time_ms; 60 : 61 : // how long to delay the next firing of event in millis 62 : uint16_t delay_ms; 63 : 64 : // how many times to cycle : -1 (or -2) = forever, 2 = do one cycle, 4 = do two cycles 65 : int16_t repeat; 66 : 67 : // RC channel for servos, relay number for relays 68 : uint8_t channel; 69 : 70 : // PWM for servos 71 : uint16_t servo_value; 72 : }; 73 : 74 : namespace AP { 75 : AP_ServoRelayEvents *servorelayevents(); 76 : }; 77 : 78 : #endif // AP_SERVORELAYEVENTS_ENABLED