Rockbox Ports are now being developed for various digital audio players!
%?bl<U|A|B|C|D|E>
*intval = (enum - 1) * battery_level() / 100 + 1 + 1;
I was digging into why my image-based battery meter didn't seem to be working correctly. Of my 5+1 images, The highest value was only displaying at 100%. This thanks to the "dynamic battery meter" feature added by learman on 2006-08-26 (r1.61). Before you say the obvious "because he added a '-1' value to display 'unknown' values", that's not the cause. The problem is that skip_conditional() counts the number of |s in a conditional, not the number of options in the conditional. The code in get_tag() for ?%bl assumes you're passing it the number of options. Take the following example:Code: [Select]%?blskip_conditional returns that there are 5 |s (in enum), which is correct. Note that we have 6 options (5 levels + 1 unknown). Now let's look at the get_tag code:Code: [Select]*intval = (enum - 1) * battery_level() / 100 + 1 + 1;this tries to quantize the battery level to 4 values, instead of 5.
%?bl
I'm posting this here for discussion instead of in bugs because it can be changed in one of three places:1 -- Change the bl tag code to not subtract 1. Easiest fix, no chance of regressions in other areas.2 -- Change the conditional code to add one to the enum result of skip_conditional(). Affects all conditionals (currently only %?pv, %?bl). This would affect the behavior of the volume conditional, in that now it shows the highest option only when volume is at 100%. Changing it here would show the highest option for the full volume / N quantization.3 -- Modify skip_conditional to return the count of options, not the count of pipes. This is a slightly larger code change, which requires it to keep track of if the last character encountered before the > is a |.#2 Seems like the way to go, but would like input before I formally submit the bug.
I remember that I also found some weird behaviour in skip_conditionals when I had a look at it:As far as I remember - it does not take care of "%|" and does also count it as conditional separator (I'm not sure about that - it's been a while since I had a look at)
- it's not able to handle tags with parameters inside conditionals (they also use the '|' as separator).
The second one is currently not relevant because there are no tags which are allowed inside conditionals which have parameters, but that may change in future (e.g. a tag for user ID3 tags).
The above code may look a bit odd, but is in fact correct. Note that battery_level() returns a number between 0 and 100 (inclusive). In this case, enum is 5, so the highest value you can get from the "first" part is 4 * 100 / 100, which is 4. The lowest value is 0. 0, 1, 2, 3, 4 - that's five values, which is what you want.
Page created in 0.096 seconds with 17 queries.