-
Notifications
You must be signed in to change notification settings - Fork 72
Initial vtx support (TBS SmartAudio) #159
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
my comments are mainly about convention and structure, but overall I like it, thanks ;)
lib/Espfc/src/Model.h
Outdated
@@ -548,6 +548,7 @@ class Model | |||
pid.begin(); | |||
} | |||
state.customMixer = MixerConfig(config.customMixerCount, config.customMixes); | |||
if (state.vtx != NULL) state.vtx->load(config.vtx.channel, config.vtx.band, config.vtx.power, config.vtx.lowPowerDisarm); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
manage whole communication in Vtx::update(), I recommend to make state machine with switch-case construction, like:
switch(_state)
{
case STATE_INIT:
// some initialization code if required
_state = STATE_SET_POWER;
break;
case STATE_SET_POWER:
setPower();
_state = STATE_SET_CHANNEL;
break;
case STATE_SET_CHANNEL:
setChannel();
_state = STATE_SET_POWER;
break;
default:
_state = STATE_INIT;
}
lib/Espfc/src/ModelState.h
Outdated
@@ -328,6 +329,7 @@ struct ModelState | |||
MagState mag; | |||
BaroState baro; | |||
|
|||
Device::Vtx * vtx; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there is no real need keep device pointer in model, avoid this practice if possible.
lib/Espfc/src/SerialManager.cpp
Outdated
{ | ||
sdc.baud = 4800; | ||
sdc.parity = SDC_SERIAL_PARITY_NONE; | ||
sdc.stop_bits = SDC_SERIAL_STOP_BITS_1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AFAIR there are 2 stop bits in spec
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you're right. confused it with number of start bits
lib/Espfc/src/Espfc.cpp
Outdated
@@ -61,6 +61,7 @@ int FAST_CODE_ATTR Espfc::update(bool externalTrigger) | |||
_serial.update(); | |||
_buzzer.update(); | |||
_model.state.stats.update(); | |||
if (_model.state.vtx && _model.state.vtx->timer.check()) _model.state.vtx->setPower(_model.isModeActive(MODE_ARMED)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just call _vtx.update() in SerialManager::update() function. Check timer condition at the beginning of Vtx::update() function.
lib/Espfc/src/Device/Vtx.cpp
Outdated
crc = crc8tab[crc ^ *ptr++]; | ||
} | ||
return crc; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fix indentation, use spaces around operators. make function and variables above static.
lib/Espfc/src/Device/Vtx.cpp
Outdated
int Vtx::update() | ||
{ | ||
if(!_serial) return 0; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
put logic here with state machine and timer check.
lib/Espfc/src/Device/Vtx.hpp
Outdated
class Vtx | ||
{ | ||
public: | ||
Vtx(): _serial(NULL) {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pass Model& reference in constructor so you'll get access to config and global state inside.
lib/Espfc/src/Device/Vtx.hpp
Outdated
uint8_t band; | ||
uint8_t power; | ||
uint8_t lowPowerDisarm; | ||
bool armed = false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
once you have a Model& reference, you won't need these variables anymore.
lib/Espfc/src/Device/Vtx.hpp
Outdated
VTXDEV_UNKNOWN = 0xFF, | ||
}; | ||
|
||
class Vtx |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One more thing, namespace/directory Connect
would be better place for it, if you don't mind. Thanks.
b318600
to
9089acb
Compare
9089acb
to
5255def
Compare
@rtlopez addressed everything :) |
@Alissonsz Your changes are now in master branch, thank you :) |
this adds basic vtx support, what should be possible:
I tested it with Eachine tx805, so not sure how it will behave with different transmitters, but the smartaudio functions implemented here seems to be the same for all the smartaudio revisions.