Ejemplo n.º 1
0
 def test_subtract_minutes(self):
     self.assertEqual(str(Clock(10, 3) - 3), '10:00')
Ejemplo n.º 2
0
 def test_hour_rolls_over(self):
     self.assertEqual('01:00', str(Clock(25, 0)))
Ejemplo n.º 3
0
 def test_sixty_minutes_is_next_hour(self):
     self.assertEqual('02:00', str(Clock(1, 60)))
Ejemplo n.º 4
0
 def test_clocks_with_negative_minute_that_wraps(self):
     self.assertEqual(Clock(4, 10), Clock(5, -1490))
Ejemplo n.º 5
0
 def test_clocks_with_negative_hours_and_minutes(self):
     self.assertEqual(Clock(7, 32), Clock(-12, -268))
Ejemplo n.º 6
0
 def test_clocks_with_negative_hour_that_wraps_multiple_times(self):
     self.assertEqual(Clock(13, 49), Clock(-83, 49))
Ejemplo n.º 7
0
 def test_clocks_with_minute_overflow_by_several_days(self):
     self.assertEqual(Clock(2, 2), Clock(2, 4322))
Ejemplo n.º 8
0
 def test_subtract_more_than_two_hours_with_borrow(self):
     self.assertEqual('03:35', str(Clock(6, 15).add(-160)))
Ejemplo n.º 9
0
 def test_subtract_more_than_one_day(self):
     self.assertEqual('04:32', str(Clock(5, 32).add(-1500)))
Ejemplo n.º 10
0
 def test_subtract_across_midnight(self):
     self.assertEqual('08:53', str(Clock(10, 3).add(-70)))
Ejemplo n.º 11
0
 def test_subtract_more_than_two_hours(self):
     self.assertEqual('21:20', str(Clock(0, 0).add(-160)))
Ejemplo n.º 12
0
 def test_past_the_hour(self):
     self.assertEqual('11:09', str(Clock(11, 9)))
Ejemplo n.º 13
0
    def run(self):
        # Wiringpi pin number, NOT RPI PIN! see here: http://wiringpi.com/pins/
        # Maybe use RPi instead of wiringpi...
        RESET_PIN = 15
        DC_PIN = 16
        led = ssd1351.SSD1351(reset_pin=RESET_PIN, dc_pin=DC_PIN, rows=96)
        self.clk = Clock(led)

        # handle sigterm
        signal.signal(signal.SIGTERM, self.shutdown)

        now = datetime.datetime.now()

        led.clear()

        led.log.setLevel(logging.WARNING)

        hours = now.hour
        minutes = now.minute

        # time sync
        time.sleep(1 - datetime.datetime.now().microsecond / 1000.0 / 1000.0)
        REFRESH_RATE = 1

        # Alarm (fixed for testing purpose)
        self.clk.alarm = ""  # 07:00"
        try:
            while True:
                now = datetime.datetime.now()
                resync = 0
                self.clk.clear()
                if self.clk.input_thread.has_input.is_set():
                    with self.clk.audio_thread.lock:
                        wheel = self.clk.input_thread.wheel
                        click = self.clk.input_thread.click
                    self.clk.input_thread.has_input.clear()
                    if wheel != 0 and not self.clk.in_menu:
                        new_vol = self.clk.audio_thread.volume + self.clk.input_thread.wheel
                        self.clk.d_volume(new_vol)
                    elif click or wheel != 0:
                        self.clk.d_menu(click, wheel)
                    with self.clk.input_thread.lock:
                        self.clk.input_thread.wheel = 0
                        self.clk.input_thread.click = False
                # elif clk.freeze > 0:
                #    clk.freeze -= 1
                #    clk.d_menu()
                else:
                    self.clk.in_menu = False
                    self.clk.in_volume = False
                    self.clk.freeze = 0
                self.clk.d_clock()
                if not self.clk.in_menu:
                    self.clk.d_mplayer()
                    self.clk.d_signal()
                    self.clk.d_temp()
                    self.clk.d_audio()
                    self.clk.d_alarm()
                self.clk.d_cpu()

                self.clk.display()

                if minutes != now.minute:
                    # refresh minutes
                    minutes = now.minute
                    if (now.microsecond > 100000):
                        resync = 0 - (now.microsecond / 1000.0 / 1000.0)

                # end here
                d = (datetime.datetime.now() - now).total_seconds()
                s = max(REFRESH_RATE - d + resync, 0)
                if s > 0:
                    # time.sleep(s)
                    self.clk.input_thread.has_input.wait(s +
                                                         1 * self.clk.freeze)
                if resync:
                    self.log.info(
                        "process: %.4f sleep: %.4f total: %.4f resync: %.2fms"
                        % (d, s, d + s, resync * 1000))
                elif d > 0.5:
                    self.log.info(
                        "process: %.4f sleep: %.4f total: %.4f overhead!" %
                        (d, s, d + s))
        except KeyboardInterrupt, e:
            self.shutdown()
Ejemplo n.º 14
0
 def test_subtract_to_previous_hour(self):
     self.assertEqual(str(Clock(10, 3) - 30), '09:33')
Ejemplo n.º 15
0
 def test_clocks_with_negative_hour(self):
     self.assertEqual(Clock(22, 40), Clock(-2, 40))
Ejemplo n.º 16
0
 def test_subtract_more_than_two_days(self):
     self.assertEqual('00:20', str(Clock(2, 20).add(-3000)))
Ejemplo n.º 17
0
 def test_clocks_with_negative_hour_that_wraps(self):
     self.assertEqual(Clock(17, 3), Clock(-31, 3))
Ejemplo n.º 18
0
 def test_clocks_with_same_time(self):
     self.assertEqual(Clock(15, 37), Clock(15, 37))
Ejemplo n.º 19
0
 def test_clocks_with_minute_overflow(self):
     self.assertEqual(Clock(0, 1), Clock(0, 1441))
Ejemplo n.º 20
0
 def test_clocks_a_minute_apart(self):
     self.assertNotEqual(Clock(15, 36), Clock(15, 37))
Ejemplo n.º 21
0
 def test_clocks_with_negative_minute(self):
     self.assertEqual(Clock(2, 40), Clock(3, -20))
Ejemplo n.º 22
0
 def test_clocks_an_hour_apart(self):
     self.assertNotEqual(Clock(14, 37), Clock(15, 37))
Ejemplo n.º 23
0
 def test_clocks_with_negative_minute_that_wraps_multiple_times(self):
     self.assertEqual(Clock(6, 15), Clock(6, -4305))
Ejemplo n.º 24
0
 def test_clocks_with_hour_overflow(self):
     self.assertEqual(Clock(10, 37), Clock(34, 37))
Ejemplo n.º 25
0
 def test_clocks_with_negative_hours_and_minutes_that_wrap(self):
     self.assertEqual(Clock(18, 7), Clock(-54, -11513))
Ejemplo n.º 26
0
 def test_clocks_with_hour_overflow_by_several_days(self):
     self.assertEqual(Clock(3, 11), Clock(99, 11))
Ejemplo n.º 27
0
 def test_hour_rolls_over_continuously(self):
     self.assertEqual('04:00', str(Clock(100, 0)))
Ejemplo n.º 28
0
 def test_midnight_is_zero_hours(self):
     self.assertEqual('00:00', str(Clock(24, 0)))
Ejemplo n.º 29
0
 def test_minutes_roll_over(self):
     self.assertEqual('02:40', str(Clock(0, 160)))
Ejemplo n.º 30
0
 def test_add_more_than_two_days(self):
     self.assertEqual(str(Clock(1, 1) + 3500), '11:21')