Skip to content

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

Merged
merged 1 commit into from
Mar 16, 2019

Conversation

dronejunkie
Copy link
Contributor

This PR is in response to this PR betaflight/betaflight#7671

@dronejunkie
Copy link
Contributor Author

Here is the screen recording https://www.youtube.com/watch?v=ZxatONuCn_8

@dronejunkie
Copy link
Contributor Author

Sorry about all of those commit points. Please let me know if you want me to squash them.

ctx.drawImage(img, (element.x + offsetX) * 12, (element.y + offsetY) * 18);
}
//Add string to the preview.
if (element.constructor == String) {
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 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

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.

Copy link
Contributor Author

@dronejunkie dronejunkie Mar 9, 2019

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

Copy link
Member

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.

@dronejunkie
Copy link
Contributor Author

dronejunkie commented Mar 11, 2019

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.

position -= (selectedPositionX + limits.maxX + 1) - FONT.constants.SIZES.LINE;    (line 1751)
position -= (selectedPositionY + limits.maxY - OSD.data.display_size.y + 1) * FONT.constants.SIZES.LINE; (line 1756)

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

@@ -803,7 +803,7 @@ OSD.constants = {
default_position: -1,
draw_order: 490,
positionable: true,
preview: '226000'
preview: [ "22600","22600","22600","22600"]
Copy link
Member

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.

limits.maxY = Math.max(valor.y, limits.maxY);
});
if ((arrayElements.length > 0) && (arrayElements[0].constructor == String)) {
limits.maxY=arrayElements.length;
Copy link
Member

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.

@@ -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)) {
Copy link
Member

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.

ctx.drawImage(img, (element.x + offsetX) * 12, (element.y + offsetY) * 18);
}
//Add string to the preview.
if (element.constructor == String) {
Copy link
Member

Choose a reason for hiding this comment

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

Indentation.

@dronejunkie
Copy link
Contributor Author

I have done the requested changes. Please review.

limits.maxY = Math.max(valor.y, limits.maxY);
});
if ((arrayElements.length > 0) && (arrayElements[0].constructor === String)) {
limits.maxY = arrayElements.length;
Copy link
Member

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

@@ -3696,6 +3696,9 @@
"osdDescElementEscRpm": {
"message": "RPM reported by ESC telemetry"
},
"osdDescElementEscRpmFreq": {
"message": "RPM Freq reported by ESC telemetry"
Copy link
Member

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?

@dronejunkie
Copy link
Contributor Author

dronejunkie commented Mar 14, 2019

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.

@mikeller mikeller added this to the 10.5.0 milestone Mar 14, 2019
@mikeller
Copy link
Member

mikeller commented Mar 14, 2019

All good, the formatting looks good now. Unfortunately, with your changes pre-existing elements using a custom draw function can now moved around and positioned so that they wrap around the screen:

image

(This isn't possible before your change.)

@dronejunkie
Copy link
Contributor Author

I could replicate this issue with build #131 Here is the video, skip to near the end
https://youtu.be/eylOIegBaU0

@dronejunkie
Copy link
Contributor Author

dronejunkie commented Mar 15, 2019

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.

if (arrayElements.length > 0) {
limits.maxY = arrayElements.length;
limits.minY = 0;
limits.minX = 0;
arrayElements.forEach(function(valor, indice, array) {
limits.maxX = Math.max(valor.length, limits.maxX);
});
limits.maxX--;
limits.maxY--;
} else {

I will do the change when I get home tonight. The above should only be applicable to the array of strings.

@mikeller
Copy link
Member

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).

@dronejunkie
Copy link
Contributor Author

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
https://youtu.be/cC8YI7eUaM4

@dronejunkie
Copy link
Contributor Author

dronejunkie commented Mar 16, 2019

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.

@mikeller
Copy link
Member

Found the culprit that broke wrapping for arrays of char: #1165.

mikeller
mikeller previously approved these changes Mar 16, 2019
@mikeller
Copy link
Member

Can you rebase and squash into one commit please?

@dronejunkie
Copy link
Contributor Author

rebased and squashed to one commit. Thanks for your help!

@mikeller mikeller merged commit 9e3f279 into betaflight:master Mar 16, 2019
@mikeller
Copy link
Member

Thanks for sticking with me - that regression on wraparound is nasty.

@dronejunkie
Copy link
Contributor Author

@mikeller , I have a fix for it. Here is the test I have done.
https://youtu.be/ZnzQeR34jok

@dronejunkie dronejunkie deleted the rpm-osd branch March 17, 2019 08:19
@mikeller
Copy link
Member

@dronejunkie: Looks good! Thanks for looking into this!

@dronejunkie
Copy link
Contributor Author

Do I raise a separate PR?

@McGiverGim
Copy link
Member

Yes, this has been merged. You need a new PR.

@mikeller mikeller added the RN: UI label Apr 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants