small changes. takes an additional argument for a rough recording duration +- 1 min ...
This commit is contained in:
parent
e5efa3187b
commit
1f0020a3c4
@ -32,9 +32,9 @@ class Configuration():
|
|||||||
self.n_extra = 0
|
self.n_extra = 0
|
||||||
|
|
||||||
# timestamps
|
# timestamps
|
||||||
self._now = datetime.datetime.now()
|
self.now = datetime.datetime.now()
|
||||||
self._start_clock = None
|
self.start_clock = None
|
||||||
self._end_clock = None
|
self.end_clock = None
|
||||||
|
|
||||||
# paths
|
# paths
|
||||||
self.path = './'
|
self.path = './'
|
||||||
@ -49,7 +49,6 @@ class Configuration():
|
|||||||
|
|
||||||
# init calls
|
# init calls
|
||||||
self.read_cfg()
|
self.read_cfg()
|
||||||
self.create_file_structure()
|
|
||||||
|
|
||||||
def GPIO_setup(self, LED1_pin, LED2_pin, LED_out_pin, Button1_pin, Button2_pin, power_controll_pin):
|
def GPIO_setup(self, LED1_pin, LED2_pin, LED_out_pin, Button1_pin, Button2_pin, power_controll_pin):
|
||||||
GPIO.setmode(GPIO.BOARD)
|
GPIO.setmode(GPIO.BOARD)
|
||||||
@ -100,7 +99,7 @@ class Configuration():
|
|||||||
|
|
||||||
def create_file_structure(self):
|
def create_file_structure(self):
|
||||||
start_str = ('%2.f_%2.f' % (self.start_clock[0], self.start_clock[1])).replace(' ', '0')
|
start_str = ('%2.f_%2.f' % (self.start_clock[0], self.start_clock[1])).replace(' ', '0')
|
||||||
self.path = os.path.join(self._base_path, self._now.strftime('-'.join(self.path_format.split('-')[:3])) + start_str) # ToDo: Edit here
|
self.path = os.path.join(self._base_path, self.now.strftime('-'.join(self.path_format.split('-')[:3])) + start_str) # ToDo: Edit here
|
||||||
if not os.path.exists(self.path):
|
if not os.path.exists(self.path):
|
||||||
os.makedirs(self.path)
|
os.makedirs(self.path)
|
||||||
|
|
||||||
@ -111,12 +110,7 @@ class Configuration():
|
|||||||
cfg = cfg_f.readlines()
|
cfg = cfg_f.readlines()
|
||||||
for enu, line in enumerate(cfg):
|
for enu, line in enumerate(cfg):
|
||||||
if "StartDate" in line:
|
if "StartDate" in line:
|
||||||
cfg[enu] = (' StartDate : %s\n' % self._now.strftime('-'.join(self.path_format.split('-')[:3])))
|
cfg[enu] = (' StartDate : %s\n' % self.now.strftime('-'.join(self.path_format.split('-')[:3])))
|
||||||
elif "StartTime" in line:
|
|
||||||
if not hasattr(self.start_clock, '__len__'):
|
|
||||||
cfg[enu] = (' StartTime : %s\n' % (self._now.strftime('%H:%M:%S') + self._now.strftime(".%f")[:4]))
|
|
||||||
else:
|
|
||||||
cfg[enu] = (' StartTime : %s\n' % ('%2.f:%2.f:00' % (self.start_clock[0], self.start_clock[1])))
|
|
||||||
cfg_f.close()
|
cfg_f.close()
|
||||||
cfg_f = open(cfg_file, 'w+')
|
cfg_f = open(cfg_file, 'w+')
|
||||||
for line in cfg:
|
for line in cfg:
|
||||||
@ -128,37 +122,12 @@ class Configuration():
|
|||||||
self.led_file = os.path.join(self.path, 'led_times.csv')
|
self.led_file = os.path.join(self.path, 'led_times.csv')
|
||||||
self.led_file2 = os.path.join(self.path, 'led_idxs.csv')
|
self.led_file2 = os.path.join(self.path, 'led_idxs.csv')
|
||||||
|
|
||||||
# @property
|
|
||||||
# def start_clock(self):
|
|
||||||
# return self._start_clock
|
|
||||||
#
|
|
||||||
# @start_clock.setter
|
|
||||||
# def start_clock(self, val):
|
|
||||||
# try:
|
|
||||||
# h, s = int(val[:2]), int(val[2:])
|
|
||||||
# self._start_clock = [h, s]
|
|
||||||
# except ValueError:
|
|
||||||
# self._start_clock = [10, 0]
|
|
||||||
#
|
|
||||||
# @property
|
|
||||||
# def end_clock(self):
|
|
||||||
# return self._end_clock
|
|
||||||
#
|
|
||||||
# @end_clock.setter
|
|
||||||
# def end_clock(self, val):
|
|
||||||
# try:
|
|
||||||
# h, s = int(val[:2]), int(val[2:])
|
|
||||||
# self._end_clock = [h, s]
|
|
||||||
# except ValueError:
|
|
||||||
# self._end_clock = [16, 0]
|
|
||||||
|
|
||||||
class Recorder():
|
class Recorder():
|
||||||
def __init__(self, config):
|
def __init__(self, config):
|
||||||
self.config = config
|
self.config = config
|
||||||
|
self.config.create_file_structure()
|
||||||
|
|
||||||
self._last_button_2_t = time()
|
# GPIO configuration
|
||||||
self.config._now = self._now
|
|
||||||
|
|
||||||
self.LED1_pin = 11
|
self.LED1_pin = 11
|
||||||
self.Button1_pin = 16
|
self.Button1_pin = 16
|
||||||
self.LED2_pin = 13
|
self.LED2_pin = 13
|
||||||
@ -166,6 +135,8 @@ class Recorder():
|
|||||||
self.LED_out_pin = 35
|
self.LED_out_pin = 35
|
||||||
self.power_controll_pin = 37
|
self.power_controll_pin = 37
|
||||||
|
|
||||||
|
self.last_button_2_t = time()
|
||||||
|
|
||||||
self.LED_status = self.config.GPIO_setup(LED1_pin = self.LED1_pin, Button1_pin = self.Button1_pin,
|
self.LED_status = self.config.GPIO_setup(LED1_pin = self.LED1_pin, Button1_pin = self.Button1_pin,
|
||||||
LED2_pin = self.LED2_pin, Button2_pin = self.Button2_pin,
|
LED2_pin = self.LED2_pin, Button2_pin = self.Button2_pin,
|
||||||
LED_out_pin = self.LED_out_pin, power_controll_pin = self.power_controll_pin)
|
LED_out_pin = self.LED_out_pin, power_controll_pin = self.power_controll_pin)
|
||||||
@ -298,7 +269,7 @@ class Recorder():
|
|||||||
self.config.start_clock[0] * 60 + self.config.start_clock[1]:
|
self.config.start_clock[0] * 60 + self.config.start_clock[1]:
|
||||||
h = datetime.datetime.now().hour
|
h = datetime.datetime.now().hour
|
||||||
m = datetime.datetime.now().minute
|
m = datetime.datetime.now().minute
|
||||||
self.config.start_clock = ('%2.f%2.f' % (h, m)).replace(' ', '0')
|
self.config.start_clock = [h, m]
|
||||||
|
|
||||||
GPIO.output(self.LED2_pin, GPIO.HIGH)
|
GPIO.output(self.LED2_pin, GPIO.HIGH)
|
||||||
self.LED_status[1] = True
|
self.LED_status[1] = True
|
||||||
@ -331,7 +302,7 @@ class Recorder():
|
|||||||
while GPIO.input(self.Button1_pin) == GPIO.LOW:
|
while GPIO.input(self.Button1_pin) == GPIO.LOW:
|
||||||
|
|
||||||
if GPIO.input(self.Button2_pin) == GPIO.HIGH:
|
if GPIO.input(self.Button2_pin) == GPIO.HIGH:
|
||||||
if (time() - self._last_button_2_t) > 5:
|
if (time() - self.last_button_2_t) > 5:
|
||||||
if disp_eth_power == True:
|
if disp_eth_power == True:
|
||||||
subprocess.run(['tvservice', '-o'])
|
subprocess.run(['tvservice', '-o'])
|
||||||
subprocess.run(['vcgencmd', 'display_power', '0']) #
|
subprocess.run(['vcgencmd', 'display_power', '0']) #
|
||||||
@ -451,6 +422,14 @@ class Recorder():
|
|||||||
def main():
|
def main():
|
||||||
config = Configuration()
|
config = Configuration()
|
||||||
|
|
||||||
|
if len(sys.argv) > 1:
|
||||||
|
rec_duration = int(sys.argv[1])
|
||||||
|
config.start_clock = [config.now.hour, config.now.minute]
|
||||||
|
config.end_clock = [config.now.hour, config.now.minute + rec_duration]
|
||||||
|
if config.end_clock[2] >= 60:
|
||||||
|
config.end_clock[0] += 1
|
||||||
|
config.end_clock[1] -= 60
|
||||||
|
|
||||||
rc = Recorder(config)
|
rc = Recorder(config)
|
||||||
|
|
||||||
rc.run()
|
rc.run()
|
||||||
|
Loading…
Reference in New Issue
Block a user