Logging date and time to textfile (print_screen) - Script Writing - CHDK Forum supplierdeeply

Logging date and time to textfile (print_screen)

  • 15 Replies
  • 8055 Views
Logging date and time to textfile (print_screen)
« on: 13 / August / 2008, 13:53:46 »
Advertisements
Hi,

My newbie question:

Playing with a motion detection script (to spot cars driving by) I was wondering
if there is an general way / command to write a MD event with a date - time(stamp)
to a file using the print_screen and e.g. the command
print "MD event ", systemdate, systemtime
So not needing to extract the EXIF data...

Are the camera date / time available as a ubasic var.?

I would appreciate if someone can point me in the right direction. Thanks.





Re: Logging date and time to textfile (print_screen)
« Reply #1 on: 16 / August / 2008, 09:48:20 »
FYI

As an ubasic date/time/timestamp function isn't yet available in the CHDK builds
I wrote some coding which makes a more or less decent timestamp:

rem Timestamp logging
@title Timestamp
@param p Log (0=No,1=Yes)
@default p 1
@param d Day (01-31)
@default d 16
@param e Month (01-12)
@default e 8
@param f Year (8-9)
@default f 8

n=0
print_screen p

rem logging test of events...
gosub "timestamp"
sleep 2000
gosub "timestamp"
sleep 3000
gosub "timestamp"
print "*** END OF LOG ***"
print_screen 0
end

:timestamp
x=get_day_seconds
y=x/60
h=y/60
s=x-(y*60)
m=y-(h*60)
cls
n=n+1
rem f e d formatted to 200Y-MM-DD
if e<10 and d>9  then print "MD event ";n;": 200";f;"-0";e;"-";d;" ";h;":";m;":";s
if e<10 and d<10 then print "MD event ";n;": 200";f;"-0";e;"-0";d;" ";h;":";m;":";s
if e>9  and d<10 then print "MD event ";n;": 200";f;"-";e;"-0";d;" ";h;":";m;":";s
if e>9  and d>9  then print "MD event ";n;": 200";f;"-";e;"-";d;" ";h;":";m;":";s
return


*

Offline Jucifer

  • *****
  • 251
  • [A710IS]
Re: Logging date and time to textfile (print_screen)
« Reply #2 on: 16 / August / 2008, 18:19:11 »
I don't think there are functions in ubasic that would return date/time (other than get_day_seconds), at least yet...

but I just added get_time("Y[ear]|M[onth]|D[ay]|h[our]|m[inute]|s[econd]") to Lua.
(I tried to add that also for ubasic, but didn't succeed...)
Now that also Lua has fully functional MD, give it a try. :]

(check the collaborative CHDK build)

*

Offline fbonomi

  • ****
  • 469
  • A570IS SD1100/Ixus80
    • Francesco Bonomi
Re: Logging date and time to textfile (print_screen)
« Reply #3 on: 16 / August / 2008, 20:15:18 »
Jucifer, you made my code obsolete even before I could post it :-)

Code: [Select]
-- formats a number with two digits, leading zeroes
 -- (only works for numbers in range 0 - 99)
 function format_nn(n)
  r=tostring(n)
  if n<10 then
   r= "0" .. n
  end
  return r
 end
 
 -- return a formatted timestamp (hh:mm:ss)
 -- if called without parameters, gets current camera time and formats it
 -- if a parameter is passed, formats the passed number
 function timestamp(t)
 
  if t == nil then
   t=get_day_seconds()
  end
   
  s = t % 60
  m = (t / 60) % 60
  h = (t / 3600) % 24
 
  return format_nn(h) .. ":" .. format_nn(m) .. ":" .. format_nn(s)
 end
 


Re: Logging date and time to textfile (print_screen)
« Reply #4 on: 17 / August / 2008, 15:39:37 »
Thank you Jucifer. get_time works great!
I made a lua code snippet to test it and to create a timestamp for logging.

One lua ? problem: how to get the "print_screen" function to work.
How to disable writing to the file PR_SCREEN.TXT ?
Seems it writes always to this file...

--[[
@title Timestamp test
@param p Log (0=No,1=Yes)
--]]

function date()
   yyyy = (get_time("Y"))
   mm   = (get_time("M"))
   if (tonumber(mm)<10) then
      mm = "0"..mm
   end
   dd   = (get_time("D"))
   if (tonumber(dd)<10) then
   dd = "0"..dd
   end
   yyyymmdd = yyyy .. "-" .. mm .. "-" .. dd
