My first CHDK script... does it look good?

  • 7 Replies
  • 1818 Views
My first CHDK script... does it look good?
« on: 22 / June / 2012, 13:22:59 »
Advertisements
I just wanted to run some tests with my camera's battery in relation to temperature, so I made this little Lua script.  This is my first script that I have made for CHDK, so hopefully it works!  I will be testing it soon, but if anyone can see an error could they please let me know?

--Test 1
--[[
rem Test1 by mrShrimp
@title batterytest1
@param m free memory percentage
@default m 1
@param i shoot interval
@default i 3000
@param b battery dead
@default b false
@param n shot number
@default n 0
]]

freemem, interval, deadbatt, shotnumber = m, i, b, n
--Jump right into it!

x = get_meminfo()
original = x[11]
print("we got this far")
while deadbatt == false do
   table1 = get_meminfo()
   if table1 ~= nil then
      freemem = (table1[11]/original) --NewMem/StartingMem, default of 1
      print(freemem)
   else
      print("err1:notable")
   end
   sleep(3000)
   --Take the shot
   press("shoot_half")
   repeat
      sleep(50)
    until get_shooting() == true
   click("shoot_full")
   release("shoot_half")
   shotnumber = shotnumber+1
   print("Shots taken: " .. shotnumber)
   --For initial testing purposes
   if shotnumber == 20 then
      deadbatt = true
      print("Script End")
   end
end


Also, this is my first time on the forums so I just realized that there might be rules about no script posting.  Sorry if that's the case 0_0
« Last Edit: 22 / June / 2012, 13:54:48 by mrShrimp »

Re: My first CHDK script... does it look good?
« Reply #1 on: 22 / June / 2012, 13:27:38 »
Edit: I have found a lot of errors in the past 10 minutes, and I realize I probably should have waited a bit to ask for help.  Anyways, the above post is the revised script as of now.
« Last Edit: 22 / June / 2012, 13:54:24 by mrShrimp »

Re: My first CHDK script... does it look good?
« Reply #2 on: 22 / June / 2012, 13:28:33 »

Also, this is my first time on the forums so I just realized that there might be rules about no script posting.  Sorry if that's the case 0_0
Script posting is encouraged but its nicer if you post using the formatting provide by the "#" button on the edit tool bar so that your script is inserted something like this :

Code: [Select]
--Test 1
--[[
rem 20080815 test script by xxx
@title batterytest1
@param m free memory percentage
@default a 1
@param i shoot interval
@default b 3000
@param b battery dead
@default h false
@param n shot number
@default n 0
]]

freemem, interval, deadbatt shotnumber = m, i, b, n
--Jump right into it!

while deadbatt == false do
   table1 = get_meminfo()
   if table1 ~= nil then
      freemem = (table1[11]/table1[11]) --NewMem/StartingMem, default of 1
      print(freemem)
   else
      print("err1:notable")
   end
   sleep(3000)
   --Take the shot
   press("shoot_half")
   repeat
      sleep(50)
    until get_shooting() == true
   click("shoot_full")
   release("shoot_half")
   shotnumber = shotnumber+1
   print("Shots taken: " .. shotnumber)
   --For initial testing purposes
   if shotnumber == 20 then
      deadbatt = true
      print("Script End")
   end
end
Ported :   A1200    SD940   G10    Powershot N    G16

Re: My first CHDK script... does it look good?
« Reply #3 on: 22 / June / 2012, 14:11:28 »
Ok, thanks!  I'm just getting the hang of this, and I was wondering how I specify the heapname for function get_meminfo, and is the free_size value a numeric value?

Latest Code:
Code: [Select]
--Test 1
--[[
rem Test1 by mrShrimp
@title batterytest1
@param m free memory percentage
@default m 1
@param i shoot interval
@default i 3000
@param b battery dead
@default b 0
@param n shot number
@default n 0
]]

freemem, interval, deadbatt, shotnumber = m, i, b, n
--Jump right into it!

x = get_meminfo()
original = x[11]
print("we got this far")
while deadbatt == 0 do
table1 = get_meminfo()
if table1 ~= nil then
freemem = (table1[11]/original) --NewMem/StartingMem, default of 1
print(freemem)
else
print("err1:notable")
end
sleep(3000)
--Take the shot
press("shoot_half")
repeat
sleep(50)
    until get_shooting() == true
click("shoot_full")
release("shoot_half")
shotnumber = shotnumber+1
print("Shots taken: " .. shotnumber)
--For initial testing purposes
if shotnumber == 20 then
deadbatt = 1
print("Script End")
end
end


Re: My first CHDK script... does it look good?
« Reply #4 on: 22 / June / 2012, 15:14:22 »
Eh, sorry for bothering you all.  After a bit of research, I found an alternative way to accomplish what I wanted to do.  Thanks waterwingz for your help!

Re: My first CHDK script... does it look good?
« Reply #5 on: 23 / June / 2012, 03:33:33 »
--[[
rem Test1 by mrShrimp
@title batterytest1
@param m free memory percentage
@default m 1
@param i shoot interval
@default i 3000
@param b battery dead
@default b false
@param n shot number
@default n 0
]]

You can not use 'false' in params - there are only integer values possible. Nevertheless in the so-called unstable trunk you can have more possibilities: Nevertheless, you can use special keywords to have more possibilities:

you can use @range keyword to set the allowed range for parameter. Example:

Code: [Select]
@param x
@default x 4
@range x 1 10

above code allows user to set the number from 1 to 10.

If range is set to 0-1 then in menu a boolean-like value is showed:


Code: [Select]
@param c foobar
@default c 0
@range c 0 1

What user will see in menu:

Code: [Select]
foobar       [false]


You can also use the @values keyword for setting the list of settings. Example:



Code: [Select]
@param f author
@default f 2
@range f alva bethe gamov


user will see:

Code: [Select]
author     [  bethe ]


The (integer) value of the f param depends on the user select. f=1 if alva is selected, 2 if bethe and so on.
« Last Edit: 23 / June / 2012, 04:00:50 by outslider »
if (2*b || !2*b) {
    cout<<question
}

Compile error: poor Yorick

*

Offline philmoz

  • *****
  • 3070
    • Photos
Re: My first CHDK script... does it look good?
« Reply #6 on: 23 / June / 2012, 03:54:24 »
Nevertheless in the so-called unstable trunk you can have more possibilities:

you can use @range keyword to set the allowed range for parameter. Example:...

You can also use the @values keyword for setting the list of settings. Example:...

@range and @values are also available in the release-1.0 'stable' branch so that scripts remain compatible between versions.

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)

Re: My first CHDK script... does it look good?
« Reply #7 on: 23 / June / 2012, 03:59:53 »
Nevertheless in the so-called unstable trunk you can have more possibilities:

you can use @range keyword to set the allowed range for parameter. Example:...

You can also use the @values keyword for setting the list of settings. Example:...

@range and @values are also available in the release-1.0 'stable' branch so that scripts remain compatible between versions.

Phil.


Good to know;) I haven't notice that or missed.
if (2*b || !2*b) {
    cout<<question
}

Compile error: poor Yorick


 

Related Topics