diff --git a/brmdoor_nfc.config.sample b/brmdoor_nfc.config.sample index 9f44f3f..8e603e7 100644 --- a/brmdoor_nfc.config.sample +++ b/brmdoor_nfc.config.sample @@ -41,3 +41,11 @@ password = whatevs channels = #test-bjornbot tls = True reconnect_delay = 300 + +[open-switch] +# Controls showing status of "OPEN/CLOSE" switch that is connected to some GPIO pin +# Changes topic of connected IRC channels if IRC is enabled +# enabled - True/False +# status_file - file in sysfs that contains 1 or 0 defining the state of button +enabled = True +status_file = /sys/class/gpio/gpio11/value diff --git a/brmdoor_nfc_daemon.py b/brmdoor_nfc_daemon.py index 3083227..6e8f06d 100755 --- a/brmdoor_nfc_daemon.py +++ b/brmdoor_nfc_daemon.py @@ -59,6 +59,9 @@ class BrmdoorConfig(object): self.ircChannels = self.config.get("irc", "channels").split(" ") self.ircUseTLS = self.config.getboolean("irc", "tls") self.ircReconnectDelay = self.config.getint("irc", "reconnect_delay") + self.useOpenSwitch = self.config.getboolean("open-switch", "enabled") + if self.useOpenSwitch: + self.switchStatusFile = self.config.get("open-switch", "status_file") def convertLoglevel(self, levelString): """Converts string 'debug', 'info', etc. into corresponding @@ -256,6 +259,23 @@ class IrcThread(threading.Thread): else: time.sleep(self.reconnectDelay) +class OpenSwitchThread(threading.Thread): + """ + Class for watching OPEN/CLOSED switch that + """ + def __init__(self, config, ircThread): + """ + Create thread for IRC connection. + + :param config - BrmdoorConfig object + :param ircThread: IrcThread through which we can set and receive current topics + """ + self.statusFile = config.statusFile + threading.Thread.__init__(self) + + def run(self): + while True: + time.sleep(1) if __name__ == "__main__":