hide_osd() script function - page 3 - General Discussion and Assistance - CHDK Forum

hide_osd() script function

  • 98 Replies
  • 34628 Views
*

Offline msl

  • *****
  • 1280
  • A720 IS, SX220 HS 1.01a
    • CHDK-DE links
Re: hide_osd() script function
« Reply #20 on: 29 / September / 2013, 16:43:26 »
Advertisements
The -1 value is useful if you just want to tie the OSD state to a button on your camera and not remember the OSD state in your script.
Ok, that makes sense and is useful. But this type does not correspond to the usual CHDK syntax get/set-...

msl
CHDK-DE:  CHDK-DE links

Re: hide_osd() script function
« Reply #21 on: 29 / September / 2013, 16:44:25 »
Just an observation if you have an equivalent get_chdk_osd_state, then to invert the state you could you not then use  something like

It think that's what reyalp meant when he posted :
I'm not really convinced toggle needs to be a parameter, you could trivially write your own using the on/off values, though it would be clearer if there was a corresponding get_ function.

The question is whether its worth the effort and space to add yet another function to avoid using the "toggle" = -1 trick lapser proposed ?
Ported :   A1200    SD940   G10    Powershot N    G16

*

Offline lapser

  • *****
  • 1093
Re: hide_osd() script function
« Reply #22 on: 29 / September / 2013, 16:45:31 »
The enums make the C code easier to understand, and the compiler is smart enough these days that it will make negligible difference to the code size or speed. You could also check against the enum values in the switch statement to make things clearer.

Is 'hide_osd' a suitable name for the function when calling 'hide_osd(1)' does the exact opposite, and 'hide_osd(-1)' could either show or hide the display. It also does not make it clear that the function only affects the CHDK OSD, not the Canon one. Perhaps 'set_chkd_osd_state' might be better.

My other concern is that the 'magic' integer values as parameters to the functions make the script code harder to follow for new users, or if you've forgotten what the magic numbers mean. Not sure what the best solution for this is - having three separate functions seems overkill.
Thanks for the input. I like:    set_chdk_osd( -1| 0 | 1).

This is similar to set_backlight(0 | 1), which everyone is already used to. Adding a -1 input for toggle is very useful in a script, I've discovered. And all the other script functions use "magic numbers" since  enum is not visible to scripts. You could use a string input, like "off", "on" or "toggle", but I think that's overkill for just 3 values, and is inconsistent with set_backlight and other functions. If you really hate the -1 option, that can be done in the script with another script variable. I find it useful, so I hope you'll agree to keep it.

Using enum is useful for C variables with 3 or more valid values, but not useful with only 2 values. I was able to handle the screen clearing with only 2 values, so enum isn't needed. A single assignment statement should take a lot less memory than the switch and all the if statements.

So I don't think -1,0, and 1 are too much to remember, especially if we keep it consistent with set_backlight and other functions. I'm working on set_display(-1,0,1) using reyalp's new display off event_proc discovery, so we can add that to the list.

The new code hides the osd when camera_info.state.osd_off is any non zero value. I only used the assignment to conditional form to force the values to 0 or 1. If you eliminate the -1 input, you can just store the parameter to camera_info.state.osd_off.

I agree that I want it to be as simple as possible to understand and use. However everyone else wants to implement it is fine with me.
EOS-M3_120f / SX50_100b / SX260_101a / G1X_100g / D20_100b
https://www.youtube.com/user/DrLapser/videos

Re: hide_osd() script function
« Reply #23 on: 29 / September / 2013, 16:57:36 »
Using enum is useful for C variables with 3 or more valid values, but not useful with only 2 values.
I respectfully disagree.

Quote
A single assignment statement should take a lot less memory than the switch and all the if statements.
Its almost always possible to write clever code that saves a few bytes at the expense of readability.  I'd submit that the trade-off is almost never worth it.
Ported :   A1200    SD940   G10    Powershot N    G16

*

Offline reyalp

  • ******
  • 14126
