diff --git a/platformio.ini b/platformio.ini index f675e73157db7a38bd0329bcd10dc136045dc20a..92f4ec8be5925e35753d30276f96a3129040af12 100644 --- a/platformio.ini +++ b/platformio.ini @@ -10,7 +10,7 @@ [env:gpio_commons_lgt8fx8p] platform = lgt8f -board = lgt8fx8p +board = LGT8F328P framework = arduino lib_deps = diff --git a/src/lock.h b/src/lock.h index c6ace508c428769bd75203bc13d5283ef681ee4e..867dc6b67c13dd79315b3d73d3a66fe1b6284b12 100644 --- a/src/lock.h +++ b/src/lock.h @@ -4,34 +4,33 @@ #include #include -class Lock{ - private: - int _lockPin; - int _statePin; - bool _writeOffState = false; - bool _readOffState = false; - - public: - Lock(int lockPin, int statePin); - Lock(int lockPin, int statePin, bool offState); - Lock(int lockPin, bool writeOffState, int statePin, bool readOffState); - // void setSwitch(Switch *lockSwitch); - // void setStatePin(Pin *state); - void setup(int lockPin, bool writeOffState, int statePin, bool readOffState); - - bool turn(bool state); - - bool turn_on(); - - bool turn_off(); - - bool is_on(); - - bool is_off(); - - int state(); - - +class Lock +{ +private: + int _lockPin; + int _statePin; + bool _writeOffState = false; + bool _readOffState = false; + +public: + Lock(int lockPin, int statePin); + Lock(int lockPin, int statePin, bool offState); + Lock(int lockPin, bool writeOffState, int statePin, bool readOffState); + // void setSwitch(Switch *lockSwitch); + // void setStatePin(Pin *state); + void setup(int lockPin, bool writeOffState, int statePin, bool readOffState); + + bool turn(bool state); + + bool turn_on(); + + bool turn_off(); + + bool is_on(); + + bool is_off(); + + int state(); }; #endif \ No newline at end of file diff --git a/src/switch.cpp b/src/switch.cpp index 2aabacb04344ff8b0fc25829e05c58573048b3c4..c341f303d461b09332ef69c0486dfa307d2f1720 100644 --- a/src/switch.cpp +++ b/src/switch.cpp @@ -28,7 +28,10 @@ bool Switch::is_on() int s = state(); return offState ? s == LOW : s == HIGH; }; - +bool Switch::turn(bool state) +{ + return pin->write(state); +}; bool Switch::turn_on() { return pin->write(!offState); diff --git a/src/switch.h b/src/switch.h index a69a9e76f2800e704df8af0a2f3989592d3d9c4f..b5a95c46dd74cf8b8a29bd3175d4b6f450ca661a 100644 --- a/src/switch.h +++ b/src/switch.h @@ -6,13 +6,19 @@ class Switch { private: + #ifdef CLASS_PROPERTY_AUTO_INIT Pin *pin = &Pin(-1, INPUT); + #else + Pin *pin; + #endif bool offState = true; + public: Switch(Pin *_pin); Switch(Pin *_pin, bool _offState); int state(bool state); int state(); + bool turn(bool state); bool turn_on(); bool turn_off(); bool is_on();