start of lua libraries - seeking feedback - LUA Scripting - CHDK Forum

start of lua libraries - seeking feedback

  • 1 Replies
  • 3510 Views
start of lua libraries - seeking feedback
« on: 25 / January / 2009, 23:40:29 »
Advertisements
i've put some time into creating functions that i hope will be useful for other chdk scripters. however, i'm new to lua and lack the technical knowledge that others here have therefore i'm posting my code for feedback.



Code: [Select]
--checks directories in DCIM for image files
function getImageList()
log.print("-start- getImageList \n\n")
local imgTable = {}
--get directories that may contain images
local dcimList = os.listdir("A/DCIM", false)
if(dcimList) then
local dirCount = table.getn(dcimList)
log.print("dirCount:"..dirCount.."\n")
table.sort(dcimList)
--loop through directories
local i = 0
while ( dirCount ~= i) do
i = i + 1
--get file list
log.print("A/DCIM/"..dcimList[i].."\n")
local imgDirList = os.listdir("A/DCIM/"..dcimList[i], false)
if(imgDirList) then
local imgCount = table.getn(imgDirList)
log.print("imgCount:"..imgCount)
table.sort(imgDirList)
if(imgCount ~= nil) then
--loop through files, add to list
local a = 0
while (imgCount ~= a) do
a = a + 1
print("A/DCIM/"..dcimList[i].."/"..imgDirList[a])
log.print("A/DCIM/"..dcimList[i].."/"..imgDirList[a])
table.insert(imgTable,"A/DCIM/"..dcimList[i].."/"..imgDirList[a])
end
else
os.remove("A/DCIM/"..dcimList[i])
table.remove(dcimList,i)
end
else
os.remove("A/DCIM/"..dcimList[i])
table.remove(dcimList,itemCount)
end
end
end

log.print("-end- getImageList ")
return imgTable
end

--warning - get_jpg_count doesn't work until a shot is taken.
function deleteUntilJpgFree(min,target)
local jpgCount = get_jpg_count()
log.print("jpgCount:"..jpgCount.."\n")
if (jpgCount <= min) then
local deleteCount = target - jpgCount
log.print("deleteCount:"..deleteCount.."\n")
local imgTable = getImageList()
if (deleteCount > table.getn(imgTable)) then
deleteCount = table.getn(imgTable)
end
log.print("table count:"..table.getn(imgTable))
if(table.getn(imgTable) > 0) then
local i = 0
repeat
i = i + 1
log.print("image to delete:"..imgTable[1])
os.remove(imgTable[1])
table.remove(imgTable,1)
until deleteCount == i
end
end
end

function deleteUntilMbFree(mbMin, mbTarget)
local kbMin = mbMin * 1024
local kbTarget = mbTarget * 1024
if(get_free_disk_space() < kbMin) then
local imgTable = getImageList()
repeat
os.remove(imgTable[1])
table.remove(imgTable,1)
until get_free_disk_space() > kbTarget
end
end

function sleepUntilTime(time)
local secondsFuture = (time.hour * 3600) + (time.minute * 60) + time.second
local secondsNow = os.date("%S")
local minutesNow = os.date("%M")
local hoursNow = os.date("%H")
local secondsNow = (hoursNow * 3600) + (minutesNow * 60) + secondsNow

--if future time is smaller than current time, add 12hrs.
if(secondsNow > secondsFuture) then
secondsFuture = secondsFuture + 43200
end
local secondsDelta = secondsFuture - secondsNow
sleep(secondsDelta * 1000)
end

*

Offline PhyrePhoX

  • *****
  • 2254
  • make RAW not WAR
    • PhyreWorX
Re: start of lua libraries - seeking feedback
« Reply #1 on: 27 / January / 2009, 06:41:42 »
hey, nice stuff. you might want to explain in detail what these do, for people not really well into scripting ;)

 

Related Topics