Exemplo n.º 1
0
 def test_uninhibit(self, mock_output):
     exp_inhibit = 2
     exp_pins = [8, 3, 6, 10]
     d = Demux(exp_inhibit, exp_pins)
     mock_output.reset_mock()
     d.uninhibit()
     mock_output.assert_has_calls([call(exp_inhibit, GPIO.LOW)],
                                  any_order=True)
Exemplo n.º 2
0
 def test_inhibit(self, mock_output):
     exp_inhibit = 12
     exp_pins = [4, 19, 1, 3]
     d = Demux(exp_inhibit, exp_pins)
     mock_output.reset_mock()
     d.inhibit()
     mock_output.assert_has_calls([call(exp_inhibit, GPIO.HIGH)],
                                  any_order=True)
Exemplo n.º 3
0
 def test_reset(self, mock_output):
     exp_inhibit = 21
     exp_pins = [4, 5, 6, 8]
     d = Demux(exp_inhibit, exp_pins)
     mock_output.reset_mock()
     d.reset()
     mock_output.assert_has_calls([
         call(exp_pins[0], GPIO.LOW),
         call(exp_pins[1], GPIO.LOW),
         call(exp_pins[2], GPIO.LOW),
         call(exp_pins[3], GPIO.LOW)
     ],
                                  any_order=True)
Exemplo n.º 4
0
 def test_signal(self, mock_output):
     exp_inhibit = 21
     exp_pins = [4, 5, 6, 8]
     d = Demux(exp_inhibit, exp_pins)
     mock_output.reset_mock()
     d.signal(3)
     mock_output.assert_has_calls(
         [call(exp_pins[0], GPIO.HIGH),
          call(exp_pins[1], GPIO.HIGH)],
         any_order=True)
     mock_output.reset_mock()
     d.signal(8)
     mock_output.assert_has_calls([call(exp_pins[3], GPIO.HIGH)],
                                  any_order=True)
Exemplo n.º 5
0
 def test_init(self, mock_output):
     with patch("FakeRPi.GPIO.setup", autospec=True) as mock_setup:
         exp_inhibit = 12
         exp_pins = [4, 19, 1, 3]
         d = Demux(exp_inhibit, exp_pins)
         self.assertEqual(exp_inhibit, d._inhibit_pin)
         self.assertEqual(exp_pins, d._data_pins)
         mock_output.assert_has_calls([
             call(exp_inhibit, GPIO.HIGH),
             call(exp_pins[0], GPIO.LOW),
             call(exp_pins[1], GPIO.LOW),
             call(exp_pins[2], GPIO.LOW),
             call(exp_pins[3], GPIO.LOW)
         ],
                                      any_order=True)
         mock_setup.assert_has_calls([
             call(exp_inhibit, GPIO.OUT),
             call(exp_pins[0], GPIO.OUT),
             call(exp_pins[1], GPIO.OUT),
             call(exp_pins[2], GPIO.OUT),
             call(exp_pins[3], GPIO.OUT)
         ],
                                     any_order=True)
Exemplo n.º 6
0
 def test_init_fails_without_four_pins(self, mock_output):
     exp_inhibit = 12
     exp_pins = [4, 19, 1]
     with self.assertRaises(ValueError):
         Demux(exp_inhibit, exp_pins)
Exemplo n.º 7
0
import web
import time
from demux import Demux

urls = ('/', 'index', '/launch/(\d+)', 'launch')

t_globals = {'datestr': web.datestr}
render = web.template.render('templates', base='base', globals=t_globals)

demultiplexer = [
    Demux(3, [5, 7, 8, 10]),
    Demux(11, [12, 13, 15, 16]),
    Demux(18, [19, 21, 22, 23])
]


class index:
    def GET(self):
        return render.index()


class launch:
    def POST(self, id):
        fire(int(id))
        raise web.seeother('/')


def fire(num):
    r = num / 16
    d = demultiplexer[r]
    d.signal(num - r * 16)