| 1 | --[[ |
|---|
| 2 | @title set cap mode test |
|---|
| 3 | @param a 0=batch 1=menu 2=single |
|---|
| 4 | @default a 0 |
|---|
| 5 | @param b batch: 0=valid only 1=all |
|---|
| 6 | @default b 0 |
|---|
| 7 | @param c single: 0=by prop 1=by CHDK |
|---|
| 8 | @default c 0 |
|---|
| 9 | @param d single: mode value |
|---|
| 10 | @default d 0 |
|---|
| 11 | @param e mode change delay, ms |
|---|
| 12 | @default e 10 |
|---|
| 13 | --]] |
|---|
| 14 | action=a |
|---|
| 15 | batchtype=b |
|---|
| 16 | singletype=c |
|---|
| 17 | reqmode=d |
|---|
| 18 | |
|---|
| 19 | function mode_change_delay() |
|---|
| 20 | if e ~= 0 then |
|---|
| 21 | sleep(e) |
|---|
| 22 | end |
|---|
| 23 | end |
|---|
| 24 | |
|---|
| 25 | capmode=require("capmode") |
|---|
| 26 | |
|---|
| 27 | function printf(...) |
|---|
| 28 | print(string.format(...)) |
|---|
| 29 | end |
|---|
| 30 | |
|---|
| 31 | function get_rec_str() |
|---|
| 32 | local isrec,isvid=get_mode() |
|---|
| 33 | if isrec then |
|---|
| 34 | if isvid then |
|---|
| 35 | return "VID" |
|---|
| 36 | else |
|---|
| 37 | return "STL" |
|---|
| 38 | end |
|---|
| 39 | else |
|---|
| 40 | return "PLY" |
|---|
| 41 | end |
|---|
| 42 | end |
|---|
| 43 | |
|---|
| 44 | function print_status() |
|---|
| 45 | printf("%s %d %d %s",capmode.get_name(),capmode.get(),capmode.get_canon(),get_rec_str()) |
|---|
| 46 | end |
|---|
| 47 | |
|---|
| 48 | function check_one() |
|---|
| 49 | local methodstr, oldmode, newmode, status, status_str |
|---|
| 50 | -- we continue even if not in rec, to test error handling |
|---|
| 51 | if not get_mode() then |
|---|
| 52 | print("WARNING: not in rec mode") |
|---|
| 53 | end |
|---|
| 54 | print_status() |
|---|
| 55 | if singletype == 0 then |
|---|
| 56 | methodstr="canon" |
|---|
| 57 | oldmode=capmode.get_canon() |
|---|
| 58 | status=set_capture_mode_canon(reqmode) |
|---|
| 59 | newmode=capmode.get_canon() |
|---|
| 60 | else |
|---|
| 61 | methodstr="chdk" |
|---|
| 62 | oldmode=capmode.get() |
|---|
| 63 | if not capmode.valid(reqmode) then |
|---|
| 64 | printf("%d not valid",reqmode) |
|---|
| 65 | end |
|---|
| 66 | -- we continue even if not valid, to test error handling |
|---|
| 67 | status=capmode.set(reqmode) |
|---|
| 68 | newmode=capmode.get() |
|---|
| 69 | end |
|---|
| 70 | if status then |
|---|
| 71 | status_str="OK" |
|---|
| 72 | else |
|---|
| 73 | status_str="FAIL" |
|---|
| 74 | end |
|---|
| 75 | printf("%s %d->%d %s",methodstr,oldmode,reqmode,status_str) |
|---|
| 76 | if newmode ~= reqmode then |
|---|
| 77 | printf("ERROR req %d got %d",reqmode,newmode) |
|---|
| 78 | end |
|---|
| 79 | print_status() |
|---|
| 80 | end |
|---|
| 81 | |
|---|
| 82 | function log_printf(...) |
|---|
| 83 | log:write(string.format(...)) |
|---|
| 84 | end |
|---|
| 85 | function log_status() |
|---|
| 86 | log_printf("%20s %3d %5d %s",capmode.get_name(),capmode.get(),capmode.get_canon(),get_rec_str()) |
|---|
| 87 | end |
|---|
| 88 | |
|---|
| 89 | fail_count=0 |
|---|
| 90 | function log_rec_change(rec) |
|---|
| 91 | local start_tick, end_tick, status_str, sleep_count |
|---|
| 92 | if rec then |
|---|
| 93 | log:write("SET RECORD | ") |
|---|
| 94 | else |
|---|
| 95 | log:write("SET PLAY | ") |
|---|
| 96 | end |
|---|
| 97 | start_tick=get_tick_count() |
|---|
| 98 | set_record(rec) |
|---|
| 99 | sleep_count = 0 |
|---|
| 100 | -- set_record just posts the message, needs time to finish |
|---|
| 101 | while sleep_count < 1000 do |
|---|
| 102 | if (rec and get_mode()) or not ( rec or get_mode()) then |
|---|
| 103 | break |
|---|
| 104 | end |
|---|
| 105 | sleep(10) |
|---|
| 106 | sleep_count = sleep_count + 1 |
|---|
| 107 | end |
|---|
| 108 | end_tick=get_tick_count() |
|---|
| 109 | log_status() |
|---|
| 110 | if (rec and get_mode()) or not (rec or get_mode()) then |
|---|
| 111 | status_str="OK" |
|---|
| 112 | else |
|---|
| 113 | status_str="FAIL" |
|---|
| 114 | fail_count = fail_count + 1 |
|---|
| 115 | end |
|---|
| 116 | log_printf(" %4dms sleep %d %s\n",end_tick - start_tick, sleep_count, status_str) |
|---|
| 117 | end |
|---|
| 118 | |
|---|
| 119 | function log_mode_change(id) |
|---|
| 120 | local start_tick, end_tick, status, status_str |
|---|
| 121 | log_printf("TRY %20s %3d | ",tostring(capmode.mode_to_name[id]),id) |
|---|
| 122 | start_tick=get_tick_count() |
|---|
| 123 | status=capmode.set(id) |
|---|
| 124 | end_tick=get_tick_count() |
|---|
| 125 | if status then |
|---|
| 126 | if capmode.get() ~= id then |
|---|
| 127 | status_str=string.format("CHANGE FAIL req %3d got %3d",id,capmode.get()) |
|---|
| 128 | fail_count = fail_count + 1 |
|---|
| 129 | else |
|---|
| 130 | status_str="OK" |
|---|
| 131 | end |
|---|
| 132 | else |
|---|
| 133 | status_str=string.format("SET %3d FAIL",id) |
|---|
| 134 | fail_count = fail_count + 1 |
|---|
| 135 | end |
|---|
| 136 | if not capmode.valid(id) then |
|---|
| 137 | status_str = status_str .. " INVALID" |
|---|
| 138 | end |
|---|
| 139 | log_status() |
|---|
| 140 | log_printf(" %4dms %s\n",end_tick - start_tick,status_str) |
|---|
| 141 | end |
|---|
| 142 | |
|---|
| 143 | function check_all_chdk() |
|---|
| 144 | local logname="A/setmode.log" |
|---|
| 145 | local was_play |
|---|
| 146 | printf("BATCH: log %s",logname) |
|---|
| 147 | log=io.open(logname,"wb") |
|---|
| 148 | if not log then |
|---|
| 149 | error("open log failed") |
|---|
| 150 | end |
|---|
| 151 | local bi=get_buildinfo() |
|---|
| 152 | log_printf("%s %s %s %s %s %s %s 0x%x\n", |
|---|
| 153 | bi.platform,bi.platsub,bi.version,bi.build_number, |
|---|
| 154 | bi.build_date,bi.build_time,bi.os,bi.platformid) |
|---|
| 155 | |
|---|
| 156 | log:write("START | ") |
|---|
| 157 | log_status() |
|---|
| 158 | log:write("\n") |
|---|
| 159 | if not get_mode() then |
|---|
| 160 | was_play=true |
|---|
| 161 | log_rec_change(true) |
|---|
| 162 | end |
|---|
| 163 | original_mode=capmode.get() |
|---|
| 164 | for id,_ in ipairs(capmode.mode_to_name) do |
|---|
| 165 | if capmode.valid(id) or batchtype > 0 then |
|---|
| 166 | log_mode_change(id) |
|---|
| 167 | -- some cameras require a delay |
|---|
| 168 | mode_change_delay() |
|---|
| 169 | end |
|---|
| 170 | end |
|---|
| 171 | log_mode_change(original_mode) |
|---|
| 172 | if was_play then |
|---|
| 173 | log_rec_change(false) |
|---|
| 174 | end |
|---|
| 175 | log:close() |
|---|
| 176 | -- need this to see display if we switched back to play |
|---|
| 177 | sleep(1000) |
|---|
| 178 | if fail_count == 0 then |
|---|
| 179 | print("PASS") |
|---|
| 180 | else |
|---|
| 181 | printf("%d FAILED check log",fail_count) |
|---|
| 182 | end |
|---|
| 183 | end |
|---|
| 184 | |
|---|
| 185 | function domenu() |
|---|
| 186 | local i=1 |
|---|
| 187 | local mainmenu={} |
|---|
| 188 | for id,name in ipairs(capmode.mode_to_name) do |
|---|
| 189 | if capmode.valid(id) then |
|---|
| 190 | mainmenu[i] = {name=name,id=id} |
|---|
| 191 | i = i + 1 |
|---|
| 192 | end |
|---|
| 193 | end |
|---|
| 194 | local curmenu=mainmenu |
|---|
| 195 | local curitem=1 |
|---|
| 196 | local lastitem=table.maxn(curmenu) |
|---|
| 197 | while true do |
|---|
| 198 | local sel=curmenu[curitem] |
|---|
| 199 | -- demonstrates flicker free redraw |
|---|
| 200 | set_console_autoredraw(0) |
|---|
| 201 | cls() |
|---|
| 202 | print("[/\\][\\/] [SET]") |
|---|
| 203 | print_status() |
|---|
| 204 | if curitem > 1 then |
|---|
| 205 | printf("|%s",curmenu[curitem-1].name) |
|---|
| 206 | else |
|---|
| 207 | print("--------------------") |
|---|
| 208 | end |
|---|
| 209 | printf(">%s",sel.name) |
|---|
| 210 | if curmenu[curitem+1] then |
|---|
| 211 | printf("|%s",curmenu[curitem+1].name) |
|---|
| 212 | else |
|---|
| 213 | print("--------------------") |
|---|
| 214 | end |
|---|
| 215 | console_redraw() |
|---|
| 216 | set_console_autoredraw(1) |
|---|
| 217 | wait_click(5000) |
|---|
| 218 | if is_pressed("down") then |
|---|
| 219 | if curmenu[curitem+1] then |
|---|
| 220 | curitem = curitem + 1 |
|---|
| 221 | else |
|---|
| 222 | curitem = 1 |
|---|
| 223 | end |
|---|
| 224 | elseif is_pressed("up") then |
|---|
| 225 | if curitem > 1 then |
|---|
| 226 | curitem = curitem - 1 |
|---|
| 227 | else |
|---|
| 228 | curitem = lastitem |
|---|
| 229 | end |
|---|
| 230 | elseif is_pressed("set") then |
|---|
| 231 | if capmode.set(sel.id) then |
|---|
| 232 | if capmode.get() == sel.id then |
|---|
| 233 | print("OK") |
|---|
| 234 | else |
|---|
| 235 | printf("FAIL: set %d got %d",sel.id,capmode.get()) |
|---|
| 236 | end |
|---|
| 237 | else |
|---|
| 238 | printf("FAIL: set %d",sel.id) |
|---|
| 239 | end |
|---|
| 240 | print_status() |
|---|
| 241 | print("press a key") |
|---|
| 242 | wait_click(10000) |
|---|
| 243 | elseif is_pressed("menu") then |
|---|
| 244 | break |
|---|
| 245 | end |
|---|
| 246 | end |
|---|
| 247 | end |
|---|
| 248 | |
|---|
| 249 | if action == 0 then |
|---|
| 250 | check_all_chdk() |
|---|
| 251 | print("press a key") |
|---|
| 252 | wait_click(10000) |
|---|
| 253 | elseif action == 1 then |
|---|
| 254 | domenu() |
|---|
| 255 | else |
|---|
| 256 | check_one() |
|---|
| 257 | print("press a key") |
|---|
| 258 | wait_click(10000) |
|---|
| 259 | end |
|---|
| 260 | |
|---|