-
Notifications
You must be signed in to change notification settings - Fork 152
Expand file tree
/
Copy pathVtxSmartAudio.cpp
More file actions
69 lines (60 loc) · 1.6 KB
/
VtxSmartAudio.cpp
File metadata and controls
69 lines (60 loc) · 1.6 KB
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include "VtxSmartAudio.hpp"
#include "Utils/Crc.hpp"
static const uint8_t dummyByte[] = { 0x00 };
namespace Espfc::Connect {
int VtxSmartAudio::begin(Device::SerialDevice * serial)
{
_serial = serial;
_timer.setRate(300);
_state = State::INIT;
return 1;
}
int VtxSmartAudio::update()
{
if (!_timer.check()) return 1;
switch (_state)
{
case State::INIT:
_state = State::SET_CHANNEL;
_model.state.vtx.active = true;
break;
case State::SET_POWER:
setPower();
_state = State::IDLE;
break;
case State::SET_CHANNEL:
setChannel();
_state = State::SET_POWER;
break;
case State::IDLE:
if (_model.isModeActive(MODE_ARMED) != _armed)
{
_armed = !_armed;
_state = State::SET_POWER;
}
break;
case State::INACTIVE:
default:
break;
}
return 1;
}
int VtxSmartAudio::setChannel()
{
uint8_t vtxCommand[6] = { 0xAA, 0x55, 0x07, 0x01, (uint8_t)((_model.config.vtx.band -1)*8 + _model.config.vtx.channel - 1) };
vtxCommand[5] = Utils::crc8_dvb_s2(vtxCommand[5], reinterpret_cast<uint8_t*>(&vtxCommand), 5);
_serial->write(dummyByte, 1);
_serial->write(vtxCommand, 6);
_serial->flush();
return 1;
}
int VtxSmartAudio::setPower()
{
uint8_t vtxCommand[6] = { 0xAA, 0x55, 0x05, 0x01, (uint8_t)((!_model.config.vtx.lowPowerDisarm || _model.isModeActive(MODE_ARMED)) ? _model.config.vtx.power - 1 : 0) };
vtxCommand[5] = Utils::crc8_dvb_s2(vtxCommand[5], reinterpret_cast<uint8_t*>(&vtxCommand), 5);
_serial->write(dummyByte, 1);
_serial->write(vtxCommand, 6);
_serial->flush();
return 1;
}
}