Skip to content

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

Merged
merged 1 commit into from
Feb 26, 2025
Merged

Conversation

Alissonsz
Copy link
Contributor

this adds basic vtx support, what should be possible:

  • VTX tab should show things up once you selected some UART as VTX (only smartaudio added)
  • You should be able to set channel/band/power and low power disarmed settings, only on and off supported for low power disarmed

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.

Copy link
Owner

@rtlopez rtlopez left a 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 ;)

@@ -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);
Copy link
Owner

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;
}

@@ -328,6 +329,7 @@ struct ModelState
MagState mag;
BaroState baro;

Device::Vtx * vtx;
Copy link
Owner

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.

{
sdc.baud = 4800;
sdc.parity = SDC_SERIAL_PARITY_NONE;
sdc.stop_bits = SDC_SERIAL_STOP_BITS_1;
Copy link
Owner

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

Copy link
Contributor Author

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

@@ -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));
Copy link
Owner

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.

crc = crc8tab[crc ^ *ptr++];
}
return crc;
}
Copy link
Owner

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.

int Vtx::update()
{
if(!_serial) return 0;

Copy link
Owner

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.

class Vtx
{
public:
Vtx(): _serial(NULL) {}
Copy link
Owner

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.

uint8_t band;
uint8_t power;
uint8_t lowPowerDisarm;
bool armed = false;
Copy link
Owner

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.

VTXDEV_UNKNOWN = 0xFF,
};

class Vtx
Copy link
Owner

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.

@Alissonsz Alissonsz force-pushed the vtx-support branch 2 times, most recently from b318600 to 9089acb Compare February 26, 2025 17:46
@Alissonsz
Copy link
Contributor Author

@rtlopez addressed everything :)

@rtlopez rtlopez changed the title Adds initial vtx support Initial vtx support Feb 26, 2025
@rtlopez rtlopez changed the title Initial vtx support Initial vtx support (TBS SmartAudio) Feb 26, 2025
@rtlopez rtlopez merged commit 5b2a59a into rtlopez:master Feb 26, 2025
8 checks passed
@rtlopez
Copy link
Owner

rtlopez commented Feb 26, 2025

@Alissonsz Your changes are now in master branch, thank you :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants