From 444375e33886fac2f11e53f31aa5d00ae158bab5 Mon Sep 17 00:00:00 2001 From: zhongji Date: Wed, 22 Dec 2021 15:40:13 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=8A=A0=E5=85=A5CLASS=5FPROPERTY=5FAU?= =?UTF-8?q?TO=5FINIT=E7=94=A8=E4=BA=8E=E5=AE=9A=E4=B9=89=E7=BC=96=E8=AF=91?= =?UTF-8?q?=E6=97=B6=E9=9C=80=E8=A6=81=E8=87=AA=E5=8A=A8=E5=88=9D=E5=A7=8B?= =?UTF-8?q?=E5=8C=96=E5=92=8C=E4=B8=8D=E9=9C=80=E8=A6=81=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E5=88=9D=E5=A7=8B=E5=8C=96=E7=9A=84=E6=83=85=E5=BD=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- platformio.ini | 2 +- src/lock.h | 55 +++++++++++++++++++++++++------------------------- src/switch.cpp | 5 ++++- src/switch.h | 6 ++++++ 4 files changed, 38 insertions(+), 30 deletions(-) diff --git a/platformio.ini b/platformio.ini index f675e73..92f4ec8 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 c6ace50..867dc6b 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 2aabacb..c341f30 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 a69a9e7..b5a95c4 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(); -- Gitee