Beispiel #1
0
	def test_switches(self):
		print 'The left most switch is switch 1'
		for switch_num in range(1,5):
			sys.stdout.write('Press switch %d...' % switch_num)
			sys.stdout.flush()

			switch_values = self.get_switch_values()
			while switch_values == 0:
				switch_values = self.get_switch_values()

			pressed_switch = pfio.get_pin_number(switch_values)
			self.assertEqual(pressed_switch, switch_num,
					'Switch %d was pressed.' % pressed_switch)

			## bad test case, this re-queries the switch - need a way around this...
			# test the switch class
			#this_switch = pfio.Switch(switch_num)
			#self.assertEqual(this_switch.value, 1)

			print 'OK!'

			sleep(0.3)

			# before moving on, wait until no switches are pressed
			switch_values = self.get_switch_values()
			while switch_values != 0:
				switch_values = self.get_switch_values()
Beispiel #2
0
	def test_pin_translation(self):
		'''Tests the pin translation functions'''
		for pin in range(1, 9):
			bit_mask = pfio.get_pin_bit_mask(pin)
			self.assertEqual(bit_mask, 1 << (pin-1))
			number = pfio.get_pin_number(bit_mask)
			self.assertEqual(number, pin)