I'm wondering about entering ALT mode within scripts.... - Hello, I'm a NEWBIE - HELP!! (Newbies assistance, User Guides and thank you notes) - CHDK Forum

I'm wondering about entering ALT mode within scripts....

  • 9 Replies
  • 1984 Views
I'm wondering about entering ALT mode within scripts....
« on: 18 / January / 2013, 23:06:36 »
Advertisements
Hello everyone!
I have a Canon SD960IS, which was just ported into CHDK, and I've had a great time with CHDK.
However, how do I enter ALT mode within a script?
On this camera, you enter ALT by pressing the playback button for a short amount of time, and if you hold it, you enter playback mode.
When I enter
Code: [Select]
click "play" within my script though, it does nothing.

Is there a command like
Code: [Select]
exit_alt for entering ALT mode, or do I have to figure out what the name of the button is?

Here is the code of my script (if it helps):
Code: [Select]
@title Long-Exposure Continous Shooting
@param a Number of Shots
@default a 10
@param b Exposure (Seconds)
@default b 10

print "Please be sure that"
print "the shutterspeed"
print "enum type is set"
print "to factor."
print "The script will not"
print "function properly"
print "if this occurs."
sleep 2000
cls
print "Please be sure that"
print "the Shutter Speed"
print "value is set"
print "to 0."
print "The script will not"
print "function properly"
print "if this occurs."
sleep 2000
cls
print "This script will take"
print a, "shots"
print "with a" , b , "second exposure."

set_raw 1
set_raw_nr 1
click "play"
sleep 100
click "menu"
sleep 100
click "set"
sleep 100
for x=1 to 3 step 1
click "down"
sleep 100
next x
for x=1 to 6 step 1
click "right"
sleep 100
next x
click "up"
sleep 100
for x=1 to b step 1
gosub "setEXP"
sleep 100
next x
gosub "shoot"
end

rem This sets the exposure.
:setEXP
click "RIGHT"
return

rem This does the actual shooting.
for x=1 to a step 1
shoot
sleep 1000
next x
return

Should I hit "menu" again to leave the menu before shooting?

When this script runs, it just opens up the default camera menu and a console.
It then does nothing (i.e. no shooting).

Sorry for all the questions!

-bananaman

P.S. I grow lots of banana plants, hence my username. Here is a photo I took with CHDK in RAW of a plant that is currently fruiting, with post-camera white balance and color tweaking in UFRAW to get it to look like it actually does:


*

Offline reyalp

  • ******
  • 12159
Re: I'm wondering about entering ALT mode within scripts....
« Reply #1 on: 18 / January / 2013, 23:38:47 »
Scripts really only run in alt mode. You cannot manipulate the CHDK user interface with scripted key presses though, they always get sent to the original canon firmware.

If you want to set shutter speed from script, you should use one of the set_tv* script functions. Note that the value must be set before each exposure. http://chdk.wikia.com/wiki/CHDK_Scripting_Cross_Reference_Page is a good starting point to find script functions.
Don't forget what the H stands for.

Re: I'm wondering about entering ALT mode within scripts....
« Reply #2 on: 18 / January / 2013, 23:42:01 »
Thanks a ton!

I guess I'll just have to figure out a way to convert the seconds into tv* numbers with the uBASIC math operaters... (which is what I was trying to avoid in the first place by doing button clicks!)
Anyway thanks again!

*

Offline reyalp

  • ******
  • 12159
Re: I'm wondering about entering ALT mode within scripts....
« Reply #3 on: 19 / January / 2013, 00:01:13 »
The tv96 numbers are in APEX http://dougkerr.net/Pumpkin/#APEX multiplied by 96.
Don't forget what the H stands for.


Re: I'm wondering about entering ALT mode within scripts....
« Reply #4 on: 19 / January / 2013, 00:20:13 »
I want to have the user input the time in seconds, rather than tv96 numbers, so the user does not have to know the tv96 number they want for the situation off the top of their head, and this means I must calculate them from the tv96, so I was trying to get a logarithmic function in there to calculate the tv96 numbers from the user input, as I don't have to have a bunch of if else statements because they tend to slow down programs (in general, but I don't know about CHDK scripts), but I just tested to see if I can do LUA's logarithmic functions with a simple script, and apparently I cannot use the standard math.log10 or math.log functions (without writing a custom library)..
I guess I'll just have to do a bunch of if statements to convert user input into tv96...
« Last Edit: 19 / January / 2013, 00:27:33 by bananaman »

