Request for an Lua conversion for "MD_Lightening6" - Script Writing - CHDK Forum

Request for an Lua conversion for "MD_Lightening6"

  • 4 Replies
  • 5405 Views
Request for an Lua conversion for "MD_Lightening6"
« on: 11 / May / 2008, 19:55:07 »
Advertisements
Hey Folks,

I'm running Jucifer's "evil" script in which scripts must be in Lua to be compatible.

Here's the script, and I'm wondering if someone could please convert this:
Quote
@title MD Lightning6
@param a Columns
@default a 6
@param b Rows
@default b 4
@param c Threshold (0-255)
@default c 10
@param d Compare Interval (millisecs)
@default d 1
@param e Trigger Delay (0.1 secs)
@default e 12
@param f Rows to Exclude
@default f 0
@param g Pix-Step(speed/accuracy adj)
@default g 8
@param h Reg Mode(0-no,1-incl,2-excl)
@default h 0
@param i Measure Mode(1-Y,0-U,2-V)
@default i 1
if a<1 then a=1
if b<1 then b=1
if c<0 then c=0
if g<1 then g=1
if f<1 then f=1
e=e*100
print ">[";a;",";b;"] threshold: ";c
x=30000
:md
press "shoot_half"
t=0
do
md_detect_motion a, b, i, x, d, c, 1, t, h, 1, 1, a, f, 0, g, e
until t>0
click "shoot_full"
goto "md"

Thanks!
Whoa-Hey! Careful where you point that thing. You're gonna shoot someone!

http://chdk.wikia.com/wiki/DoF_Stacking

*

Offline Jucifer

  • *****
  • 251
  • [A710IS]
Re: Request for an Lua conversion for "MD_Lightening6"
« Reply #1 on: 11 / May / 2008, 23:58:18 »
This should run as-is, there's no commands starting with get_ using the "old" syntax.

(tried, runs)

uBASIC support wasn't dropped, only the syntax of a couple of commands was "updated". ;)

As for Lua version, it could be something like this:

Code: [Select]
--[[@title MD Lightning6
@param a Columns
@default a 6
@param b Rows
@default b 4
@param c Threshold (0-255)
@default c 10
@param d Compare Interval (millisecs)
@default d 1
@param e Trigger Delay (0.1 secs)
@default e 12
@param f Rows to Exclude
@default f 0
@param g Pix-Step(speed/accuracy adj)
@default g 8
@param h Reg Mode(0-no,1-incl,2-excl)
@default h 0
@param i Measure Mode(1-Y,0-U,2-V)
@default i 1
]]
if a<1 then a=1 end
if b<1 then b=1 end
if c<0 then c=0 end
if g<1 then g=1 end
if f<1 then f=1 end
e=e*100
print(">["..a..","..b.."] threshold: "..c)
x=30000
repeat
sleep(0)
press("shoot_half")
t=0
repeat
sleep(0)
md_detect_motion(a, b, i, x, d, c, 1, t, h, 1, 1, a, f, 0, g, e)
until t>0
click("shoot_full")
until 1<0

...but md_detect_motion isn't implemented in Lua yet.

*

Offline Velo

  • *
  • 30
Re: Request for an Lua conversion for "MD_Lightening6"
« Reply #2 on: 12 / May / 2008, 03:35:31 »
Hope you don't mind my comments.

As for Lua version, it could be something like this:
Code: [Select]
...
repeat
sleep(0)
press("shoot_half")
t=0
repeat
sleep(0)
md_detect_motion(a, b, i, x, d, c, 1, t, h, 1, 1, a, f, 0, g, e)
until t>0
click("shoot_full")
until 1<0
...but md_detect_motion isn't implemented in Lua yet.

You don't need a dummy sleep in loops anymore. With patch #3 this was fixed. If it doesn't work for you, let me know.
I prefer 'while true do ... end' as an endless loop. But 'repeat ... until false' will do the same.

As I understand it, you have changed all uBasic commands to work like 'val = func x y z'?
Have you done the same thing with md_detect_motion? If so I could reuse this code in binding md_detect_motion to Lua.


*

Offline Jucifer

  • *****
  • 251
  • [A710IS]
Re: Request for an Lua conversion for "MD_Lightening6"
« Reply #3 on: 12 / May / 2008, 10:19:00 »
This is going off topic fast... :D

You don't need a dummy sleep in loops anymore.
Ok. Good. :]

Quote
As I understand it, you have changed all uBasic commands to work like 'val = func x y z'?
The ones starting with get_. I don't know, if I can go back any more... :]

Quote
Have you done the same thing with md_detect_motion? If so I could reuse this code in binding md_detect_motion to Lua.
I haven't. I was thinking of a possible solution for using md_detect_motion in Lua. Could it be possible (or would it be possibly easiest) to modify the motion detection code so that it would return the number of detected cells?
i.e. for uBASIC
md_detect_motion(a, b, i, x, d, c, 1, t, h, 1, 1, a, f, 0, g, e)
would become
t=md_detect_motion(a, b, i, x, d, c, 1, h, 1, 1, a, f, 0, g, e)
(even
do
until md_detect_motion(a, b, i, x, d, c, 1, h, 1, 1, a, f, 0, g, e)>0
)
and perhaps it would be easier to bind to Lua.
I may or may not succeed in modifying the code. :]

Re: Request for an Lua conversion for "MD_Lightening6"
« Reply #4 on: 13 / May / 2008, 06:48:21 »
If you go through the trouble, perhaps you should use fudgey's latest, bestest MD script.
It's located here:
Fast MD with burst/preview mode
Whoa-Hey! Careful where you point that thing. You're gonna shoot someone!

http://chdk.wikia.com/wiki/DoF_Stacking

 

Related Topics


SimplePortal © 2008-2014, SimplePortal