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

hide_osd() script function

  • 98 Replies
  • 34629 Views
*

Offline lapser

  • *****
  • 1093
Re: hide_osd() script function
« Reply #30 on: 29 / September / 2013, 17:35:03 »
Advertisements
As we seem to have agreement on get_chdk_osd() let's just go with that?   
OK, I guess it would make toggling simpler too. I'll add get_chdk_osd() and post something soon. Also, I'll use if/else like this, if that's better:
Code: [Select]
//1 show osd, 0 hide osd
static int luaCB_set_chdk_osd( lua_State* L )
{
  if(luaL_checknumber(L,1)==0) camera_info.state.osd_off=1;
  else camera_info.state.osd_off=0;
  return 0;
}

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

Re: hide_osd() script function
« Reply #31 on: 29 / September / 2013, 17:39:25 »
OK, I guess it would make toggling simpler too. I'll add get_chdk_osd() and post something soon. Also, I'll use if/else like this, if that's better:
You could actually use the ternary operator there if it suits your fancy.  Never been a big fan but for short lines it seems to work for people.
Ported :   A1200    SD940   G10    Powershot N    G16

*

Offline lapser

  • *****
  • 1093
Re: hide_osd() script function
« Reply #32 on: 29 / September / 2013, 18:13:28 »
Lua, it would be
set_osd_state( not get_chdk_osd() )
My $.02 This is a lot clearer than set_osd_state(-1)

OK, I got the Lua version working, but this method of toggling would require using boolean parameters and return values. With ( 0 | 1) you have to toggle with:
Code: [Select]

set_chdk_osd(bitxor(get_chdk_osd(),1))
Switching to boolean would be inconsistent with the ubasic version. Is everyone OK with the bitxor toggle method?

You could actually use the ternary operator there if it suits your fancy.  Never been a big fan but for short lines it seems to work for people.
Thanks for the idea. It sounds like it would be good to use it here. I agree that it gets hard to read in the middle of long expressions.
EOS-M3_120f / SX50_100b / SX260_101a / G1X_100g / D20_100b
https://www.youtube.com/user/DrLapser/videos

*

Offline reyalp

  • ******
  • 14126
Re: hide_osd() script function
« Reply #33 on: 29 / September / 2013, 18:25:43 »
There's nothing wrong with having Lua use booleans and ubasic use 0/1.

In luascript.c on_off_value_from_lua_arg accepts both 0/1 or boolean values
Don't forget what the H stands for.

*

Offline lapser

  • *****
  • 1093
Re: hide_osd() script function
« Reply #34 on: 29 / September / 2013, 20:07:22 »
There's nothing wrong with having Lua use booleans and ubasic use 0/1.

In luascript.c on_off_value_from_lua_arg accepts both 0/1 or boolean values
Thanks, I just figured that out while working on the code. It allows set_chdk_osd( true|1 false|0 ) fine. The problem is that
(not get_chdk_osd()) always returns false. To toggle, you have to do this:
Code: [Select]
  set_chdk_osd(not (get_chdk_osd()==1))
Can you think of any other way to do it? Want to have get_chdk_osd() return a boolean? That would solve the problem. I think that would be the best way to do it in Lua, i.e. boolean input and output.

ubasic works with just "not" for toggling:
Code: [Select]

if is_key "set" then set_chdk_osd not get_chdk_osd


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

Re: hide_osd() script function
« Reply #35 on: 29 / September / 2013, 20:14:09 »
Want to have get_chdk_osd() return a boolean? That would solve the problem. I think that would be the best way to do it in Lua, i.e. boolean input and output.
Yes.
Ported :   A1200    SD940   G10    Powershot N    G16

*

Offline lapser

  • *****
  • 1093
Re: hide_osd() script function
« Reply #36 on: 29 / September / 2013, 20:24:06 »
Want to have get_chdk_osd() return a boolean? That would solve the problem. I think that would be the best way to do it in Lua, i.e. boolean input and output.
Yes.
I agree, and it works great that way now. Do you think we should still allow optional numeric ( 0 | 1)  input, or just go boolean all the way?
EOS-M3_120f / SX50_100b / SX260_101a / G1X_100g / D20_100b
https://www.youtube.com/user/DrLapser/videos

Re: hide_osd() script function
« Reply #37 on: 29 / September / 2013, 20:26:36 »
I agree, and it works great that way now. Do you think we should still allow optional numeric ( 0 | 1)  input, or just go boolean all the way?
-->
In luascript.c on_off_value_from_lua_arg accepts both 0/1 or boolean values

Doesn't that cover it?
Ported :   A1200    SD940   G10    Powershot N    G16

*

Offline lapser

  • *****
  • 1093
Re: hide_osd() script function
« Reply #38 on: 29 / September / 2013, 20:28:51 »
Doesn't that cover it?
Yes, that's the way it's implemented now. I'll just leave it in, and people can enter either boolean or numbers.
EOS-M3_120f / SX50_100b / SX260_101a / G1X_100g / D20_100b
https://www.youtube.com/user/DrLapser/videos

*

Offline lapser

  • *****
  • 1093
Re: hide_osd() script function
« Reply #39 on: 29 / September / 2013, 21:06:42 »
Here's the (hopefully) final patch (attached). I'm really happy with it. Thanks everyone, for all the suggestions.

Lua test script:
Code: [Select]
--[[
@title OSD Off 2 Lua
--]]
print("get_chdk_osd=",get_chdk_osd())
print("Hiding OSD for 3 seconds")
sleep(3000)
set_chdk_osd(false)
print("Press <SET> to toggle OSD")
print("Press <DISPLAY> for error")
print("Press <MENU> to exit")
sleep(3000)
print("get_chdk_osd=",get_chdk_osd())
set_chdk_osd(1) -- restores console, including data written while hidden
n=0
repeat wait_click()
  if(is_key("display") or is_key("video"))then force_error() end -- call nil function
  set_chdk_osd(not get_chdk_osd()) -- new way to toggle
  n=n+1
  print(n,get_chdk_osd())
until is_key("menu")

ubasic test script:
Code: [Select]
@title OSD_Off 2 ubasic
print "Hiding OSD for 3 seconds"
sleep 2000
set_chdk_osd 0
print "get_chdk_osd=",get_chdk_osd
print "Press <SET> to toggle OSD"
print "Press <DISPLAY> for error"
print "Press <MENU> to exit"
sleep 3000
set_chdk_osd 1
print "get_chdk_osd=",get_chdk_osd
n=0
do
  wait_click
  if is_key "display" or is_key "video" then force_error
  if is_key "set" then set_chdk_osd not get_chdk_osd
  n=n+1
  print n
until is_key "menu"
EOS-M3_120f / SX50_100b / SX260_101a / G1X_100g / D20_100b
https://www.youtube.com/user/DrLapser/videos

 

Related Topics


SimplePortal © 2008-2014, SimplePortal