Skip to content
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

Mcu ID for vtx tables #361

Merged
merged 1 commit into from
Sep 20, 2020
Merged

Conversation

kristjanbjarni
Copy link
Contributor

Reads craft name from MSP and uses that name to store the vtx tables. If the craft name is empty it falls back on using the transmitter model name as before. This should solve the problem of using an incorrect vtx table when people have many different crafts with different vtx hardware under the same model name.

src/SCRIPTS/BF/ui_init.lua Outdated Show resolved Hide resolved
src/SCRIPTS/BF/ui_init.lua Outdated Show resolved Hide resolved
src/SCRIPTS/BF/ui_init.lua Outdated Show resolved Hide resolved
@kristjanbjarni
Copy link
Contributor Author

Addressed all of the review comments by removing dead code and adding check for conditional download of craft name if vtx tables are not supported.

@klutvott123 klutvott123 added this to the 1.6 milestone Sep 12, 2020
@klutvott123
Copy link
Member

@kristjanbjarni Looks good 👍. Tested and works as expected. Could you squash please?

@klutvott123
Copy link
Member

There is still the issue that craft name isn't guaranteed to be unique just like model name. I think the best solution would be if each FC had a unique identifier. STM devices have a unique 96 bit id and it's available through MSP(MSP_UID). This could possibly simplify things and remove a lot of confusion.

@mikeller Any thoughts on using the mcu id for this?

@kristjanbjarni
Copy link
Contributor Author

@klutvott123 This is my first pull request so I am not really sure how I squash correctly, seems I messed it up?

There is still the issue that craft name isn't guaranteed to be unique just like model name. I think the best solution would be if each FC had a unique identifier. STM devices have a unique 96 bit id and it's available through MSP(MSP_UID). This could possibly simplify things and remove a lot of confusion.

I think the only reason for craft name not being unique is if somebody is using it for their pilot name. Since there already exists "Display name" for pilot name I would consider that to be erroneous usage of craft name. But maybe mcu id would be a better idea.

@mikeller
Copy link
Member

@klutvott123: Good idea! Using the MCU id will solve this once and for all.

@klutvott123
Copy link
Member

All right let's do it!

@kristjanbjarni I agree, but there will always be someone doing it wrong. By using the mcu id it should just work without the user having to keep track of all their model names and craft names. The code you have already written could easily be adapted to get the mcu id from the FC. Would you like to have a go at it?

You had two commits on your branch and wanted to squash them into one commit.
You would do this with git rebase -i HEAD~2. This brings up a text editor with a list of the two last commits prepended with pickalong with some instructions. Change pick to squash(but fixup might be better in this case) for the second commit in the list, save and exit. Now you should have only one commit on your local branch. Now to make the remote branch the same as your local branch you can do git push --force-with-lease.

I assume your local branch now has the same commit history as the remote. 3 commits and a merge. To get it back to where you were before squashing/pushing/pulling/merging do you can do git log to find the hash string of the Simplified ui_init commit. Then you can do git reset --hard your-commit-hash-string-here. Then you should be back where you started and can do the process described above.

@kristjanbjarni
Copy link
Contributor Author

@klutvott123 I fixed the commits.

Yes I can look into changing the code to use MCU id instead.

@kristjanbjarni
Copy link
Contributor Author

OK changed the name to use instead the MSP_UID as 24 hex characters to make it short and consistant. Tested a couple of quads, seemed to work just fine.

src/SCRIPTS/BF/craft_name.lua Outdated Show resolved Hide resolved
src/SCRIPTS/TOOLS/bf.lua Outdated Show resolved Hide resolved
@kristjanbjarni
Copy link
Contributor Author

Updated to use mcuId and fixed the order of the id to be the same order as mcu_id in CLI. I removed the check for apiVersion>1.042 since although you can't download the vtx tables under that version you should still be able to manually copy them to the transmitter and use them with the MCU id, right?

@klutvott123
Copy link
Member

@kristjanbjarni I think we should keep the check. Vtx tables were introduced in betaflight 4.1(api version 1.042) so I don't see why we would want to load vtx tables for firmware versions older than that. For that we have vtx_defaults.lua.

@kristjanbjarni
Copy link
Contributor Author

@klutvott123 Added the check back in

Comment on lines 14 to 25
elseif not mcuId then
if apiVersion >= 1.042 then
lcd.drawText(6, radio.yMinLimit, "Waiting for unique device ID")
getMCUId = getMCUId or assert(loadScript("mcu_id.lua"))()
if getMCUId() then
getMCUId = nil
local vtxTables = loadScript("/BF/VTX/"..mcuId..".lua")
if vtxTables and vtxTables() then
vtxTablesReceived = true
vtxTables = nil
end
collectgarbage()
end
else
mcuId = model.getInfo().name
end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if storing the model name in mcuId is the best thing to do. I would combine the conditionals like
elseif apiVersion >= 1.042 and not mcuId then
and leave mcuId = nilfor older versions.
This would require loading vtx tables or defaults in vtx.lua based on apiVersion like this:

local vtx_tables
if apiVersion >= 1.042 then
    vtx_tables = assert(loadScript("/BF/VTX/"..mcuId..".lua"))()
else
    vtx_tables = assert(loadScript("/BF/VTX/vtx_defaults.lua"))()
end

Can we change the message to just "Waiting for device ID"? That would make it fit nicely on the 128x64 screens too.

@klutvott123
Copy link
Member

@kristjanbjarni Great! Just added some comments. We're almost there 😁

Reads MCU id from MSP and uses that unique id to store the vtx tables. This should solve the problem of using an incorrect vtx table when there are different crafts with different vtx hardware under the same model name.
@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities (and Security Hotspot 0 Security Hotspots to review)
Code Smell A 0 Code Smells

No Coverage information No Coverage information
No Duplication information No Duplication information

Copy link
Member

@klutvott123 klutvott123 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Copy link
Member

@mikeller mikeller left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work, thanks @kristjanbjarni and @klutvott123, this will put this problem to an end once and for all.

@mikeller mikeller merged commit 335a9d4 into betaflight:master Sep 20, 2020
@kristjanbjarni kristjanbjarni deleted the craft_name branch December 29, 2020 13:45
@klutvott123 klutvott123 changed the title Craft name for vtx tables Mcu ID for vtx tables Apr 9, 2021
@klutvott123
Copy link
Member

Edited PR title to make it clear that we're using mcu ID and not craft name. Just to avoid any confusion

@limonspb
Copy link
Member

limonspb commented Jul 16, 2021

Sorry, late to the party and got nothing useful to say, but thanks a lot!!! This is brilliant.

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

Successfully merging this pull request may close these issues.

4 participants