-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsbus.h
31 lines (26 loc) · 765 Bytes
/
sbus.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#pragma once
#include <stdint.h>
constexpr uint16_t SBUS_VALUE_CENTER {1000};
constexpr uint16_t SBUS_VALUE_RADIUS {640};
constexpr uint16_t SBUS_VALUE_MIN {0};
constexpr uint16_t SBUS_VALUE_MAX {2047};
void SbusInit();
void SbusWrite();
void SbusBuildPacket();
inline void SbusInit()
{
}
inline uint16_t SbusFromPwm(uint16_t pulse_width_us) {
int32_t value =
(static_cast<int32_t>(pulse_width_us)
- static_cast<int32_t>(PWM_PULSE_WIDTH_CENTER_US))
* static_cast<int32_t>(SBUS_VALUE_RADIUS)
/ static_cast<int32_t>(PWM_PULSE_WIDTH_RADIUS_US)
+ static_cast<int32_t>(SBUS_VALUE_CENTER);
if (value < SBUS_VALUE_MIN) {
value = SBUS_VALUE_MIN;
} else if (value > SBUS_VALUE_MAX) {
value = SBUS_VALUE_MAX;
}
return static_cast<uint16_t>(value);
}