def test_01150_time_writes_F_F_F_F_to_T_T_T_T_on_gen_gpio0_to_3(self): a_pin_group = pingroup.open_pingroup( [ pingroup.PinId.p1_gpio_gen0()\ , pingroup.PinId.p1_gpio_gen1()\ , pingroup.PinId.p1_gpio_gen2()\ , pingroup.PinId.p1_gpio_gen3()\ ]\ , 'wS') self.assertIsInstance(a_pin_group,pingroup.PinListWriter) states = [ [False, False, False, False]\ , [ True, False, False, False]\ , [False, True, False, False]\ , [ True, True, False, False]\ , [False, False, True, False]\ , [ True, False, True, False]\ , [False, True, True, False]\ , [ True, True, True, False]\ , [False, False, False, True]\ , [ True, False, False, True]\ , [False, True, False, True]\ , [ True, True, False, True]\ , [False, False, True, True]\ , [ True, False, True, True]\ , [False, True, True, True]\ , [ True, True, True, True]\ ] ITERATIONS = 200 print "\nStarting pin group sequence write timing..." time.sleep(0.05) then = time.time() for it in range(ITERATIONS): for i in states: a_pin_group.write(i) now = time.time() a_pin_group.write(states[0]) print ITERATIONS, "* F,F,F,F..T,T,T,T GPIO pin group writes took:", now - then, "seconds."
def open_pingroup_explicit_close(): gpio_gen0_1_out = pingroup.open_pingroup( [ pin.PinId.p1_gpio_gen0() , pin.PinId.p1_gpio_gen1() ] , 'w') assert( not gpio_gen0_1_out.closed() ) gpio_gen0_1_out.close() assert( gpio_gen0_1_out.closed() )
def with_open_pingroup_closed_in_with_clause_exit_cleanup(): outside_value = None with pingroup.open_pingroup( [ pin.PinId.p1_gpio_gen0() , pin.PinId.p1_gpio_gen1() ] ) as p: outside_value = p assert( not p.closed() ) assert( not outside_value.closed() ) assert( outside_value.closed() )
def cycle_gpio_gen0_gen1_sequence(): with pingroup.open_pingroup( [ pingroup.PinId.p1_gpio_gen0() , pingroup.PinId.p1_gpio_gen1() ] , 'wS') as out_pins: out_pins.write([True,False]) # Set p1_gpio_gen0 pin of group HIGH time.sleep(0.2) out_pins.write([False,True]) # Set p1_gpio_gen1 pin of group HIGH time.sleep(0.2) out_pins.write([False,False]) # Set both pin group GPIO pins LOW time.sleep(0.2)
def cycle_gpio_gen0_gen1_integer(): with pingroup.open_pingroup( [ pingroup.PinId.p1_gpio_gen0() , pingroup.PinId.p1_gpio_gen1() ] , 'wI') as out_pins: out_pins.write(1) # Set p1_gpio_gen0 pin of group HIGH time.sleep(0.2) out_pins.write(2) # Set p1_gpio_gen1 pin of group HIGH time.sleep(0.2) out_pins.write(0) # Set both pin group GPIO pins LOW time.sleep(0.2)
def wait_on_both_GPIO_GEN6_GCLK_no_timeout_sequence(): with pingroup.open_pingroup( [ pingroup.PinId.p1_gpio_gen6() , pingroup.PinId.p1_gpio_gclk() ], 'rBS' ) as in_pins: in_pins.read() # returns immediately with initial state of pins print "Start waiting for 3 state changes on P1 GPIO_GEN6 or GPIO_GCLK..." first_sample = list(in_pins.read()) second_sample = list(in_pins.read()) third_sample = list(in_pins.read()) print "Read 3 samples from P1 GPIO_GEN6 and GPIO_GCLK ",\ first_sample, second_sample, third_sample
def wait_on_rising_edge_GPIO_GEN6_GCLK_no_timeout_integer(): with pingroup.open_pingroup( [ pingroup.PinId.p1_gpio_gen6() , pingroup.PinId.p1_gpio_gclk() ], 'rRI' ) as in_pins: in_pins.read() # returns immediately with initial state of pins print "Start sampling 3 transitions to HIGH state on P1 GPIO_GEN6 or GPIO_GCLK..." in_pins.read() print "High once" in_pins.read() print "High twice" in_pins.read() print "High thrice" print "P1 GPIO_GEN6 or GPIO_GCLK gone high 3 times"
def test_00100_write_0_to_7_and_down_again_to_gen_gpio0_to_2(self): a_pin_group = pingroup.open_pingroup( [ pingroup.PinId.p1_gpio_gen0()\ , pingroup.PinId.p1_gpio_gen1()\ , pingroup.PinId.p1_gpio_gen2()\ ]\ , 'w') self.assertIsInstance(a_pin_group,pingroup.PinWordWriter) for i in range(8): time.sleep(0.5) a_pin_group.write(i) for i in range(7,-1,-1): time.sleep(0.5) a_pin_group.write(i)
def wait_on_rising_edge_GPIO_GEN6_GCLK_no_timeout_sequence(): with pingroup.open_pingroup( [ pingroup.PinId.p1_gpio_gen6() , pingroup.PinId.p1_gpio_gclk() ], 'rRS' ) as in_pins: in_pins.read() # returns immediately with initial state of pins print "Start sampling 3 transitions to HIGH state on P1 GPIO_GEN6 or GPIO_GCLK..." first_sample = list(in_pins.read()) print "High once" second_sample = list(in_pins.read()) print "High twice" third_sample = list(in_pins.read()) print "High thrice" print "P1 GPIO_GEN6 or GPIO_GCLK gone high 3 times, returned values were",\ first_sample, second_sample, third_sample
def poll_GPIO_GEN6_GCLK_opened_non_blocking_sequence(): INTERVAL = 1.0 # seconds with pingroup.open_pingroup( [ pingroup.PinId.p1_gpio_gen6() , pingroup.PinId.p1_gpio_gclk() ], 'rNS' ) as in_pins: print "Start sampling GPIO_GEN6 and GPIO_GCLK (open mode rNS) ..." time.sleep(INTERVAL) first_sample = list(in_pins.read()) time.sleep(INTERVAL) second_sample = list(in_pins.read()) time.sleep(INTERVAL) third_sample = list(in_pins.read()) print "Read 3 samples from P1 GPIO_GEN6, GPIO_GCLK at approximately",\ INTERVAL, "second intervals:", first_sample, second_sample,\ third_sample
def test_05150_blocking_both_read_word_list_gpio_gen6_and_gpio_gclk(self): a_pin_group = pingroup.open_pingroup( [ pingroup.PinId.p1_gpio_gen6()\ , pingroup.PinId.p1_gpio_gclk()\ ]\ , 'rBS') self.assertIsInstance(a_pin_group,pingroup.PinListBlockingReader) print "\nMake P1 pin GPIO_GEN6 LOW and GPIO_GCLK LOW..." time.sleep(1.5) self.assertEquals(a_pin_group.read(), [False,False]) print "Change P1 pin GPIO_GEN6 to HIGH keep GPIO_GCLK at LOW..." self.assertEquals(a_pin_group.read(), [True,False]) print "Keep P1 pin GPIO_GEN6 at HIGH change GPIO_GCLK to HIGH..." self.assertEquals(a_pin_group.read(), [True,True]) print "Change P1 pin GPIO_GEN6 to LOW keep GPIO_GCLK at HIGH..." self.assertEquals(a_pin_group.read(), [False,True])
def test_05200_blocking_rising_read_list_from_gpio_gen6_and_gpio_gclk(self): a_pin_group = pingroup.open_pingroup( [ pingroup.PinId.p1_gpio_gen6()\ , pingroup.PinId.p1_gpio_gclk()\ ]\ , 'rRS') self.assertIsInstance(a_pin_group,pingroup.PinListBlockingReader) print "\nMake P1 pin GPIO_GEN6 LOW and GPIO_GCLK LOW..." time.sleep(1.5) self.assertEquals(a_pin_group.read(), [False,False]) print "Toggle P1 pin GPIO_GEN6 state keep GPIO_GCLK LOW..." self.assertEquals(a_pin_group.read(), [True,False]) print "Keep P1 pin GPIO_GEN6 LOW toggle GPIO_GCLK state..." self.assertEquals(a_pin_group.read(), [True,True]) time.sleep(1.0) self.assertEquals(a_pin_group.read(0), [False,False])
def poll_GPIO_GEN6_GCLK_opened_blocking_on_rising_edge_integer(): INTERVAL = 1.0 # seconds with pingroup.open_pingroup( [ pingroup.PinId.p1_gpio_gen6() , pingroup.PinId.p1_gpio_gclk() ], 'rRI' ) as in_pins: print "Start sampling GPIO_GEN6 and GPIO_GCLK (open mode rRI) ..." in_pins.read() # returns immediately with initial state of pins time.sleep(INTERVAL) first_sample = in_pins.read(0) time.sleep(INTERVAL) second_sample = in_pins.read(0) time.sleep(INTERVAL) third_sample = in_pins.read(0) print "Read 3 samples from P1 GPIO_GEN6, GPIO_GCLK at approximately",\ INTERVAL, "second intervals:", first_sample, second_sample,\ third_sample
def test_04250_blocking_rising_read_word_from_gpio_gen6_and_gpio_gclk(self): a_pin_group = pingroup.open_pingroup( [ pingroup.PinId.p1_gpio_gen6()\ , pingroup.PinId.p1_gpio_gclk()\ ]\ , 'rF') self.assertIsInstance(a_pin_group,pingroup.PinWordBlockingReader) print "\nMake P1 pin GPIO_GEN6 HIGH and GPIO_GCLK HIGH..." time.sleep(2.5) self.assertEquals(a_pin_group.read(), 3) print "Toggle P1 pin GPIO_GEN6 state keep GPIO_GCLK HIGH..." self.assertEquals(a_pin_group.read(), 2) print "Keep P1 pin GPIO_GEN6 HIGH toggle GPIO_GCLK state..." self.assertEquals(a_pin_group.read(), 0) time.sleep(1.0) self.assertEquals(a_pin_group.read(0), 3) print "\nMake P1 pin GPIO_GEN6 LOW and GPIO_GCLK LOW..."
def test_00150_time_writes_0_to_15_on_gen_gpio0_to_3(self): a_pin_group = pingroup.open_pingroup( [ pingroup.PinId.p1_gpio_gen0()\ , pingroup.PinId.p1_gpio_gen1()\ , pingroup.PinId.p1_gpio_gen2()\ , pingroup.PinId.p1_gpio_gen3()\ ]\ , 'w') self.assertIsInstance(a_pin_group,pingroup.PinWordWriter) ITERATIONS = 200 print "\nStarting pin group word write timing..." time.sleep(0.05) then = time.time() for it in range(ITERATIONS): for i in range(16): a_pin_group.write(i) now = time.time() a_pin_group.write(0) print ITERATIONS, "* 0..15 GPIO pin group writes took:", now - then, "seconds."
def test_04100_poll_blocking_read_word_from_gpio_gen6_and_gpio_gclk(self): a_pin_group = pingroup.open_pingroup( [ pingroup.PinId.p1_gpio_gen6()\ , pingroup.PinId.p1_gpio_gclk()\ ]\ , 'rB') self.assertIsInstance(a_pin_group,pingroup.PinWordBlockingReader) print "\nMake P1 pin GPIO_GEN6 LOW and GPIO_GCLK LOW..." time.sleep(1.5) self.assertEquals(a_pin_group.read(0), 0) print "Make P1 pin GPIO_GEN6 HIGH and GPIO_GCLK LOW..." time.sleep(1.5) self.assertEquals(a_pin_group.read(0), 1) print "Make P1 pin GPIO_GEN6 LOW and GPIO_GCLK HIGH..." time.sleep(1.5) self.assertEquals(a_pin_group.read(0), 2) print "Make P1 pin GPIO_GEN6 HIGH and GPIO_GCLK HIGH..." time.sleep(1.5) self.assertEquals(a_pin_group.read(0), 3)
def test_05100_poll_blocking_read_list_from_gpio_gen6_and_gpio_gclk(self): a_pin_group = pingroup.open_pingroup( [ pingroup.PinId.p1_gpio_gen6()\ , pingroup.PinId.p1_gpio_gclk()\ ]\ , 'rBS') self.assertIsInstance(a_pin_group,pingroup.PinListBlockingReader) print "\nMake P1 pin GPIO_GEN6 LOW and GPIO_GCLK LOW..." time.sleep(1.5) self.assertEquals(a_pin_group.read(0), [False,False]) print "Make P1 pin GPIO_GEN6 HIGH and GPIO_GCLK LOW..." time.sleep(1.5) self.assertEquals(a_pin_group.read(0), [True,False]) print "Make P1 pin GPIO_GEN6 LOW and GPIO_GCLK HIGH..." time.sleep(1.5) self.assertEquals(a_pin_group.read(0), [False,True]) print "Make P1 pin GPIO_GEN6 HIGH and GPIO_GCLK HIGH..." time.sleep(1.5) self.assertEquals(a_pin_group.read(0), [True,True])
def toggle_gpio_gen0_gen1_integer(): with pingroup.open_pingroup( [ pingroup.PinId.p1_gpio_gen0() , pingroup.PinId.p1_gpio_gen1() ] , 'wI') as out_pins: out_pins.write(3) # Set both pin group GPIO pins HIGH time.sleep(0.2) out_pins.write(0) # Set both pin group GPIO pins LOW time.sleep(0.2) out_pins.write('3') # Set both pin group GPIO pins HIGH time.sleep(0.2) out_pins.write('0') # Set both pin group GPIO pins LOW time.sleep(0.2) out_pins.write(3.1) # Set both pin group GPIO pins HIGH time.sleep(0.2) out_pins.write(0.0) # Set both pin group GPIO pins LOW time.sleep(0.2) out_pins.write(1 | 2) # Set both pin group GPIO pins HIGH time.sleep(0.2) out_pins.write(False) # Set both pin group GPIO pins LOW time.sleep(0.2)
def toggle_gpio_gen0_gen1_sequence(): with pingroup.open_pingroup( [ pingroup.PinId.p1_gpio_gen0() , pingroup.PinId.p1_gpio_gen1() ] , 'wS') as out_pins: out_pins.write([True,True]) # Set both pin group GPIO pins HIGH time.sleep(0.2) out_pins.write([False,False]) # Set both pin group GPIO pins LOW time.sleep(0.2) out_pins.write([1,1]) # Set both pin group GPIO pins HIGH time.sleep(0.2) out_pins.write([0,0]) # Set both pin group GPIO pins LOW time.sleep(0.2) out_pins.write([23,42]) # Set both pin group GPIO pins HIGH time.sleep(0.2) out_pins.write([None,None]) # Set both pin group GPIO pins LOW time.sleep(0.2) out_pins.write(['1','1']) # Set both pin group GPIO pins HIGH time.sleep(0.2) out_pins.write(['0','0']) # Set both pin group GPIO pins LOW time.sleep(0.2)
def wait_on_both_GPIO_GEN6_GCLK_with_timeouts_sequence(): with pingroup.open_pingroup( [ pingroup.PinId.p1_gpio_gen6() , pingroup.PinId.p1_gpio_gclk() ], 'rBS' ) as in_pins: in_pins.read() # returns immediately with initial state of pins print "Waiting for 0.0001s for state change on P1 GPIO_GEN6 or GPIO_GCLK, timeout probable..." value = in_pins.read(0.0001) if value==None: print "Wait for input change timed out..." else: print "Value read:", value print "Waiting for 10000s for state change on P1 GPIO_GEN6 or GPIO_GCLK, timeout less probable..." value = in_pins.read(10000) if value==None: print "Wait for input change timed out..." else: print "Value read:", value
def test_01100_write_F_F_F_to_T_T_T_and_down_again_to_gen_gpio0_to_2(self): a_pin_group = pingroup.open_pingroup( [ pingroup.PinId.p1_gpio_gen0()\ , pingroup.PinId.p1_gpio_gen1()\ , pingroup.PinId.p1_gpio_gen2()\ ]\ , 'wS') self.assertIsInstance(a_pin_group,pingroup.PinListWriter) states = [ [False, False, False]\ , [ True, False, False]\ , [False, True, False]\ , [ True, True, False]\ , [False, False, True]\ , [ True, False, True]\ , [False, True, True]\ , [ True, True, True]\ ] for i in states: time.sleep(0.5) a_pin_group.write(i) for i in reversed(states): time.sleep(0.5) a_pin_group.write(i)
def test_open_pin_for_reading_blockonbothedges_sequence_mode_creates_PinListBlockingReader(self): self.assertIsInstance( pingroup.open_pingroup([pingroup.PinId.p1_gpio_gen0()], "rBS"), pingroup.PinListBlockingReader )
def test_open_pins_for_writing_bad_format_mode_fails(self): with self.assertRaises(error.PinGroupFormatModeInvalidError): pingroup.open_pingroup([pingroup.PinId.p1_gpio_gen0()], "wN#")
def test_open_pin_for_writing_creates_PinWordWriter(self): self.assertIsInstance(pingroup.open_pingroup([pingroup.PinId.p1_gpio_gen0()], "w"), pingroup.PinWordWriter)
def test_open_pin_for_writing_noblocking_integer_mode_creates_PinWordWriter(self): self.assertIsInstance(pingroup.open_pingroup([pingroup.PinId.p1_gpio_gen0()], "wNI"), pingroup.PinWordWriter)
def test_open_pin_for_writing_nonblocking_sequence_mode_creates_PinListWriter(self): self.assertIsInstance(pingroup.open_pingroup([pingroup.PinId.p1_gpio_gen0()], "wNS"), pingroup.PinListWriter)
def test_open_pins_for_writing_some_blocking_mode_fails(self): with self.assertRaises(error.PinBlockModeInvalidError): pingroup.open_pingroup([pingroup.PinId.p1_gpio_gen0()], "wRI") with self.assertRaises(error.PinBlockModeInvalidError): pingroup.open_pingroup([pingroup.PinId.p1_gpio_gen0()], "wFS") with self.assertRaises(error.PinBlockModeInvalidError): pingroup.open_pingroup([pingroup.PinId.p1_gpio_gen0()], "wBI") with self.assertRaises(error.PinBlockModeInvalidError): pingroup.open_pingroup([pingroup.PinId.p1_gpio_gen0()], "wR") with self.assertRaises(error.PinBlockModeInvalidError): pingroup.open_pingroup([pingroup.PinId.p1_gpio_gen0()], "wF") with self.assertRaises(error.PinBlockModeInvalidError): pingroup.open_pingroup([pingroup.PinId.p1_gpio_gen0()], "wB")
def test_open_pins_for_reading_bad_blocking_or_format_mode_fails(self): with self.assertRaises(error.PinGroupOpenModeInvalidError): pingroup.open_pingroup([pingroup.PinId.p1_gpio_gen0()], "r#")
def test_open_pins_bad_rw_mode_fails(self): with self.assertRaises(error.PinDirectionModeInvalidError): pingroup.open_pingroup([pingroup.PinId.p1_gpio_gen0()], "a")
def test_open_pins_bad_mode_string_fails(self): with self.assertRaises(error.PinGroupOpenModeInvalidError): pingroup.open_pingroup([pingroup.PinId.p1_gpio_gen0()], "rNS+")