Wikia

CHDK Wiki

PropertyCaseDump

Talk0
575pages on
this wiki
Revision as of 03:48, September 12, 2010 by 89.245.247.179 (Talk)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

A lua script that:

  • dumps all PropertyCase values out to a file propdump.log
  • compares PropertyCase values against the existing propdump.log file.

Useful to detect which property cases have changed.


You can configure a few variables:

  • Change the range of propcases that is scanned (From propcase and To propcase</code>).
  • Disable outputting of the file (set Do dump? to 0)
  • Dump to a numbered dump file (set Output to dump# to 1 or more (saves to file propdump.### where ### is the number you choose)
  • Compare against a numbered dump (set Compare with dump# to 1 or more (compares against file propdump.### where ### is the number you choose) or -1 to disable comparison output.
  • Do value comparisons in hex (default) or decimal (set As hex? to 0).

The most useful thing you may wish to use in other scripts, is that it shows:

Here is an example of the log file output (which is read in on next script run) for propcases 0 to 10. The file has unneeded whitespace added because I find the extra tabs make the file more readable. Also LUA "arrays" normally have a much cleaner syntax like {itemA, itemB, itemC, itemD}, but I wanted a zero based array and I wanted to easily see the relation between propcase index and the propcase value.

{
[	0]=	0,
[	1]=	0,
[	2]=	0,
[	3]=	0,
[	4]=	0,
[	5]=	1,
[	6]=	0,
[	7]=	0,
[	8]=	1,
[	9]=	0,
[	10]=	0,
ver=1,
from=0,
to=20
}

The script:

--propdump.lua    by Morris Johns
-- dump property cases and compare for differences against last dump (see http://chdk.wikia.com/wiki/PropertyCase)
--[[ 
@title propdump
@param f From propcase
@default f 0 
@param t To propcase
@default t 279
@param d Do dump?
@default d 1
@param h As hex?
@default h 1
@param i Compare with dump#
@default i 0
@param o Output to dump#
@default o 0
]] 


-- setup
_from = f
_to = t
_dodump = d
_ashex = h
if i >= 0 then
	_compare = true
end
if i == 0 then
	i = "log"
end
_infilename = "A/propdump." .. i
if o == 0 then
	o = "log"
end
_outfilename = "A/propdump." .. o


function logwrite(...)
	if _dodump and not outfile then
		outfile=io.open(_outfilename, "w+b")
	end
	if outfile then
		outfile:write(...)
	end
end


function waitshutter()
	print("press half-shutter")
	repeat
		wait_click(100)
	until not is_pressed("shoot_half")
	repeat
		wait_click(100)
	until is_pressed("shoot_half")
end


-- load previous data
if _compare then
	infile = io.open(_infilename, "rb")
	if infile then
		fn = loadstring("data=" .. infile:read("*a"))
		if fn then
			fn()
		end
		infile:close()
	end
	if not data then
		print("no existing data")
	end
end

-- loop through propcases
diffs = {}
logwrite("{\n")
for i = _from,_to do
	v = get_prop(i)
	logwrite("[", i, "]=\t", v, ",\n")
	if data and data.ver == 1 and data.from <= i and i <= data.to then
		-- do comparison
		if data[i] ~= v then
			if _ashex then
				num1 = string.sub(string.format('%04X', data[i]), -4)
				num2 = string.sub(string.format('%04X', v), -4)
			else
				num1 = data[i]
				num2 = v
			end
			table.insert(diffs, "[" .. i .. "] " .. num1 .. " -> " .. num2)
		end
	end
end
logwrite("ver=1,\n")
logwrite("from=", f, ",\n")
logwrite("to=", t, ",\n")
diffs_were = unpack(diffs)
if _compare and diffs_were then 
	logwrite("diffs_were=", string.format("%q", diffs_were), ",\n")
end
logwrite("}\n")
if outfile then
	outfile:close()
end

-- tell user the differences
if _compare then
	for i,diff in ipairs(diffs) do
		print(diff)
		if i % 4 == 0 and diffs[i+1] then
			waitshutter()
		end
	end
	if get_mode() == 1 then
		-- in play mode, screen cleared without this
		waitshutter()
	end
end

Around Wikia's network

Random Wiki