@@ -42,7 +42,19 @@ def read_all_pins(self) -> dict:
4242 pin_states [name ] = p ()
4343
4444 return pin_states
45+ @classmethod
46+ def _get_pin (cls , pin :str , direction :int ) -> Pin :
4547
48+ pin_ionum = None
49+ if isinstance (pin , int ):
50+ pin_ionum = pin
51+ else :
52+ pin_name_to_io = GPIOMap .all ()
53+ if pin not in pin_name_to_io :
54+ raise KeyError (f'No pin named { pin } found' )
55+ pin_ionum = pin_name_to_io [pin ]
56+
57+ return Pin (pin_ionum , direction )
4658 @classmethod
4759 def read_pin (cls , pin :str ) -> int :
4860 '''
@@ -54,22 +66,24 @@ def read_pin(cls, pin:str) -> int:
5466 @return: the value read
5567 '''
5668
57- pin_ionum = None
58- if isinstance (pin , int ):
59- pin_ionum = pin
60- else :
61- pin_name_to_io = GPIOMap .all ()
62- if pin not in pin_name_to_io :
63- raise KeyError (f'No pin named { pin } found' )
64- pin_ionum = pin_name_to_io [pin ]
65-
66- p = Pin (pin_ionum , Pin .IN )
69+ p = cls ._get_pin (pin , Pin .IN )
6770 return p ()
6871
72+ @classmethod
73+ def write_pin (cls , pin :str , value :int ):
74+ p = cls ._get_pin (pin , Pin .OUT )
75+ p (value )
76+
77+
6978
7079 @classmethod
7180 def dotest_buttons_held (cls ):
72- return cls .read_pin ('rp_projclk' ) # and not cls.read_pin('sdi_nprojectrst')
81+ cls .write_pin ('hk_csb' , 1 )
82+ if cls .read_pin ('rp_projclk' ) and not cls .read_pin ('sdi_nprojectrst' ):
83+ log .info ('POST "do test" buttons held' )
84+ return True
85+
86+ return False
7387
7488# could also check
7589
0 commit comments