*

Offline reyalp

  • ******
  • 12159
Re: I'm wondering about entering ALT mode within scripts....
« Reply #5 on: 19 / January / 2013, 15:46:27 »
In CHDK lua (and ubasic) numbers are integers. If you are using lua and only accept an integer number of seconds, using a table to look up the corresponding tv96 value might be simpler. People have made other ways of approximating this too, if you search the forum you can probably find some lua code to re-use.

In the 1.2 development version, a fixed point integer based library is available, see http://chdk.setepontos.com/index.php?topic=9131.0
Don't forget what the H stands for.

*

Offline lapser

  • *****
  • 1093
Apex 96 conversion function
« Reply #6 on: 20 / January / 2013, 16:10:16 »
I want to have the user input the time in seconds, rather than tv96 numbers
I've written a CHDK conversion function for Lua that converts all the Apex96 exposure values to and from linear values. If the user enters the shutter time in msec, you would convert it like this:

tv=convert96(t,1)

If t is negative, then it will convert it as 1000/t where t is in msec. So for a shutter time of 1/2 second, you could do

tv96=convert96(500,1)
or
tv96=convert96(-2000,1)

Code: [Select]
//in luascript.c
int convert96(int x, int type) //converts for lua integers
{
  switch(type)
  {
    case 1: //shutter speed (msec) to tv96
      if(x==0)break; //shutter speed 0 invalid
      double f=(double)x;
      if(x<0)f = -1000./f; //<0 means 1000/x.  example: -2000 means 1/2 sec shutter speed
      else f  *=  0.001; //500 means 1/2 sec also
      return (int)(318.90509710918*log10(f)+0.5); //96*log2(f)
    case 2: //tv96 to shutter speed(msec)
      return (int)(1000.*pow(2,(((double)-x)*0.010416666666667))+0.5); //2^(-t/96)
      //if tv96<0 you can call with -tv96(positive) and print as ("1/",convert96(-tv,2))

    case 3: //iso to sv96
      return (int)(318.90509710918*log10(0.297301778750680*x)+0.5); // (96/log10(2))*log10(N*ISO)
    case 4: //sv96 to iso
      return (int)(pow(2,(((double)(x+168))*0.010416666666667))); //2^((x+96N)/96) N=2^(-7/4)
   
    case 5: //aperture to av96
      if(x<1)break;
      return (int)(log10(((double)x)*0.001)*637.810194218373+0.5); //log2(x/1000)*96
    case 6: //av96 to aperture
      return (int)(pow(2,((double)x)*0.005208333333333)*1000.+0.5 ); //2^(x/192)*1000
  }
  return 0; //invalid type or input
}

static int luaCB_convert96( lua_State* L )
{
  lua_pushnumber( L, convert96(luaL_checknumber(L,1),
    luaL_checknumber(L,2)));
  return 1;
}

    FUNC(convert96) //static const luaL_Reg chdk_funcs[] = {

Since this has to be compiled as part of CHDK for it to become available to Lua, reyalp or philmoz will have to approve adding it to the CHDK trunk. In the meantime, I can compile you a version of CHDK that includes this function, if you'd like to test it out. Just give me your camera model and firmware version if you're interested.

I also did a Lua only version awhile back for converting tv96 to shutter time, but the convert96 function makes it obsolete for me, plus you're interested in converting time to tv96. The lua function is here.
http://chdk.setepontos.com/index.php?topic=8742.msg91368#msg91368

