A better(?) way to control display off - page 2 - General Discussion and Assistance - CHDK Forum supplierdeeply

A better(?) way to control display off

  • 81 Replies
  • 39052 Views
*

Offline lapser

  • *****
  • 1093
Re: A better(?) way to control display off
« Reply #10 on: 15 / August / 2013, 16:26:43 »
Advertisements
First let me say that this is a great idea. I set up the SX260 while watching the meteor shower, and the backlight flashing was unacceptable. Leaving the backlight on was also too bright, so I ended up setting the camera pointing straight up so I wouldn't see all the light. Anyway, here's my two cents:

1. I don't see any need for a new Lua function. Just modify set_backight in C so it tries to use call_event_proc first, and if that fails, it uses the current function (with backlight fix).

2. You should turn the backlight on when the script terminates, or when the script encounters an error. I already have this in my backlight fix. If there's a timing problem, just save the tick_count when you turn the backlight off, and make sure a minimum time has passed before turning it back on.

3.  The changes should be done in the C code, and not require script changes. It will simply make set_backlight(0) work correctly now. It's probably best to do it for Lua and then repeat the code in uBasic since they're modules that don't run at the same time.

I should have some time to try it out by this weekend. I'm still processing all the meteor shower pictures I got on Tuesday night. I can probably write the luascript.c code changes if no one else gets to it in the next few days. Can someone show me how to do the call_event_proc code in C?

Thanks again reyalp (and others) for figuring this out.
« Last Edit: 15 / August / 2013, 16:29:05 by lapser »
EOS-M3_120f / SX50_100b / SX260_101a / G1X_100g / D20_100b
https://www.youtube.com/user/DrLapser/videos

*

Offline reyalp

  • ******
  • 14082
Re: A better(?) way to control display off
« Reply #11 on: 15 / August / 2013, 16:55:00 »
1. I don't see any need for a new Lua function. Just modify set_backight in C so it tries to use call_event_proc first, and if that fails, it uses the current function (with backlight fix).
Turning of the display is not the same thing as turning off the backlight, I don't think we should combine them. In general, we don't use call_event_proc from C code, because it requires registering a whole set of eventprocs that take up memory (most are only a trivial amount, but some are not) and could have other side effects. The display on/off function would be added to the stubs.

If we were going to try to fix set_backlight, it would be better to use LcdCon_SetLcdBackLightBrightness(0), since it really does change the backlight, and keeps it off through shooting. The only problem is that it's not clear how to get back to the previous setting. LcdCon_GetLcdBackLightParameter might be it, but there's a separate "set" function for that.
Quote
2. You should turn the backlight on when the script terminates, or when the script encounters an error. I already have this in my backlight fix. If there's a timing problem, just save the tick_count when you turn the backlight off, and make sure a minimum time has passed before turning it back on.
This isn't always desirable. For example, if you are executing script code over ptp, you want to be able to turn the display off and have it stay off, not turn right back on when the call ends. In some applications, turning the display on for errors would also be undesirable. I'm not sure what the best way to handle this is. Theoretically, scripts that want to restore camera state should use restore() but it's not very reliable, and puts the onus on script writers to figure out keep track of what they need to restore.
Don't forget what the H stands for.

*

Offline lapser

  • *****
  • 1093
Re: A better(?) way to control display off
« Reply #12 on: 15 / August / 2013, 17:43:16 »
Turning of the display is not the same thing as turning off the backlight, I don't think we should combine them.

If we were going to try to fix set_backlight, it would be better to use LcdCon_SetLcdBackLightBrightness(0)
I agree it's not the same, but it seems like turning off the display the way you discovered, is the desired effect of set_backlight(0). The advantage of modifying the current set_backlight function is that scripts wouldn't have to be changed. Visibly, I don't think they're any different, are they? As a script writer, I don't care how you do it. Just turn the damned light off already!

Quote
This isn't always desirable. For example, if you are executing script code over ptp, you want to be able to turn the display off and have it stay off, not turn right back on when the call ends. In some applications, turning the display on for errors would also be undesirable. I'm not sure what the best way to handle this is. Theoretically, scripts that want to restore camera state should use restore() but it's not very reliable, and puts the onus on script writers to figure out keep track of what they need to restore.
How about set_backlight(-1) to turn the backlight(display) off and leave it off?
EOS-M3_120f / SX50_100b / SX260_101a / G1X_100g / D20_100b
https://www.youtube.com/user/DrLapser/videos

Re: A better(?) way to control display off
« Reply #13 on: 15 / August / 2013, 19:44:26 »
I should have some time to try it out by this weekend.
If your actually do have a little time,  taking an hour to document the function calls in shot_histogram would be really helpful ...
Ported :   A1200    SD940   G10    Powershot N    G16


*

Offline lapser

  • *****
  • 1093
Re: A better(?) way to control display off
« Reply #14 on: 24 / August / 2013, 21:24:57 »
I was able to get reyalp's better backlight off code to work with my time lapse script. Reyalp, you're the greatest! (well, at least until our next disagreement  :)

To make it easier to use, and work with older cameras (hopefully), I added this Lua function:

Code: [Select]
blight=1 -- backlight on / current state
bldisp=true -- turn off display with eventproc if true
if call_event_proc('DispDev_EnableEventProc') == -1 then
  if call_event_proc('DispDev.Create') == -1 then
    bldisp=false -- must turn off display with set_backlight
  end
end
function backlight(bl) -- bl=0 off, 1 on, -1 toggle
  if(bl<0)then bl=bitxor(blight,1)  -- toggles 0 or 1
  elseif (bl>1)then bl=1 end
  if(bl==blight)then return end -- don't double set to current state
  blight=bl
  if(bldisp)then
    if(bl==0)then call_event_proc('DispCon_TurnOffDisplay')
    else call_event_proc('DispCon_TurnOnDisplay') end
  else
    set_backlight(bl) -- do the old way if no event_proc available
  end
