diff --git a/grid_recorder.py b/grid_recorder.py index 5ced541..049d2a1 100644 --- a/grid_recorder.py +++ b/grid_recorder.py @@ -32,9 +32,9 @@ class Configuration(): self.n_extra = 0 # timestamps - self._now = datetime.datetime.now() - self._start_clock = None - self._end_clock = None + self.now = datetime.datetime.now() + self.start_clock = None + self.end_clock = None # paths self.path = './' @@ -49,7 +49,6 @@ class Configuration(): # init calls 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): GPIO.setmode(GPIO.BOARD) @@ -100,7 +99,7 @@ class Configuration(): def create_file_structure(self): 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): os.makedirs(self.path) @@ -111,12 +110,7 @@ class Configuration(): cfg = cfg_f.readlines() for enu, line in enumerate(cfg): if "StartDate" in line: - 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[enu] = (' StartDate : %s\n' % self.now.strftime('-'.join(self.path_format.split('-')[:3]))) cfg_f.close() cfg_f = open(cfg_file, 'w+') for line in cfg: @@ -128,37 +122,12 @@ class Configuration(): self.led_file = os.path.join(self.path, 'led_times.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(): def __init__(self, config): self.config = config + self.config.create_file_structure() - self._last_button_2_t = time() - self.config._now = self._now - + # GPIO configuration self.LED1_pin = 11 self.Button1_pin = 16 self.LED2_pin = 13 @@ -166,6 +135,8 @@ class Recorder(): self.LED_out_pin = 35 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, LED2_pin = self.LED2_pin, Button2_pin = self.Button2_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]: h = datetime.datetime.now().hour 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) self.LED_status[1] = True @@ -331,7 +302,7 @@ class Recorder(): while GPIO.input(self.Button1_pin) == GPIO.LOW: 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: subprocess.run(['tvservice', '-o']) subprocess.run(['vcgencmd', 'display_power', '0']) # @@ -451,6 +422,14 @@ class Recorder(): def main(): 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.run()