Here's the description of how to use the convert96 function
==========
Apex Conversion Function
==========
r=convert96(x,type)
  x: input value to convert from or to Apex96
  type: type of conversion
     1: if x>0   shutter time(msec) to Tv96
        if x<0    -1/shutter time(msec)  to TV96
        i.e. x=500 and x=-2000 both mean 1/2 second
     2: Tv96 to shutter time (msec)
     3: iso to Sv96
     4: Sv96 to iso
     5: aperture*1000 to Av96
     6: Av96 to aperture*1000
  Example: Print formatted shutter time from Tv96
    s=""
    if(tv<0)then
      s="1/"
      tv=-tv
    end
    r=convert96(tv,2)
    print(string.format("%s%d.%03d",s,r/1000,r%1000) //fractional time <1 sec
      --or
    r=convert96(tv,2)
    print(string.format("%d.%03d",r/1000,r%1000) //time (seconds)
EOS-M3_120f / SX50_100b / SX260_101a / G1X_100g / D20_100b
https://www.youtube.com/user/DrLapser/videos

Re: I'm wondering about entering ALT mode within scripts....
« Reply #7 on: 20 / January / 2013, 16:26:18 »
Tanks a ton to everyone for your help!
I decided to make an array of the TV96 values, where the index numbers of the array are the exposure time.  I used excel to do the calculations.
Anyway, here is my finished script!

Code: [Select]
--[[
@title Long-Exposure Continuous Shooting
@param a Exposure Time (Seconds)
@default a 10
@param b Number of Shots
@default b 10
]]

--This is an array of TV96 values for exposure tomes 1-60 seconds.
--It is indexed by the exposure time in seconds.
expVAL = {0, -96, -152, -192, -223, -248, -270, -288, -304, -319, -332, -344, -355, -366, -375, -384, -392, -400, -408, 415, -422, -428, -434, -440, -446, -451, -456, -462, -466, -471, -476, -480, -484, -488, -492, -496, -500, -504, -507, -511, -514, -518, -521, -524, -527, -530, -533, -536, -539, -542, -545, -547, -550, -552, -555, -558, -560, -562, -565, -567}

--This is the main part of the script.
for i = 1,b do
print( "Shot", i)
set_tv96_direct( expVAL[a] )
sleep( 100 )
shoot()
sleep( 1000 )
end

I designed it for star trail picture sets and/or other uses of long exposure continuous shooting.
Again, thanks for the help!


*

Offline philmoz

  • *****
  • 3129
    • Photos
Re: I'm wondering about entering ALT mode within scripts....
« Reply #8 on: 20 / January / 2013, 20:42:25 »
Code: [Select]
//in luascript.c
int convert96(int x, int type) //converts for lua integers
{
  switch(type)
  {
    case 1: //shutter speed (msec) to tv96
      if(x==0)break; //shutter speed 0 invalid
      double f=(double)x;
      if(x<0)f = -1000./f; //<0 means 1000/x.  example: -2000 means 1/2 sec shutter speed
      else f  *=  0.001; //500 means 1/2 sec also
      return (int)(318.90509710918*log10(f)+0.5); //96*log2(f)
    case 2: //tv96 to shutter speed(msec)
      return (int)(1000.*pow(2,(((double)-x)*0.010416666666667))+0.5); //2^(-t/96)
      //if tv96<0 you can call with -tv96(positive) and print as ("1/",convert96(-tv,2))

    case 3: //iso to sv96
      return (int)(318.90509710918*log10(0.297301778750680*x)+0.5); // (96/log10(2))*log10(N*ISO)
    case 4: //sv96 to iso
      return (int)(pow(2,(((double)(x+168))*0.010416666666667))); //2^((x+96N)/96) N=2^(-7/4)
   
    case 5: //aperture to av96
      if(x<1)break;
      return (int)(log10(((double)x)*0.001)*637.810194218373+0.5); //log2(x/1000)*96
    case 6: //av96 to aperture
      return (int)(pow(2,((double)x)*0.005208333333333)*1000.+0.5 ); //2^(x/192)*1000
  }
  return 0; //invalid type or input
}

static int luaCB_convert96( lua_State* L )
{
  lua_pushnumber( L, convert96(luaL_checknumber(L,1),
    luaL_checknumber(L,2)));
  return 1;
}

    FUNC(convert96) //static const luaL_Reg chdk_funcs[] = {

Since this has to be compiled as part of CHDK for it to become available to Lua, reyalp or philmoz will have to approve adding it to the CHDK trunk.

I don't have any issues adding this type of functionality to Lua, it's not a huge amount of new code; but I'm not keen on a single function that performs six different things based on a 'type' parameter. Having to go back to the documentation all the time to figure out which 'type' value is needed for a specific conversion is a pain.

If added as Lua functions in the C code then I think 6 suitably named functions would be preferable - e.g. convertShutterSpeedToTV96, etc.

It's probably worth having a separate topic for this.

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)

*

Offline reyalp

  • ******
  • 12159
Don't forget what the H stands for.

 

Related Topics