def _enable_power(self, enable: bool): ''' set GPIO for the power SSR ''' if self._pin_power: l.debug('enable_power {}'.format(enable)) pi.write(self._pin_power, enable != self._inv_power) # pos polarity
def __init__(self, **params): super().__init__() self.id = 'piT' self.params = params self._timing_tick = 0 self._time_EOT = 0 self._last_waiting = 0 self._state = None self._time_squelch = 0 self._use_squelch = True self._keep_alive_counter = 0 self._tx_buffer = [] self._rx_buffer = [] # get setting params self._mode = params.get('mode', 'TW39') self._baudrate = params.get('baudrate', 50) self._bytesize = params.get('bytesize', 5) self._stopbits = params.get('stopbits', 1.5) self._stopbits2 = int(self._stopbits * 2 + 0.5) self._pin_txd = params.get('pin_txd', 17) #self._inv_txd = params.get('inv_txd', False) # not possible with PIGPIO self._pin_dir = params.get('pin_dir', 0) self._pin_rxd = params.get('pin_rxd', 27) self._inv_rxd = params.get('inv_rxd', False) self._pin_relay = params.get('pin_relay', 22) self._inv_relay = params.get('inv_relay', False) self._pin_power = params.get('pin_power', 0) self._inv_power = params.get('inv_power', False) self._pin_number_switch = params.get( 'pin_number_switch', params.get('pin_fsg_ns', 6)) # pin typical wired to rxd pin self._inv_number_switch = params.get('inv_number_switch', False) self._line_observer = None if params.get('use_observe_line', True): self._pin_observe_line = params.get('pin_observe_line', self._pin_rxd) self._inv_observe_line = params.get('inv_observe_line', self._inv_rxd) self._line_observer = Observer(self._pin_observe_line, self._inv_observe_line, 10) # 10ticks = 0.5sec self._coding = params.get('coding', 0) self._loopback = params.get('loopback', True) self._timing_rxd = params.get('timing_rxd', False) self._WB_pulse_length = params.get('WB_pulse_length', 40) self._double_WR = params.get('double_WR', False) # init codec self._character_duration = (self._bytesize + 1.0 + self._stopbits) / self._baudrate self._mc = txCode.BaudotMurrayCode( self._loopback, coding=self._coding, character_duration=self._character_duration) # init GPIOs pi.set_mode(self._pin_rxd, pigpio.INPUT) pi.set_pull_up_down(self._pin_rxd, pigpio.PUD_UP) pi.set_glitch_filter(self._pin_rxd, 50000 // self._baudrate) # 1ms @ 50Bd self._number_switch = None if self._pin_number_switch > 0: # 0:keyboard pos:TW39 neg:TW39@RPiCtrl self._number_switch = NumberSwitch(self._pin_number_switch, self._callback_number_switch, self._inv_number_switch) pi.set_mode(self._pin_txd, pigpio.OUTPUT) #pi.write(self._pin_txd, not self._inv_txd) pi.write(self._pin_txd, 1) if self._pin_power: pi.set_mode(self._pin_power, pigpio.OUTPUT) pi.write(self._pin_power, self._inv_power) if self._pin_relay: pi.set_mode(self._pin_relay, pigpio.OUTPUT) # relay for commutating pi.write(self._pin_relay, self._inv_relay) # pos polarity if self._pin_dir: pi.set_mode(self._pin_dir, pigpio.OUTPUT) # direction of comminication pi.write(self._pin_dir, 0) # 1=transmitting # init bit bongo serial read try: _ = pi.bb_serial_read_close( self._pin_rxd ) # try to close if it is still open from last debug except: pass _ = pi.bb_serial_read_open(self._pin_rxd, self._baudrate, self._bytesize) pi.bb_serial_invert(self._pin_rxd, self._inv_rxd) if self._timing_rxd: self._cb = pi.callback(self._pin_rxd, pigpio.EITHER_EDGE, self._callback_timing) # init bit bongo serial write self.last_wid = None # init state self._set_state(S_OFFLINE)
def __init__(self, **params): super().__init__() self.id = 'piC' self.params = params self._pin_number_switch = params.get('pin_number_switch', 0) # connected to NS self._inv_number_switch = params.get('inv_number_switch', True) self._pin_button_1T = params.get('pin_button_1T', 0) # single button optional self._pin_button_AT = params.get('pin_button_AT', 0) # button AT optional self._pin_button_ST = params.get('pin_button_ST', 0) # button ST optional self._pin_button_LT = params.get('pin_button_LT', 0) # button LT optional self._pin_button_U1 = params.get('pin_button_U1', 0) # button user 1 optional self._pin_button_U2 = params.get('pin_button_U2', 0) # button user 2 optional self._pin_button_U3 = params.get('pin_button_U3', 0) # button user 3 optional self._pin_button_U4 = params.get('pin_button_U4', 0) # button user 4 optional self._pin_LED_A = params.get('pin_LED_A', 0) self._pin_LED_WB = params.get('pin_LED_WB', 0) self._pin_LED_WB_A = params.get('pin_LED_WB_A', 0) self._pin_LED_status_R = params.get('pin_LED_status_R', 0) # LED red self._pin_LED_status_G = params.get('pin_LED_status_G', 0) # LED green self._pin_power = params.get('pin_power', 0) self._inv_power = params.get('inv_power', False) self._rx_buffer = [] self._mode = None self._status_out = 0 self._status_act = 0 self._status_dst = 0 self._LED_status_R = None self._LED_status_G = None if self._pin_LED_status_R and self._pin_LED_status_G: self._LED_status_R = LED_PWM(self._pin_LED_status_R) self._LED_status_G = LED_PWM(self._pin_LED_status_G) self._set_status('INIT') self._LED_A = None self._LED_WB = None self._LED_WB_A = None if self._pin_LED_A: self._LED_A = LED(self._pin_LED_A) if self._pin_LED_WB: self._LED_WB = LED(self._pin_LED_WB) if self._pin_LED_WB_A: self._LED_WB_A = LED(self._pin_LED_WB_A) if self._pin_button_1T: self._button_1T = Button(self._pin_button_1T, self._callback_button_1T) if self._pin_button_AT: self._button_AT = Button(self._pin_button_AT, self._callback_button_AT) if self._pin_button_ST: self._button_ST = Button(self._pin_button_ST, self._callback_button_ST) if self._pin_button_LT: self._button_LT = Button(self._pin_button_LT, self._callback_button_LT) if self._pin_button_U1: self._button_U1 = Button(self._pin_button_U1, self._callback_button_U1) if self._pin_button_U2: self._button_U2 = Button(self._pin_button_U2, self._callback_button_U2) if self._pin_button_U3: self._button_U3 = Button(self._pin_button_U3, self._callback_button_U3) if self._pin_button_U4: self._button_U4 = Button(self._pin_button_U4, self._callback_button_U4) self._number_switch = None if self._pin_number_switch: self._number_switch = NumberSwitch(self._pin_number_switch, self._callback_number_switch, self._inv_number_switch) if self._pin_power: pi.set_mode(self._pin_power, pigpio.OUTPUT) pi.write(self._pin_power, self._inv_power) self._set_mode('Z')
def _enable_relay(self, enable: bool): ''' set GPIO for the relay ''' if self._pin_relay: l.debug('enable_relay {}'.format(enable)) pi.write(self._pin_relay, enable != self._inv_relay) # pos polarity