module Tlapse::Capture

Constants

CAPTURE_DIRNAME
CAPTURE_FILENAME

Public Class Methods

capture_dirname() click to toggle source
# File lib/tlapse/capture.rb, line 13
def self.capture_dirname
  CAPTURE_DIRNAME
end
capture_filename() click to toggle source
# File lib/tlapse/capture.rb, line 9
def self.capture_filename
  CAPTURE_FILENAME
end
capture_single() click to toggle source
# 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:) click to toggle source

Calculate how many captures are needed given a duration of capture time and a desired interval between captures.

@example

captures_needed duration: 5.minutes, interval: 30.seconds # => 10

Specify either `start_time` and `end_time` or `duration`. If both are given, `duration` is preferred.

@param start_time: [Time] when to start capturing @param end_time: [Time] when to end capturing @param duration: [Duration] duration over which images are captured.

If specifying, do not also specify `end_time

@param interval: [Duration] time between each capture @return how many captures will be taken over the duration and interval

# 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:) click to toggle source

Capture a series of timelapse images over the given duration and at the given interval.

@return [String] a gphoto2 command with the desired arguments

# 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) click to toggle source

Capture a timelapse image once per interval while the sun is up.

@param interval [Duration] how frequently to capture images @return [String] a gphoto2 command with the desired arguments

# 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