-
-
Notifications
You must be signed in to change notification settings - Fork 983
Adding rpm freq osd element and new format for rpm. #1315
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
Here is the screen recording https://www.youtube.com/watch?v=ZxatONuCn_8 |
Sorry about all of those commit points. Please let me know if you want me to squash them. |
src/js/tabs/osd.js
Outdated
ctx.drawImage(img, (element.x + offsetX) * 12, (element.y + offsetY) * 18); | ||
} | ||
//Add string to the preview. | ||
if (element.constructor == String) { |
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.
Not sure if adding this is actually the right thing to do - this adds complexity, and the same effect can be achieved easily by returning an array of objects, like it is done in
betaflight-configurator/src/js/tabs/osd.js
Lines 474 to 509 in 4dcc910
ARTIFICIAL_HORIZON: { | |
name: 'ARTIFICIAL_HORIZON', | |
desc: 'osdDescElementArtificialHorizon', | |
default_position: function () { | |
var position = 74; | |
if (OSD.constants.VIDEO_TYPES[OSD.data.video_system] != 'NTSC') { | |
position += FONT.constants.SIZES.LINE; | |
} | |
return position; | |
}, | |
draw_order: 10, | |
positionable: function () { | |
return semver.gte(CONFIG.apiVersion, "1.39.0") ? true : false; | |
}, | |
preview: function () { | |
var artificialHorizon = new Array(); | |
for (var j = 1; j < 8; j++) { | |
for (var i = -4; i <= 4; i++) { | |
var element; | |
// Blank char to mark the size of the element | |
if (j != 4) { | |
element = { x: i, y: j, sym: SYM.BLANK }; | |
// Sample of horizon | |
} else { | |
element = { x: i, y: j, sym: SYM.AH_BAR9_0 + 4 }; | |
} | |
artificialHorizon.push(element); | |
} | |
} | |
return artificialHorizon; | |
} | |
}, |
Also, this does not check to make sure the element can fit onto the screen.
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.
This was what I initially looked at but this only does one char per element as far I can see. I have thought of iterating through each strings and create individual element for each character. However this becomes very messy. I am new to this so I may have missed something.
RE making sure the element can fit, are you referring to this code below which re-position the element when it is dropped onto the canvas? This can be expanded.
if (display_item.preview.constructor !== Array) {
// Standard preview, string type
var overflows_line = FONT.constants.SIZES.LINE - ((position % FONT.constants.SIZES.LINE) + display_item.preview.length);
if (overflows_line < 0) {
position += overflows_line;
}
} else {
// Advanced preview, array type
var arrayElements = display_item.preview;
var limits = OSD.searchLimitsElement(arrayElements);
var selectedPositionX = position % FONT.constants.SIZES.LINE;
var selectedPositionY = Math.trunc(position / FONT.constants.SIZES.LINE);
if ((limits.minX < 0) && ((selectedPositionX + limits.minX) < 0)) {
position += Math.abs(selectedPositionX + limits.minX);
} else if ((limits.maxX > 0) && ((selectedPositionX + limits.maxX) >= FONT.constants.SIZES.LINE)) {
position -= (selectedPositionX + limits.maxX + 1) - FONT.constants.SIZES.LINE;
}
if ((limits.minY < 0) && ((selectedPositionY + limits.minY) < 0)) {
position += Math.abs(selectedPositionY + limits.minY) * FONT.constants.SIZES.LINE;
} else if ((limits.maxY > 0) && ((selectedPositionY + limits.maxY) >= OSD.data.display_size.y)) {
position -= (selectedPositionY + limits.maxY - OSD.data.display_size.y + 1) * FONT.constants.SIZES.LINE;
}
}
}
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.
Good point, I thought the array of objects could be used for strings as well. If not, extending that, and allowing the strings to be anchored to an arbitrary point makes more sense in my opinion.
And yes - we want to prevent users from placing elements off screen.
Here is the screen video capture https://youtu.be/MSsPLAxVrf0. Placement of the element is pretty precise and user can not drag it outside of the canvas. However you can not drag element to the edge of the bottom or left of the screen. This is because of the current existing logic below which re-align the x and y position when there is overflow. I am not sure why there is a +1 there, which become -1 i.e Y is one less and so is X. In affect you are losing one line.
Here is a demonstration of what I meant https://youtu.be/TvEreM_Ofrw I can have a separate formulae for my case if that is ok with you, which allow user to drag it all the way down to the edge. Here is what it should look like https://youtu.be/pcGGyogsLEg |
src/js/tabs/osd.js
Outdated
@@ -803,7 +803,7 @@ OSD.constants = { | |||
default_position: -1, | |||
draw_order: 490, | |||
positionable: true, | |||
preview: '226000' | |||
preview: [ "22600","22600","22600","22600"] |
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.
Please use space after comma.
src/js/tabs/osd.js
Outdated
limits.maxY = Math.max(valor.y, limits.maxY); | ||
}); | ||
if ((arrayElements.length > 0) && (arrayElements[0].constructor == String)) { | ||
limits.maxY=arrayElements.length; |
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.
Indentation.
Also, please use space around operators.
src/js/tabs/osd.js
Outdated
@@ -1669,7 +1686,7 @@ OSD.GUI.preview = { | |||
var offsetX = 6; | |||
var offsetY = 9; | |||
|
|||
if (display_item.preview.constructor === Array) { | |||
if ((display_item.preview.constructor === Array) && (display_item.preview[0].constructor != String)) { |
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.
This should use non-coercing inequality.
src/js/tabs/osd.js
Outdated
ctx.drawImage(img, (element.x + offsetX) * 12, (element.y + offsetY) * 18); | ||
} | ||
//Add string to the preview. | ||
if (element.constructor == String) { |
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.
Indentation.
I have done the requested changes. Please review. |
src/js/tabs/osd.js
Outdated
limits.maxY = Math.max(valor.y, limits.maxY); | ||
}); | ||
if ((arrayElements.length > 0) && (arrayElements[0].constructor === String)) { | ||
limits.maxY = arrayElements.length; |
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.
I think you should check the indentation settings in the editor that you are using. Betaflight coding style states 4 spaces for indentation, and there are still plenty of tabs in your changes: https://github.com/betaflight/betaflight/blob/master/docs/development/CodingStyle.md#indentation
locales/en/messages.json
Outdated
@@ -3696,6 +3696,9 @@ | |||
"osdDescElementEscRpm": { | |||
"message": "RPM reported by ESC telemetry" | |||
}, | |||
"osdDescElementEscRpmFreq": { | |||
"message": "RPM Freq reported by ESC telemetry" |
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.
Can we change this to 'frequency' please?
Sorry about the tab, I have been editing from a Windows laptop instead of my normal Linux Dev pc. It should be ok now. I have aligned the new element layout with the single char layout. As a result I could reuse existing logic for single char and do not need to distinct between array of string or single character. All tested fine. |
I could replicate this issue with build #131 Here is the video, skip to near the end |
I found a silly mistake in my code. This will definitely can cause the wrapping for the array of characters osd element. This however does not explain why I could replicate this issue in build #131. I will double check my testing of #131 again. betaflight-configurator/src/js/tabs/osd.js Lines 1125 to 1134 in 4592324
I will do the change when I get home tonight. The above should only be applicable to the array of strings. |
Thanks for looking into this again @dronejunkie. It's well possible that the existing code is buggy as well, allowing this to happen some times, but your changes seemed to allow it to happen every time (or else I got 'lucky' 2 times out of 2 that I tried to replicate it with your changes). |
I tried with latest build and it is very easy to replicate this issue. You just need to place the cursor towards the top left corner and it will wrap every single time. Here is the video |
Latest fix should fix the wrapping issue for array of strings. The logic for detection/adjustment of wrapping for array of single char and array of strings are different. The array of single char one stay untouched. The testing I have done so far for the array of strings did not show any wrapping issue. |
Found the culprit that broke wrapping for arrays of char: #1165. |
Can you rebase and squash into one commit please? |
…type, which is an array of string.
rebased and squashed to one commit. Thanks for your help! |
Thanks for sticking with me - that regression on wraparound is nasty. |
@mikeller , I have a fix for it. Here is the test I have done. |
@dronejunkie: Looks good! Thanks for looking into this! |
Do I raise a separate PR? |
Yes, this has been merged. You need a new PR. |
This PR is in response to this PR betaflight/betaflight#7671