diff --git a/pppc-sample.ini b/pppc-sample.ini index ae9c9ce..3141da5 100644 --- a/pppc-sample.ini +++ b/pppc-sample.ini @@ -1,8 +1,30 @@ -; Global options +;########################################################################### +;# Global options section # +;########################################################################### + +; port = port = LPT1 -[Light] +;########################################################################### +;# Entry section # +;########################################################################### +; Entry format: +; [Entry_Name] +; pin = (required) +; on_start = +; on_exit = +; on_lock = +; on_unlock = + +; Actions: +; on - turn the controller on +; off - turn the controller off +; none - do not change the controller (default if an event is unspecified) +; previous - only used for unlock events - restores state to what it was +; when the lock event ocurred + +[Overhead Light] pin = 7 on_start = on on_exit = off @@ -11,7 +33,6 @@ on_unlock = on [Fan] pin = 6 -on_start = off on_exit = off on_lock = off on_unlock = previous diff --git a/pppc.cc b/pppc.cc index 89218a7..f133693 100644 --- a/pppc.cc +++ b/pppc.cc @@ -241,17 +241,63 @@ void PPPC::event_start() void PPPC::event_exit() { + for (int sz = m_config.entries.size(), i = 0; i < sz; i++) + { + switch (m_config.entries[i].on_exit) + { + case Config::ON: + SET_BIT(m_pins, m_config.entries[i].pin, 1); + break; + case Config::OFF: + SET_BIT(m_pins, m_config.entries[i].pin, 0); + break; + default: + break; + } + } update_pins(); } void PPPC::event_lock() { + for (int sz = m_config.entries.size(), i = 0; i < sz; i++) + { + switch (m_config.entries[i].on_lock) + { + case Config::ON: + SET_BIT(m_pins, m_config.entries[i].pin, 1); + break; + case Config::OFF: + SET_BIT(m_pins, m_config.entries[i].pin, 0); + break; + default: + break; + } + } update_pins(); m_previous_pins = m_pins; } void PPPC::event_unlock() { + for (int sz = m_config.entries.size(), i = 0; i < sz; i++) + { + switch (m_config.entries[i].on_unlock) + { + case Config::ON: + SET_BIT(m_pins, m_config.entries[i].pin, 1); + break; + case Config::OFF: + SET_BIT(m_pins, m_config.entries[i].pin, 0); + break; + case Config::PREVIOUS: + SET_BIT(m_pins, m_config.entries[i].pin, + GET_BIT(m_previous_pins, m_config.entries[i].pin)); + break; + default: + break; + } + } update_pins(); }