创客百科

姿势共享,有节操无门槛参与的创客百科,创客动力之源 \ (^_^) /

用户工具

站点工具


saks:sdk:libraries:dipswitch2bit

DipSwitch2Bit

2位拨码开关类,配置开关的触发事件并随时读取开关即时状态。

方法

__init__(self, pins, real_true = GPIO.HIGH)

初始化对象,设置引脚和触发电平(高电平或低电平触发)。pins 为 IO 引脚数组。

is_on(self)

返回当前开关的按下状态数组,2个元素,其值为 true 或 false。

register(self, observer)

为当前开关注册监听对象。observer 为监听对象。当开关状态改变时会触发 observer 对象的 on_dip_switch_2bit_status_changed(self, status) 方法。status 为该触发发生时的开关的状态数组,2个元素,其值为 true 或 false。

deregister(self, observer)

为当前开关注销监听对象。observer 为监听对象。

调用方法:

self.dip_switch = entities.DipSwitch2Bit([PINS.DIP_SWITCH_1, PINS.DIP_SWITCH_2], GPIO.LOW)

dip_switch_status_changed_handler = None
def on_dip_switch_2bit_status_changed(self, status):
    #print('on_dip_switch_2bit_status_changed')
    if self.dip_switch_status_changed_handler is not None:
        self.dip_switch_status_changed_handler(status)

def dip_switch_status_changed_handler(status):
    '''
    called while the status of dip switch changed
    :param status: current status
    :return: void
    '''
    print('on_dip_switch_status_changed:')
    print(status)
    pass
    
SAKS.dip_switch_status_changed_handler = dip_switch_status_changed_handler
本页面的其他翻译:
saks/sdk/libraries/dipswitch2bit.txt · 最后更改: 2017/01/23 14:41 (外部编辑)