end

function restore()
  backlight(1)
--etc
end

--then in my time lapse loop:
repeat
    wait_click(10)
    if(is_key("set"))then
      backlight(-1) --toggle
    elseif
      --etc.
    end
until get_shot_ready() --wait for shot
It keeps the display completely dark in continuous or single shot mode, which is exactly what I wanted.

As mentioned above, it might be nice to incorporate reyalp's method into the set_backlight(int b) function in C. If someone can make DispCon_TurnOffDisplay and DispCon_TurnOnDisplay available (sig finder?), I can the write the C function for others to review and modify as needed.

Also, I seem to recall a menu option to enable native calls, but I can't find it now. Maybe I'm enabling them with a compile option? Will this Lua function method work on unmodified CHDK?
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: A better(?) way to control display off
« Reply #15 on: 25 / August / 2013, 05:46:59 »
Also, I seem to recall a menu option to enable native calls, but I can't find it now. Maybe I'm enabling them with a compile option? Will this Lua function method work on unmodified CHDK?
Miscellaneous Stuff => Enable Lua Native Calls'  http://chdk.wikia.com/wiki/CHDK_1.2.0_User_Manual#Enable_Lua_Native_Calls.27
(Thanks to waterwingz, the manual is on the latest standing.)

There is also a script solution:
Code: (lua) [Select]
--CHDK version 1.3
--set_config_value(999, 1)
core = require("gen/cnf_core")
set_config_value(core.script_allow_lua_native_calls, 1)

--CHDK version 1.2
--set_config_value(119, 1)
msl
CHDK-DE:  CHDK-DE links

*

Offline philmoz

  • *****
  • 3450
    • Photos
Re: A better(?) way to control display off
« Reply #16 on: 25 / August / 2013, 06:02:54 »
Also, I seem to recall a menu option to enable native calls, but I can't find it now. Maybe I'm enabling them with a compile option? Will this Lua function method work on unmodified CHDK?
Miscellaneous Stuff => Enable Lua Native Calls'  http://chdk.wikia.com/wiki/CHDK_1.2.0_User_Manual#Enable_Lua_Native_Calls.27
(Thanks to waterwingz, the manual is on the latest standing.)

There is also a script solution:
Code: (lua) [Select]
--CHDK version 1.3
--set_config_value(999, 1)
core = require("gen/cnf_core")
set_config_value(core.script_allow_lua_native_calls, 1)

--CHDK version 1.2
--set_config_value(119, 1)
msl

The 'set_config_value' function doesn't allow a script to enable native calls.
The 'script_allow_lua_native_calls' entry should not be included in cnf_core.lua.

Phil.
CHDK ports:
  sx30is (1.00c, 1.00h, 1.00l, 1.00n & 1.00p)
  g12 (1.00c, 1.00e, 1.00f & 1.00g)
  sx130is (1.01d & 1.01f)
  ixus310hs (1.00a & 1.01a)
  sx40hs (1.00d, 1.00g & 1.00i)
  g1x (1.00e, 1.00f & 1.00g)
  g5x (1.00c, 1.01a, 1.01b)
  g7x2 (1.01a, 1.01b, 1.10b)

*

Offline msl

  • *****
  • 1280
  • A720 IS, SX220 HS 1.01a
    • CHDK-DE links
Re: A better(?) way to control display off
« Reply #17 on: 25 / August / 2013, 06:41:39 »
The 'set_config_value' function doesn't allow a script to enable native calls.
The 'script_allow_lua_native_calls' entry should not be included in cnf_core.lua.
:(

Why not?

It's a pain to test scripts without this. When I use a PTP connection for script test (e.g. hostlua) it is difficult everytime to activate 'native calls' via CHDK menu. I think a CHDK script author should have the responsibility and not CHDK in such cases.

msl
CHDK-DE:  CHDK-DE links


*

Offline philmoz

  • *****
  • 3450
    • Photos
Re: A better(?) way to control display off
« Reply #18 on: 25 / August / 2013, 07:20:39 »
The 'set_config_value' function doesn't allow a script to enable native calls.
The 'script_allow_lua_native_calls' entry should not be included in cnf_core.lua.
:(

Why not?

It's a pain to test scripts without this. When I use a PTP connection for script test (e.g. hostlua) it is difficult everytime to activate 'native calls' via CHDK menu. I think a CHDK script author should have the responsibility and not CHDK in such cases.

msl

To try and limit the damage a malicious script could do.

Phil.
CHDK ports:
  sx30is (1.00c, 1.00h, 1.00l, 1.00n & 1.00p)
  g12 (1.00c, 1.00e, 1.00f & 1.00g)
  sx130is (1.01d & 1.01f)
  ixus310hs (1.00a & 1.01a)
  sx40hs (1.00d, 1.00g & 1.00i)
  g1x (1.00e, 1.00f & 1.00g)
  g5x (1.00c, 1.01a, 1.01b)
  g7x2 (1.01a, 1.01b, 1.10b)

*

Offline msl

  • *****
  • 1280
  • A720 IS, SX220 HS 1.01a
    • CHDK-DE links
Re: A better(?) way to control display off
« Reply #19 on: 25 / August / 2013, 08:07:31 »
To try and limit the damage a malicious script could do.

Related to 'native calls' I know only one incident. That was reyalp's 'small accident' with the factory mode. With CHDK-DE we had this feature activated as default. There were no problems for years.

msl
CHDK-DE:  CHDK-DE links

 

Related Topics