Module: Tlapse::Capture
- Defined in:
- lib/tlapse/capture.rb
Constant Summary collapse
- CAPTURE_FILENAME =
"%Y-%m-%d_%H-%M-%S.jpg"
- CAPTURE_DIRNAME =
"%Y-%m-%d"
Class Method Summary collapse
- .capture_dirname ⇒ Object
- .capture_filename ⇒ Object
- .capture_single ⇒ Object
-
.captures_needed(start_time: Time.now, end_time: Time.now, duration: nil, interval:) ⇒ Object
Calculate how many captures are needed given a duration of capture time and a desired interval between captures.
-
.timelapse_command(from: Time.now, to:, interval:) ⇒ String
Capture a series of timelapse images over the given duration and at the given interval.
-
.timelapse_command_while_sun_is_up(interval: 5.minutes) ⇒ String
Capture a timelapse image once per interval while the sun is up.
Class Method Details
.capture_dirname ⇒ Object
13 14 15 |
# File 'lib/tlapse/capture.rb', line 13 def self.capture_dirname CAPTURE_DIRNAME end |
.capture_filename ⇒ Object
9 10 11 |
# File 'lib/tlapse/capture.rb', line 9 def self.capture_filename CAPTURE_FILENAME end |
.capture_single ⇒ Object
17 18 19 |
# File 'lib/tlapse/capture.rb', line 17 def self.capture_single `gphoto2 --capture-image-and-download --filename '#{capture_filename}'` end |
.captures_needed(start_time: Time.now, end_time: Time.now, duration: nil, interval:) ⇒ Object
Calculate how many captures are needed given a duration of capture time and a desired interval between captures.
Specify either ‘start_time` and `end_time` or `duration`. If both are given, `duration` is preferred.
37 38 39 40 41 42 43 44 45 46 |
# File 'lib/tlapse/capture.rb', line 37 def self.captures_needed(start_time: Time.now, end_time: Time.now, duration: nil, interval:) unless duration start_time = start_time.to_i end_time = end_time.to_i duration = end_time - start_time end duration / interval end |
.timelapse_command(from: Time.now, to:, interval:) ⇒ String
Capture a series of timelapse images over the given duration and at the given interval.
53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/tlapse/capture.rb', line 53 def self.timelapse_command(from: Time.now, to:, interval:) captures = self.captures_needed( start_time: from, end_time: to, interval: interval ) command = "gphoto2 --capture-image-and-download" command += " -I #{interval}" command += " -F #{captures}" command += " --filename '#{capture_filename}'" end |
.timelapse_command_while_sun_is_up(interval: 5.minutes) ⇒ String
Capture a timelapse image once per interval while the sun is up.
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/tlapse/capture.rb', line 71 def self.timelapse_command_while_sun_is_up(interval: 5.minutes) sunrise = SolarEvent.sunrise sunset = SolarEvent.sunset now = Time.now # Use now as starting time if sunrise has passed sunrise = now > sunrise ? now : sunrise captures = self.captures_needed( start_time: sunrise, end_time: sunset, interval: interval ) "gphoto2 --capture-image-and-download -I #{interval} -F #{captures} --filename '#{capture_filename}'" end |