Re: hide_osd() script function
« Reply #24 on: 29 / September / 2013, 17:00:28 »
Code: [Select]
  if ( is_key("display")) then set_osd_state(!get_chdk_osd() ) end
until is_key("menu")

(Feel free to tell me to but out, since I have just come in to the conversation half way through  ;) )
Lua, it would be
set_osd_state( not get_chdk_osd() )

My $.02 This is a lot clearer than set_osd_state(-1)

I'm generally not fond of setters without getters anyway.
Don't forget what the H stands for.

Re: hide_osd() script function
« Reply #25 on: 29 / September / 2013, 17:10:54 »
Code: [Select]
  if ( is_key("display")) then set_osd_state(!get_chdk_osd() ) end
until is_key("menu")

(Feel free to tell me to but out, since I have just come in to the conversation half way through  ;) )
Lua, it would be
set_osd_state( not get_chdk_osd() )

My $.02 This is a lot clearer than set_osd_state(-1)

I'm generally not fond of setters without getters anyway.

So is the consensis to delete the -1 toggle function,  and add

Code: [Select]
         
                 set_chdk_osd( 0 | 1 )
                 state=get_chdk_osd()


??
Ported :   A1200    SD940   G10    Powershot N    G16

*

Offline lapser

  • *****
  • 1093
Re: hide_osd() script function
« Reply #26 on: 29 / September / 2013, 17:13:04 »
Using enum is useful for C variables with 3 or more valid values, but not useful with only 2 values.
I respectfully disagree.

Its almost always possible to write clever code that saves a few bytes at the expense of readability.  I'd submit that the trade-off is almost never worth it.
The new way I did it, camera_info.state.osd_off is a boolean variable whose name says what it does in the true (1) state. I don't see any advantage to using enum OFF, ON, which would be redundant.

We have different coding styles. Your style (enum, switch, if) is harder for me to understand, and my style is harder for you to understand. It's just what we're used to. Maybe clear comments are the best solution to readability, regardless of the style.

I really don't care what style goes in the trunk, as long as it works.
EOS-M3_120f / SX50_100b / SX260_101a / G1X_100g / D20_100b
https://www.youtube.com/user/DrLapser/videos

*

Offline msl

  • *****
  • 1280
  • A720 IS, SX220 HS 1.01a
    • CHDK-DE links
Re: hide_osd() script function
« Reply #27 on: 29 / September / 2013, 17:19:46 »
So is the consensis to delete the -1 toggle function,  and add

Code: [Select]
         
                 set_chdk_osd( 0 | 1 )
                 state=get_chdk_osd()


??
Yes.   
CHDK-DE:  CHDK-DE links

*

Offline lapser

  • *****
  • 1093
Re: hide_osd() script function
« Reply #28 on: 29 / September / 2013, 17:22:27 »
So is the consensis to delete the -1 toggle function,  and add
Code: [Select]
         
                 set_chdk_osd( 0 | 1 )
                 state=get_chdk_osd()
You really don't need get_chdk_osd(). The script knows it always starts out at 1, and only changes when the script sets it to something different.
Code: [Select]
state=1 -- at start of script

--code to toggle
if(state=1)then state=0 else state=1
set_chdk_osd(state)

OK, if I delete the -1 option, change the name, and post a new patch? Should only take a little while.


EOS-M3_120f / SX50_100b / SX260_101a / G1X_100g / D20_100b
https://www.youtube.com/user/DrLapser/videos

Re: hide_osd() script function
« Reply #29 on: 29 / September / 2013, 17:25:53 »
You really don't need get_chdk_osd(). The script knows it always starts out at 1, and only changes when the script sets it to something different.
That can complicate things in a big script.

As we seem to have agreement on get_chdk_osd() let's just go with that?   
« Last Edit: 29 / September / 2013, 17:28:19 by waterwingz »
Ported :   A1200    SD940   G10    Powershot N    G16

 

Related Topics


SimplePortal © 2008-2014, SimplePortal