lib/screen_tracker.rb in sensible-cinema-0.7.2 vs lib/screen_tracker.rb in sensible-cinema-0.7.3

- old
+ new

@@ -107,10 +107,21 @@ original = get_bmp loop { current = get_bmp if current != original if @digits + return attempt_to_get_time_from_screen + else + puts 'screen time change only detected...' if $VERBOSE + end + return + end + sleep 0.02 + } + end + + def attempt_to_get_time_from_screen out = {} dump_digits if $DEBUG digits = get_digits_as_bitmaps # 0.08s [!] not too accurate... start = Time.now DIGIT_TYPES.each{|type| @@ -121,12 +132,16 @@ @a ||= 1 @a += 1 p 'unable to identify digit!' + type.to_s + @a.to_s File.binwrite("bad_digit#{@a}#{type}.bmp", digits[type]) end - # early return - return + if type == :hours + digit = 0 # this one can fail in VLC + else + # early return + return + end end out[type] = digit else # there isn't one on screen, so probably zero... out[type] = 0 @@ -134,18 +149,11 @@ } out = "%d:%d%d:%d%d" % DIGIT_TYPES.map{|type| out[type]} p 'got new screen time ' + out + " delta:" + (Time.now - start).to_s if $VERBOSE # if the window was in the background it will be all zeroes, so nil it out out = nil unless out =~ /[1-9]/ - return out, Time.now - start - else - puts 'screen time change only detected...' if $VERBOSE + return out, Time.now-start end - return - end - sleep 0.02 - } - end def process_forever_in_thread Thread.new { loop { out_time, delta = wait_till_next_change \ No newline at end of file