end

function time()
   hh = (get_time("h"))
   if (tonumber(hh)<10) then
      hh = "0"..hh
   end
   mi = (get_time("m"))
   if (tonumber(mi)<10) then
      mi = "0"..mi
   end
   ss = (get_time("s"))
   if (tonumber(ss)<10) then
      ss = "0"..ss
   end
   hhmmss = hh .. ":" .. mi .. ":" .. ss
end

print_screen ( tonumber(p) )
print ( "get_time test" )
n = 0
date()
shoot()
n = n + 1
time()
ts = "MD " .. n .. ": " .. yyyymmdd .. "-" .. hhmmss
cls()
print( ts )
sleep( 5000 )
shoot()
n = n + 1
time()
ts = "MD " .. n .. ": " .. yyyymmdd .. "-" .. hhmmss
cls()
print( ts )
print_screen ( 0 )


*

Offline PhyrePhoX

  • *****
  • 2254
  • make RAW not WAR
    • PhyreWorX
Re: Logging date and time to textfile (print_screen)
« Reply #5 on: 17 / August / 2008, 15:45:40 »
hm, how would i add this command to ubasic. hms. suggestions welcome :D

*

Offline Jucifer

  • *****
  • 251
  • [A710IS]
Re: Logging date and time to textfile (print_screen)
« Reply #6 on: 18 / August / 2008, 09:55:35 »
One lua ? problem: how to get the "print_screen" function to work.
How to disable writing to the file PR_SCREEN.TXT ?
Seems it writes always to this file...

print_screen(false)

Or did you mean writing to another file? Maybe also that will be possible some day...

Re: Logging date and time to textfile (print_screen)
« Reply #7 on: 18 / August / 2008, 14:57:24 »
Thanks Jucifer: that's what I was looking for as a LUA newbie.
BTW: One file is enough.
Updated script snippet:

--[[
@title Timestamp test
@param p Log (0=No, 1=Yes)
--]]

function date()
   yyyy = (get_time("Y"))
   mm   = (get_time("M"))
   if (tonumber(mm)<10) then
      mm = "0"..mm
   end
   dd   = (get_time("D"))
   if (tonumber(dd)<10) then
   dd = "0"..dd
   end
   yyyymmdd = yyyy .. "-" .. mm .. "-" .. dd
end

function time()
   hh = (get_time("h"))
   if (tonumber(hh)<10) then
      hh = "0"..hh
   end
   mi = (get_time("m"))
   if (tonumber(mi)<10) then
      mi = "0"..mi
   end
   ss = (get_time("s"))
   if (tonumber(ss)<10) then
      ss = "0"..ss
   end
   hhmmss = hh .. ":" .. mi .. ":" .. ss
end

function openfile()
   print_screen (true)
end

function closefile()
   print_screen (false)
end

if (p == 0) then
   closefile()
else
   openfile()
end

print ( "get_time test" )
n = 0
date()
shoot()
n = n + 1
time()
ts = "MD " .. n .. ": " .. yyyymmdd .. "-" .. hhmmss
cls()
print( ts )
sleep( 5000 )
shoot()
n = n + 1
time()
ts = "MD " .. n .. ": " .. yyyymmdd .. "-" .. hhmmss
cls()
print( ts )
closefile()


*

Offline Jucifer

  • *****
  • 251
  • [A710IS]
Re: Logging date and time to textfile (print_screen)
« Reply #8 on: 20 / August / 2008, 15:51:36 »
Check out the newly hacked print_screen. :]
Files are now written to chdk/logs, and have names similar to image files.
e.g. print_screen(123) creates log_0123.txt

edit: to get log_0000.txt, use print_screen(10000) (as print_screen(0) disables logging... (as does print_screen(false)))
feel free to hack it better ;)

edit2: I'll try to fix that...

edit3: hmm... nothing is written to log_0000.txt...
« Last Edit: 21 / August / 2008, 03:10:17 by Jucifer »

*

Offline fbonomi

  • ****
  • 469
  • A570IS SD1100/Ixus80
    • Francesco Bonomi
Re: Logging date and time to textfile (print_screen)
« Reply #9 on: 20 / August / 2008, 16:15:49 »
oh, that's handy!

 

Related Topics