String lib! - LUA Scripting - CHDK Forum

String lib!

  • 17 Replies
  • 5880 Views
String lib!
« on: 30 / November / 2008, 04:43:49 »
Advertisements
I just saw that reyalp has added the string lib support! This is a truly wonderful news!  :D
Thanks reyalp!

Re: String lib!
« Reply #1 on: 30 / November / 2008, 22:02:17 »
unfortunately the new string support seems to be crashing my a570is. if i remove the string.sub call then this runs indefinitely. with that call, it runs for a couple of minutes.

i'm posting all my code so you can tell if i've messed up anything else. i'd like to make a better error case but i need to continue work on my own project first.

Code: [Select]
--[[
@title Interval shooting
--]]

--customDir = "000Time"
customDir = "100CANON"

-- function definitions

function getCurrentDir ()
local dir = os.listdir("A/DCIM", false)
if(dir) then
local count = table.getn(dir)
print("getCurrentDir: "..dir[count])
return "A/DCIM/"..dir[count]
else
print("getCurrentDir:B")
return nil
end
end


repeat

minute = os.date("%M")
minuteDigit = string.sub(minute,-1)
print(minuteDigit)
if ((minuteDigit == "5") or (minuteDigit == "0")  ) then
if minute ~= lastMinute then
shoot()
print(minute)
lastMinute = minute
end
end


until false

Re: String lib!
« Reply #2 on: 30 / November / 2008, 22:04:39 »
oh, also, the result of the code - camera seems to crash. power off? unresponsive.

*

Offline reyalp

  • ******
  • 12106
Re: String lib!
« Reply #3 on: 30 / November / 2008, 23:50:35 »
Just a general comment, I'd try to use sleep rather than a busy loop like that.

The most likely causes I can think of for what you describe are either starving other tasks on the camera of CPU, or running out of memory.
Don't forget what the H stands for.


Re: String lib!
« Reply #4 on: 30 / November / 2008, 23:58:52 »
is shoot() a blocking function?

i want to take a pic every five minutes, 1:00, 1:05, 1:10, etc. however, the length of the exposure varies, the time required to execute code varies etc. therefore running this loop is the easiest way to trigger shoot() when the time changes. that said, i'm happy to find a way to use sleep. perhaps i can get the time after shoot() has completed and calc how long i should sleep().

*

Offline reyalp

  • ******
  • 12106
Re: String lib!
« Reply #5 on: 01 / December / 2008, 00:49:22 »
as far as I can tell, shoot() should block until shooting is finished, however it's not entirely clear whether that actually means all shooting related tasks have finished everything they need to do.

Note that if it's a cpu starvation issue, just sleeping for the minimum time (10 ms) every iteration would probably take care of it. Depending on your requirements, you could up that to a second or more without changing much.

For calculating how long to sleep (and a good intervalometer example), you might want to look at Night-time time-lapse

FWIW, I've reproduced your camera shutdown behavior.

edit:
Adding the equivalent of sleep(1) at the end of the loop appears to solve the problem. My test script is attached.
« Last Edit: 01 / December / 2008, 01:29:55 by reyalp »
Don't forget what the H stands for.

*

Offline fudgey

  • *****
  • 1705
  • a570is
Re: String lib!
« Reply #6 on: 01 / December / 2008, 12:47:37 »
as far as I can tell, shoot() should block until shooting is finished, however it's not entirely clear whether that actually means all shooting related tasks have finished everything they need to do.

In my webcam thingie from yesterday (http://chdk.setepontos.com/index.php/topic,2696.0.html) it seemed to me that post shoot() USB transmission started before the aperture was reset after shoot(), before jpeg file was written, and certainly before the aperture/display/sensor sounded their usual rec->play mode clicking sounds...

Re: String lib!
« Reply #7 on: 01 / December / 2008, 13:04:10 »
I can shoot() and then rename the file and eye-fi will download the renamed file. i couldn't get the file created/modified date though.

can you summarize your goals and progress on using PTP? I got into chdk because newer digital cameras lack capture via PTP.


*

Offline fudgey

  • *****
  • 1705
  • a570is
Re: String lib!
« Reply #8 on: 01 / December / 2008, 13:47:43 »
can you summarize your goals and progress on using PTP? I got into chdk because newer digital cameras lack capture via PTP.

Progress is pretty much what's in the link above. I don't have goals, really. Just wanted to make that sort of thing possible without eye-fi. Things to do are to try ewavr's way of enabling PTP in REC mode and see if we can do PTP transmissions smoothly without ever going to PLAY mode, and if that doesn't work, to try if the keyboard REC/PLAY switching is friendlier than my current implementation.

It would be even greater to be able to communicate both ways even if it's just via dummy files uploaded from the PC (which I can't seem to get to work, CHDK or not).

PTP download is probably a more friendly way of deleting JPEGs compared to Eye-Fi in terms of screwing up with PLAY mode previews and all that. But I haven't tested that either.

Re: String lib!
« Reply #9 on: 01 / December / 2008, 14:01:57 »
ah, see, you're working at a lower level than i have so i don't really understand the world you're operating in.

i'm not sure it ever occurred to me to use PTP for transfer only. I was greatly annoyed to see that Canon removed PTP capture from newer cameras.

My success with the eye-fi card has only been limited by the abilities of the card itself. The card will stop transferring after a while but i'm not sure if its due to time or number of files. I've attached an arduino to the power button to restart the camera when the card stop transferring - which is somewhat necessary even if the card works perfectly if you don't have easy physical access to the camera.

 

Related Topics