From a2e4cf19a3a760441f96bdbc9a76fbaa044853c4 Mon Sep 17 00:00:00 2001 From: Kadir Sevil Date: Tue, 16 Aug 2022 03:28:25 +0300 Subject: [PATCH] initial commit --- .clang-format | 147 +++++++++ .github/ISSUE_TEMPLATE/config.yml | 5 + .github/ISSUE_TEMPLATE/feature_request.yml | 69 +++++ .github/ISSUE_TEMPLATE/issue_report.yml | 99 ++++++ .github/PULL_REQUEST_TEMPLATE.md | 35 +++ .github/workflows/githubci.yml | 64 ++++ .gitignore | 17 ++ LICENSE | 165 ++++++++++ README.md | 1 - .../button_relay_control.ino | 79 +++++ .../mqtt_relay_control/mqtt_relay_control.ino | 172 +++++++++++ .../serial_terminal_relay_control.ino | 99 ++++++ keywords.txt | 14 + library.properties | 9 + src/si1108.cpp | 278 +++++++++++++++++ src/si1108.h | 287 ++++++++++++++++++ 16 files changed, 1539 insertions(+), 1 deletion(-) create mode 100644 .clang-format create mode 100644 .github/ISSUE_TEMPLATE/config.yml create mode 100644 .github/ISSUE_TEMPLATE/feature_request.yml create mode 100644 .github/ISSUE_TEMPLATE/issue_report.yml create mode 100644 .github/PULL_REQUEST_TEMPLATE.md create mode 100644 .github/workflows/githubci.yml create mode 100644 .gitignore create mode 100644 LICENSE create mode 100644 examples/button_relay_control/button_relay_control.ino create mode 100644 examples/mqtt_relay_control/mqtt_relay_control.ino create mode 100644 examples/serial_terminal_relay_control/serial_terminal_relay_control.ino create mode 100644 keywords.txt create mode 100644 library.properties create mode 100644 src/si1108.cpp create mode 100644 src/si1108.h diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..c127880 --- /dev/null +++ b/.clang-format @@ -0,0 +1,147 @@ +--- +Language: Cpp +AccessModifierOffset: 0 +AlignAfterOpenBracket: Align +AlignConsecutiveMacros: true +AlignConsecutiveAssignments: false +AlignConsecutiveBitFields: false +AlignConsecutiveDeclarations: false +AlignEscapedNewlines: Left +AlignOperands: Align +AlignTrailingComments: true +AllowAllArgumentsOnNextLine: false +AllowAllConstructorInitializersOnNextLine: false +AllowAllParametersOfDeclarationOnNextLine: false +AllowShortEnumsOnASingleLine: false +AllowShortBlocksOnASingleLine: Never +AllowShortCaseLabelsOnASingleLine: false +AllowShortFunctionsOnASingleLine: None +AllowShortLambdasOnASingleLine: None +AllowShortIfStatementsOnASingleLine: Never +AllowShortLoopsOnASingleLine: false +AlwaysBreakAfterDefinitionReturnType: None +AlwaysBreakAfterReturnType: None +AlwaysBreakBeforeMultilineStrings: false +AlwaysBreakTemplateDeclarations: MultiLine +BinPackArguments: false +BinPackParameters: false +BraceWrapping: + AfterCaseLabel: true + AfterClass: true + AfterControlStatement: Always + AfterEnum: true + AfterFunction: true + AfterNamespace: true + AfterObjCDeclaration: true + AfterStruct: true + AfterUnion: true + AfterExternBlock: true + BeforeCatch: true + BeforeElse: true + BeforeLambdaBody: true + BeforeWhile: true + IndentBraces: true + SplitEmptyFunction: true + SplitEmptyRecord: true + SplitEmptyNamespace: true +BreakBeforeBinaryOperators: All +BreakBeforeBraces: Allman +BreakBeforeInheritanceComma: false +BreakInheritanceList: AfterColon +BreakBeforeTernaryOperators: true +BreakConstructorInitializersBeforeComma: true +BreakConstructorInitializers: AfterColon +BreakAfterJavaFieldAnnotations: true +BreakStringLiterals: true +ColumnLimit: 160 +CommentPragmas: '^ IWYU pragma:' +CompactNamespaces: false +ConstructorInitializerAllOnOneLineOrOnePerLine: true +ConstructorInitializerIndentWidth: 4 +ContinuationIndentWidth: 4 +Cpp11BracedListStyle: true +DeriveLineEnding: true +DerivePointerAlignment: false +DisableFormat: false +ExperimentalAutoDetectBinPacking: false +FixNamespaceComments: false +ForEachMacros: + - foreach + - Q_FOREACH + - BOOST_FOREACH +IncludeBlocks: Preserve +IncludeCategories: + - Regex: '^"(llvm|llvm-c|clang|clang-c)/' + Priority: 2 + SortPriority: 0 + - Regex: '^(<|"(gtest|gmock|isl|json)/)' + Priority: 3 + SortPriority: 0 + - Regex: '.*' + Priority: 1 + SortPriority: 0 +IncludeIsMainRegex: '(Test)?$' +IncludeIsMainSourceRegex: '' +IndentCaseLabels: false +IndentCaseBlocks: false +IndentGotoLabels: true +IndentPPDirectives: None +IndentExternBlock: AfterExternBlock +IndentWidth: 2 +IndentWrappedFunctionNames: false +InsertTrailingCommas: None +JavaScriptQuotes: Leave +JavaScriptWrapImports: true +KeepEmptyLinesAtTheStartOfBlocks: true +MacroBlockBegin: '' +MacroBlockEnd: '' +MaxEmptyLinesToKeep: 1 +NamespaceIndentation: None +ObjCBinPackProtocolList: Auto +ObjCBlockIndentWidth: 2 +ObjCBreakBeforeNestedBlockParam: true +ObjCSpaceAfterProperty: false +ObjCSpaceBeforeProtocolList: true +PenaltyBreakAssignment: 2 +PenaltyBreakBeforeFirstCallParameter: 19 +PenaltyBreakComment: 300 +PenaltyBreakFirstLessLess: 120 +PenaltyBreakString: 1000 +PenaltyBreakTemplateDeclaration: 10 +PenaltyExcessCharacter: 1000000 +PenaltyReturnTypeOnItsOwnLine: 60 +PointerAlignment: Left +ReflowComments: true +SortIncludes: true +SortUsingDeclarations: true +SpaceAfterCStyleCast: false +SpaceAfterLogicalNot: false +SpaceAfterTemplateKeyword: false +SpaceBeforeAssignmentOperators: true +SpaceBeforeCpp11BracedList: false +SpaceBeforeCtorInitializerColon: false +SpaceBeforeInheritanceColon: false +SpaceBeforeParens: Never +SpaceBeforeRangeBasedForLoopColon: false +SpaceInEmptyBlock: false +SpaceInEmptyParentheses: false +SpacesBeforeTrailingComments: 1 +SpacesInAngles: false +SpacesInConditionalStatement: false +SpacesInContainerLiterals: false +SpacesInCStyleCastParentheses: false +SpacesInParentheses: false +SpacesInSquareBrackets: false +SpaceBeforeSquareBrackets: false +Standard: c++03 +StatementMacros: + - Q_UNUSED + - QT_REQUIRE_VERSION +TabWidth: 4 +UseCRLF: false +UseTab: Never +WhitespaceSensitiveMacros: + - STRINGIZE + - PP_STRINGIZE + - BOOST_PP_STRINGIZE +... diff --git a/.github/ISSUE_TEMPLATE/config.yml b/.github/ISSUE_TEMPLATE/config.yml new file mode 100644 index 0000000..23253dd --- /dev/null +++ b/.github/ISSUE_TEMPLATE/config.yml @@ -0,0 +1,5 @@ +blank_issues_enabled: false +contact_links: + - name: Official Website + url: https://diodeiot.com + about: Official Diode IoT website diff --git a/.github/ISSUE_TEMPLATE/feature_request.yml b/.github/ISSUE_TEMPLATE/feature_request.yml new file mode 100644 index 0000000..68be112 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature_request.yml @@ -0,0 +1,69 @@ +name: Feature Request +description: Suggest an idea for this project +labels: ["Type: enhancement"] + +body: + - type: markdown + attributes: + value: | + * We welcome any ideas or feature requests! It is helpful if you can explain exactly why the feature would be useful. + * You can take a look to existing issues. + + - type: input + id: Area + attributes: + label: Related area + description: Please briefly explain the area of your feature request. + placeholder: eg. Board support, New functionality ... + validations: + required: true + + - type: input + id: HW + attributes: + label: Hardware specifications + description: Please provide if your proposal depends on specific hardware. + placeholder: eg. Support for ESP32, Uno ... + validations: + required: true + + - type: textarea + id: problem-related + attributes: + label: Is your feature request related to a problem? + description: Please provide a clear and concise description of what the problem is. Add relevant issue link. + placeholder: eg. I'm facing the issue/missing function... + validations: + required: true + + - type: textarea + id: solution + attributes: + label: Describe the solution you'd like + description: Please provide a clear and concise description of what you want to happen. + placeholder: eg. When using this function... + validations: + required: true + + - type: textarea + id: alternatives + attributes: + label: Describe alternatives you've considered + description: Please provide a clear and concise description of any alternative solutions or features you've considered. + placeholder: eg. Choosing other approach wouldn't work, because... + + - type: textarea + id: context + attributes: + label: Additional context + description: Please add any other context or screenshots about the feature request here. + placeholder: eg. This would work only when ... + + - type: checkboxes + id: confirmation + attributes: + label: I have checked existing list of feature requests and the contribution guide + description: You agree to check all the resources above before opening a new feature request. + options: + - label: I confirm i have checked existing list of feature requests and contribution guide. + required: true diff --git a/.github/ISSUE_TEMPLATE/issue_report.yml b/.github/ISSUE_TEMPLATE/issue_report.yml new file mode 100644 index 0000000..86fc8b6 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/issue_report.yml @@ -0,0 +1,99 @@ +name: Issue Report +description: Report any problem here +labels: ["Status: Awaiting triage"] +body: + - type: markdown + attributes: + value: | + * You can take a look to existing issues. + * If still experiencing the issue, please provide as many details as possible below about your hardware, computer setup and code. + + - type: textarea + id: other-hw + attributes: + label: Hardware configuration + description: Is anything else attached to the device? + placeholder: eg. GPIO 18 & 19 are connected to I2C devices. + validations: + required: true + + - type: textarea + id: sw-version + attributes: + label: Software version + description: What version are you running? If possible, consider updating to the latest version. + placeholder: eg. v1.0.0 + validations: + required: true + + - type: textarea + id: hw-version + attributes: + label: Hardware version + description: What version are you running? + placeholder: eg. v1.0.0 + validations: + required: true + + - type: input + id: IDE + attributes: + label: IDE name + description: What IDE are you using? + placeholder: eg. Arduino IDE, PlatformIO, Sloeber ... + validations: + required: true + + - type: input + id: os + attributes: + label: Operating System + description: On which OS does this issue occur? + placeholder: eg. macOS 12.1, Windows 10 ... + validations: + required: true + + - type: textarea + id: Description + attributes: + label: Description + description: Please describe your problem here and expected behaviour. + placeholder: eg. Can't connect/weird behaviour/wrong function/missing parameter.. + validations: + required: true + + - type: textarea + id: sketch + attributes: + label: Sketch + description: Please provide full minimal sketch/code which can be run to reproduce your issue. + placeholder: eg. Related part of the code to replicate the issue + render: cpp + validations: + required: true + + - type: textarea + id: Debug + attributes: + label: Debug Message + description: Please provide a debug message or error message. + placeholder: Debug output here + render: plain + validations: + required: true + + - type: textarea + id: other-remarks + attributes: + label: Other Steps to Reproduce + description: Is there any other information you can think of which will help us reproduce this problem? Any additional info can be added as well. + placeholder: eg. I also tried on other OS, HW...it works correctly on that setup. + + - type: checkboxes + id: confirmation + attributes: + label: I have checked existing issues, online documentation and the Troubleshooting Guide + description: You agree to check all the resources above before opening a new issue. + options: + - label: I confirm I have checked existing issues, online documentation and Troubleshooting guide. + required: true diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md new file mode 100644 index 0000000..d2aef1d --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -0,0 +1,35 @@ +# Pull Request Template for Diode IoT Arduino Libraries + +Thank you for creating a pull request to contribute to Diode IoT's GitHub Arduino repository. + +Before you open the request, please review the following guidelines and tips to +help it be more easily integrated: + +- **Describe the scope of your change i.e. what the change does and what parts of the code were modified** + + This will help us understand any risks of integrating the code. + +- **Describe any known limitations with your change** + + For example if the change doesn't apply to a supported platform of the library please mention it. + +- **Please run any tests or examples that can exercise your modified code** + + We strive to not break users of the code and running tests/examples helps with this + process. + +- **Please make sure all ci-arduino criteria are met before making pull request** + + There are strict code quality and documentation rules in Diode IoT Github repository. Plase make sure all ci-arduino checks are met + before making pull request. + +Thank you again for contributing. We will try to test and integrate the change +as soon as we can, but be aware we have many GitHub repositories to manage and +can't immediately respond to every request. There is no need to bump or check in +on a pull request (it will clutter the discussion of the request). + +Also don't be worried if the request is closed or not integrated, sometimes the +priorities of Diode IoT's GitHub repository (education, ease of use) might not match the priorities of the pull request. Don't fret, the open source community thrives on +forks and GitHub makes it easy to keep your changes in a forked repo. + +After reviewing the guidelines above you can delete this text from the pull request. diff --git a/.github/workflows/githubci.yml b/.github/workflows/githubci.yml new file mode 100644 index 0000000..11dc4d4 --- /dev/null +++ b/.github/workflows/githubci.yml @@ -0,0 +1,64 @@ +# @file githubci.yml +# +# @brief Diode IoT Arduino Library CI Workflow. +# +# @authors Diode IoT Inc. +# +# @authors Kadir Sevil +# +# @copyright Copyright (c) 2021-2022 Diode Iot Inc. All rights reserved. +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +# Directory Structure: +# . +# |__ workspace (all workflow files,except main repository files,will reside here) +# |__ ci (cloned arduino-ci repository) +# |__ code_docs (all doxygen related files) +# |__ [Main Repo (gh-pages checkout)] +# | |__ html (generated doxygen files) +# |__ doxygen-1.9.4 (doxygen executables) + +name: Arduino Library CI + +on: [push, pull_request] + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/setup-python@v4 + with: + python-version: '3.x' + + - uses: actions/checkout@v3 + + - uses: actions/checkout@v3 + with: + repository: diodeiot/ci-arduino + path: workspace/ci + + - name: pre run + run: bash workspace/ci/pre_run.sh + + - name: clang-format + run: python3 workspace/ci/run-clang-format.py -e "workspace/*" -r . + + - name: doxygen + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + #PRETTY_NAME: "NAME_HERE" + DOC_LANG: "tr" + run: bash workspace/ci/doxygen_deploy.sh diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..196b8d3 --- /dev/null +++ b/.gitignore @@ -0,0 +1,17 @@ +html/ +Doxyfile +*.hex +*.elf + +# Ignore files built by Visual Studio/Visual Micro +[Dd]ebug*/ +[Rr]elease*/ +.vs/ +__vm/ +*.vcxproj* +.vscode/ +platform.sloeber.txt +boards.sloeber.txt + +# Test log files +*.log diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..65c5ca8 --- /dev/null +++ b/LICENSE @@ -0,0 +1,165 @@ + GNU LESSER GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + + This version of the GNU Lesser General Public License incorporates +the terms and conditions of version 3 of the GNU General Public +License, supplemented by the additional permissions listed below. + + 0. Additional Definitions. + + As used herein, "this License" refers to version 3 of the GNU Lesser +General Public License, and the "GNU GPL" refers to version 3 of the GNU +General Public License. + + "The Library" refers to a covered work governed by this License, +other than an Application or a Combined Work as defined below. + + An "Application" is any work that makes use of an interface provided +by the Library, but which is not otherwise based on the Library. +Defining a subclass of a class defined by the Library is deemed a mode +of using an interface provided by the Library. + + A "Combined Work" is a work produced by combining or linking an +Application with the Library. The particular version of the Library +with which the Combined Work was made is also called the "Linked +Version". + + The "Minimal Corresponding Source" for a Combined Work means the +Corresponding Source for the Combined Work, excluding any source code +for portions of the Combined Work that, considered in isolation, are +based on the Application, and not on the Linked Version. + + The "Corresponding Application Code" for a Combined Work means the +object code and/or source code for the Application, including any data +and utility programs needed for reproducing the Combined Work from the +Application, but excluding the System Libraries of the Combined Work. + + 1. Exception to Section 3 of the GNU GPL. + + You may convey a covered work under sections 3 and 4 of this License +without being bound by section 3 of the GNU GPL. + + 2. Conveying Modified Versions. + + If you modify a copy of the Library, and, in your modifications, a +facility refers to a function or data to be supplied by an Application +that uses the facility (other than as an argument passed when the +facility is invoked), then you may convey a copy of the modified +version: + + a) under this License, provided that you make a good faith effort to + ensure that, in the event an Application does not supply the + function or data, the facility still operates, and performs + whatever part of its purpose remains meaningful, or + + b) under the GNU GPL, with none of the additional permissions of + this License applicable to that copy. + + 3. Object Code Incorporating Material from Library Header Files. + + The object code form of an Application may incorporate material from +a header file that is part of the Library. You may convey such object +code under terms of your choice, provided that, if the incorporated +material is not limited to numerical parameters, data structure +layouts and accessors, or small macros, inline functions and templates +(ten or fewer lines in length), you do both of the following: + + a) Give prominent notice with each copy of the object code that the + Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the object code with a copy of the GNU GPL and this license + document. + + 4. Combined Works. + + You may convey a Combined Work under terms of your choice that, +taken together, effectively do not restrict modification of the +portions of the Library contained in the Combined Work and reverse +engineering for debugging such modifications, if you also do each of +the following: + + a) Give prominent notice with each copy of the Combined Work that + the Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the Combined Work with a copy of the GNU GPL and this license + document. + + c) For a Combined Work that displays copyright notices during + execution, include the copyright notice for the Library among + these notices, as well as a reference directing the user to the + copies of the GNU GPL and this license document. + + d) Do one of the following: + + 0) Convey the Minimal Corresponding Source under the terms of this + License, and the Corresponding Application Code in a form + suitable for, and under terms that permit, the user to + recombine or relink the Application with a modified version of + the Linked Version to produce a modified Combined Work, in the + manner specified by section 6 of the GNU GPL for conveying + Corresponding Source. + + 1) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (a) uses at run time + a copy of the Library already present on the user's computer + system, and (b) will operate properly with a modified version + of the Library that is interface-compatible with the Linked + Version. + + e) Provide Installation Information, but only if you would otherwise + be required to provide such information under section 6 of the + GNU GPL, and only to the extent that such information is + necessary to install and execute a modified version of the + Combined Work produced by recombining or relinking the + Application with a modified version of the Linked Version. (If + you use option 4d0, the Installation Information must accompany + the Minimal Corresponding Source and Corresponding Application + Code. If you use option 4d1, you must provide the Installation + Information in the manner specified by section 6 of the GNU GPL + for conveying Corresponding Source.) + + 5. Combined Libraries. + + You may place library facilities that are a work based on the +Library side by side in a single library together with other library +facilities that are not Applications and are not covered by this +License, and convey such a combined library under terms of your +choice, if you do both of the following: + + a) Accompany the combined library with a copy of the same work based + on the Library, uncombined with any other library facilities, + conveyed under the terms of this License. + + b) Give prominent notice with the combined library that part of it + is a work based on the Library, and explaining where to find the + accompanying uncombined form of the same work. + + 6. Revised Versions of the GNU Lesser General Public License. + + The Free Software Foundation may publish revised and/or new versions +of the GNU Lesser General Public License from time to time. Such new +versions will be similar in spirit to the present version, but may +differ in detail to address new problems or concerns. + + Each version is given a distinguishing version number. If the +Library as you received it specifies that a certain numbered version +of the GNU Lesser General Public License "or any later version" +applies to it, you have the option of following the terms and +conditions either of that published version or of any later version +published by the Free Software Foundation. If the Library as you +received it does not specify a version number of the GNU Lesser +General Public License, you may choose any version of the GNU Lesser +General Public License ever published by the Free Software Foundation. + + If the Library as you received it specifies that a proxy can decide +whether future versions of the GNU Lesser General Public License shall +apply, that proxy's public statement of acceptance of any version is +permanent authorization for you to choose that version for the +Library. diff --git a/README.md b/README.md index de84728..e69de29 100644 --- a/README.md +++ b/README.md @@ -1 +0,0 @@ -# DiodeIoT_SI-1108 \ No newline at end of file diff --git a/examples/button_relay_control/button_relay_control.ino b/examples/button_relay_control/button_relay_control.ino new file mode 100644 index 0000000..b1ff82c --- /dev/null +++ b/examples/button_relay_control/button_relay_control.ino @@ -0,0 +1,79 @@ +/** + @file button_relay_control.ino + + @brief Buton ile röle kontrol uygulaması. + + @details Bu örnekte kartın üzerinde bulunan buton ile röleleri sırası ile + açacağız. + + @authors Diode IoT Inc. + + @authors Kadir Sevil + + @copyright Copyright (c) 2021-2022 Diode Iot Inc. All rights reserved. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +/* + Kartın üzerindeki BOOT butonunu program içinde kendi amaçlarınız için kullanabilirsiniz. + Bu örnekte kartın üzerindeki BOOT butonuna her bastığınızda sırası ile röleler açılmaktadır. +*/ +#include + +// Kartımız için gerekli olan kütüphane headerını ekliyoruz. +#include "si1108.h" + +// Bu değer o anda açık olan rölenin kanal numarasını tutmaktadır. +// Rölelerin kanal numaralarını kartın ön yüzünde görebilirsiniz. +int current_button = 0; + +void setup(void) +{ + // Kartımızın gerekli olan başlangıç ayarlarını yapıyoruz. + si1108.init(); +} + +void loop(void) +{ + // Buton debounce için loop() fonksiyonunu bir döngü içerisinde çağırmalıyız. + // Eğer buton kullanılmayacaksa bu fonksiyonunu kullanmayabilirsiniz. + si1108.loop(); + + // Butona basılma durumunu isButtonPressed() fonksiyonu ile kontrol ediyoruz. + // Eğer fonksiyon true döndürüyorsa butona basılmış demektir. + // Eğer butona basıldıysa önceki röleyi bırak ve bir sonraki röleyi aç. + if(si1108.isButtonPressed()) + { + si1108.ledOn(); + delay(10); + si1108.ledOff(); + + // Önceki röleyi bırak. + si1108.setRelay(current_button, 0); + + if(current_button == 8) + { + current_button = 0; + } + else + { + current_button++; + } + + // Sonraki röleyi aç. + si1108.setRelay(current_button, 1); + } +} \ No newline at end of file diff --git a/examples/mqtt_relay_control/mqtt_relay_control.ino b/examples/mqtt_relay_control/mqtt_relay_control.ino new file mode 100644 index 0000000..3226e2a --- /dev/null +++ b/examples/mqtt_relay_control/mqtt_relay_control.ino @@ -0,0 +1,172 @@ +/** + @file mqtt_relay_control.ino + + @brief MQTT protokolü ile röle kontrol uygulaması. + + @details Bu örnekte kartın üzerindeki röleleri MQTT protokolü ile uzaktan kontrol edeceğiz. + + @authors Diode IoT Inc. + + @authors Kadir Sevil + + @copyright Copyright (c) 2021-2022 Diode Iot Inc. All rights reserved. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +/* + Bu örnekte MQTT ile kartın üzerindeki röleleri uzaktan kontrol ediyoruz. + 1. "WIFI_SSID" değişkenine WiFi'ınızın adını, "WIFI_PASSWORD" değişkenine WiFi'ınızın şifresini yazın. + 2. Örnek kodu derleyip karta yükleyin. + 3. Araçlar->Seri Port Ekranı ile seri konsolu açın. + 4. Seri konsolun sağ alt köşesinden haberleşme hızını "115200" bps yapın. + 5. Bilgisayarınıza herhangi bir MQTT client programı indirin. + 6. İndirdiğiniz MQTT client programında MQTT broker olarak test.mosquitto.org, MQTT broker port olarak 1883 girin. + 7. İndirdiğiniz MQTT client programından topic olarak SI1108-[mac adresi]/relay yazın. [mac adresi] alanı seri konsoldan görebileceğiz ESP32'nin mac adresi + olmalıdır. Örneğin SI1108-4C11AECCB9D0/relay + 8. Topic mesajı olarakta: + -> Herhangi bir röleyi açmak için "open" ve hemen yanına açmak istediğiniz rölenin kanal numarasını yazıp enter yapın. Örneğin "open1". + -> Herhangi bir röleyi kapatmak için "close" ve hemen yanına kapatmak istediğiniz rölenin kanal numarasını yazıp enter yapın. Örneğin "close1". +*/ +#include +#include +#include +#include + +// Kartımız için gerekli olan kütüphane headerını ekliyoruz. +#include "si1108.h" + +// WiFi'ınızın adı. +const char* WIFI_SSID = "ssid"; +// WiFi'ınızın şifresi. +const char* WIFI_PASSWORD = "password"; + +// MQTT client. +WiFiClient wifiClient; +PubSubClient mqttClient(wifiClient); + +// Bu fonksiyon ile ESP32'nin mac adresini alıyoruz. +String getMacAddress(void) +{ + uint8_t base_mac[6]; + char base_mac_str[13]; + + esp_read_mac(base_mac, ESP_MAC_WIFI_STA); + snprintf(base_mac_str, sizeof(base_mac_str), "%02X%02X%02X%02X%02X%02X", base_mac[0], base_mac[1], base_mac[2], base_mac[3], base_mac[4], base_mac[5]); + return String(base_mac_str); +} + +void mqtt_callback(char* topic, byte* payload, unsigned int length) +{ + String str = ""; + for(int i = 0; i < length; i++) + { + str += (char)payload[i]; + } + + str.trim(); + if(str.startsWith(String("open"))) + { + str.replace(String("open"), String("")); + str.trim(); + int ch = str.toInt(); + if(ch >= 1 && ch <= 8) + { + si1108.setRelay(ch, 1); + Serial.printf("[Info] Relay %d is opened\n", ch); + } + else + { + Serial.printf("[Error] Wrong parameter: \"%s\"!\n", str.c_str()); + } + } + else if(str.startsWith(String("close"))) + { + str.replace(String("close"), String("")); + str.trim(); + int ch = str.toInt(); + if(ch >= 1 && ch <= 8) + { + si1108.setRelay(ch, 0); + Serial.printf("[Info] Relay %d is closed\n", ch); + } + else + { + Serial.printf("[Error] Wrong parameter: \"%s\"!\n", str.c_str()); + } + } + else + { + Serial.printf("[Error] Wrong parameter: \"%s\"!\n", str.c_str()); + } +} + +void mqttConnect(void) +{ + Serial.printf("[Info] Connecting to MQTT Broker...\n"); + while(!mqttClient.connected()) + { + Serial.print("[Warning] Reconnecting to MQTT Broker...\n"); + String clientId = "SI1108-" + getMacAddress(); + + if(mqttClient.connect(clientId.c_str())) + { + Serial.printf("[Info] Connected\n"); + mqttClient.subscribe((clientId + String("/relay")).c_str()); + } + } +} + +void setup(void) +{ + // Seri haberleşmeyi 115200 bps ile başlatıyoruz. + Serial.begin(115200); + + Serial.printf("example started\n"); + Serial.printf("ESP32 mac address: %s\n", getMacAddress().c_str()); + + // Kartımızın gerekli olan başlangıç ayarlarını yapıyoruz. + si1108.init(); + + // WiFi'a bağlanıyoruz. + Serial.printf("[Info] Connecting to \"%s\":", WIFI_SSID); + WiFi.begin(WIFI_SSID, WIFI_PASSWORD); + while(WiFi.status() != WL_CONNECTED) + { + Serial.printf("->"); + delay(1000); + } + Serial.printf("\n[Info] Connected\n"); + + // MQTT client'ı ayarlıyoruz. + mqttClient.setServer("test.mosquitto.org", 1883); + mqttClient.setCallback(mqtt_callback); + + // MQTT broker'ına bağlanıyoruz. + mqttConnect(); +} + +void loop(void) +{ + // Eğer MQTT bağlantımız koparsa yeniden bağlanmayı deniyoruz. + if(!mqttClient.connected()) + { + Serial.printf("[Error] MQTT client disconnected!\n"); + mqttConnect(); + } + + // PubSubClient sınıfı senkron olduğundan gelen MQTT mesajlarından haberimizin olması için loop fonksiyonunu bir döngü içinde çağırıyoruz. + mqttClient.loop(); +} \ No newline at end of file diff --git a/examples/serial_terminal_relay_control/serial_terminal_relay_control.ino b/examples/serial_terminal_relay_control/serial_terminal_relay_control.ino new file mode 100644 index 0000000..2fdb7f1 --- /dev/null +++ b/examples/serial_terminal_relay_control/serial_terminal_relay_control.ino @@ -0,0 +1,99 @@ +/** + @file serial_terminal_relay_control.ino + + @brief Seri port ile röle kontrolü. + + @details Bu örnekte seri konsol ile kartın üzerindeki röleleri kontrol ediyoruz. + + @authors Diode IoT Inc. + + @authors Kadir Sevil + + @copyright Copyright (c) 2021-2022 Diode Iot Inc. All rights reserved. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +/* + Bu örnekte seri konsol ile kartın üzerindeki röleleri kontrol ediyoruz. + 1. Örneği karta yükleyin. + 2. Araçlar->Seri Port Ekranı ile seri konsolu açın. + 3. Seri konsolun sağ alt köşesinden haberleşme hızını "115200" bps yapın. + 4. Seri konsolun sağ alt köşesinden satır sonunu "Yeni Satır" olarak değiştirin. + 5. Herhangi bir röleyi açmak için "open" ve hemen yanına açmak istediğiniz rölenin kanal numarasını yazıp enter yapın. Örneğin "open1". + 6. Herhangi bir röleyi kapatmak için "close" ve hemen yanına kapatmak istediğiniz rölenin kanal numarasını yazıp enter yapın. Örneğin "close1". +*/ +#include + +// Kartımız için gerekli olan kütüphane headerını ekliyoruz. +#include "si1108.h" + +void setup(void) +{ + // Seri haberleşmeyi 115200 bps ile başlatıyoruz. + Serial.begin(115200); + + Serial.printf("example started\n"); + + // Kartımızın gerekli olan başlangıç ayarlarını yapıyoruz. + si1108.init(); +} + +void loop(void) +{ + // Burada seri konsoldan gelen verileri izliyoruz. + // Eğer gelen veri uygun formatta ise işlemi yerine gerip seri konsola onay mesajı gönderiyoruz, değil ise hata mesajı gönderiyoruz. + if(Serial.available() > 0) + { + delay(10); + String str = Serial.readStringUntil('\n'); + str.trim(); + + if(str.startsWith(String("open"))) + { + str.replace(String("open"), String("")); + str.trim(); + int ch = str.toInt(); + if(ch >= 1 && ch <= 8) + { + si1108.setRelay(ch, 1); + Serial.printf("[Info] Relay %d is opened\n", ch); + } + else + { + Serial.printf("[Error] Wrong parameter: \"%s\"!\n", str.c_str()); + } + } + else if(str.startsWith(String("close"))) + { + str.replace(String("close"), String("")); + str.trim(); + int ch = str.toInt(); + if(ch >= 1 && ch <= 8) + { + si1108.setRelay(ch, 0); + Serial.printf("[Info] Relay %d is closed\n", ch); + } + else + { + Serial.printf("[Error] Wrong parameter: \"%s\"!\n", str.c_str()); + } + } + else + { + Serial.printf("[Error] Wrong parameter: \"%s\"!\n", str.c_str()); + } + } +} \ No newline at end of file diff --git a/keywords.txt b/keywords.txt new file mode 100644 index 0000000..bfa02ba --- /dev/null +++ b/keywords.txt @@ -0,0 +1,14 @@ +SI1108 KEYWORD1 +si1108 KEYWORD1 +init KEYWORD2 +deinit KEYWORD2 +loop KEYWORD2 +ledSet KEYWORD2 +ledOn KEYWORD2 +ledOff KEYWORD2 +isButtonPressed KEYWORD2 +isButtonReleased KEYWORD2 +setRelay KEYWORD2 +getRelay KEYWORD2 +allOnRelay KEYWORD2 +allOffRelay KEYWORD2 diff --git a/library.properties b/library.properties new file mode 100644 index 0000000..5b1db18 --- /dev/null +++ b/library.properties @@ -0,0 +1,9 @@ +name=DiodeIoT_SI-1108 +version=1.0.0 +author= Diode IoT Inc. +maintainer=Kadir Sevil +sentence=SI-1108 library for Espressif MCUs +paragraph=SI-1108 library for Espressif MCUs +category=Other +url=https://github.com/diodeiot/DiodeIoT_SI-1108 +architectures=* diff --git a/src/si1108.cpp b/src/si1108.cpp new file mode 100644 index 0000000..c1cd66d --- /dev/null +++ b/src/si1108.cpp @@ -0,0 +1,278 @@ +/** + @file si1108.cpp + + @authors Diode IoT Inc. + + @authors Kadir Sevil + + @copyright Copyright (c) 2021-2022 Diode Iot Inc. All rights reserved. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#include "si1108.h" + +#define ARRLEN(x) ((sizeof(x)) / (sizeof(*x))) + +#define GET_STATE(x, y) ((!x) != (!y)) + +SI1108 si1108; + +const int SI1108::led[1][2] = {{2, HIGH}}; + +const int SI1108::button[1][2] = {{0, LOW}}; + +const int SI1108::ch_lookup[8][2] = {{5, LOW}, {17, LOW}, {16, LOW}, {4, LOW}, {25, LOW}, {26, LOW}, {27, LOW}, {14, LOW}}; + +SI1108::SI1108(void) +{ +} + +SI1108::~SI1108(void) +{ +} + +void SI1108::init(unsigned long debounce_time) +{ + this->debounce_time = debounce_time; + + previous_steady_state = digitalRead(button[0][0]); + last_steady_state = previous_steady_state; + last_fickle_state = previous_steady_state; + last_debounce_time = 0; + + digitalWrite(led[0][0], GET_STATE(led[0][1], LOW)); + pinMode(led[0][0], OUTPUT); + + pinMode(button[0][0], INPUT); + + for(int i = 0; i < ARRLEN(ch_lookup); i++) + { + digitalWrite(ch_lookup[i][0], GET_STATE(ch_lookup[i][1], LOW)); + pinMode(ch_lookup[i][0], OUTPUT); + } +} + +void SI1108::deinit(void) +{ + pinMode(led[0][0], INPUT); + + pinMode(button[0][0], INPUT); + + for(int i = 0; i < ARRLEN(ch_lookup); i++) + { + pinMode(ch_lookup[i][0], INPUT); + } +} + +void SI1108::loop(void) +{ + unsigned long current_time = millis(); + + int current_state = digitalRead(button[0][0]); + + if(current_state != last_fickle_state) + { + last_debounce_time = current_time; + last_fickle_state = current_state; + } + + if((current_time - last_debounce_time) >= debounce_time) + { + previous_steady_state = last_steady_state; + last_steady_state = current_state; + } +} + +void SI1108::ledSet(int state) +{ + digitalWrite(led[0][0], GET_STATE(led[0][1], state)); +} + +void SI1108::ledOn(void) +{ + ledSet(1); +} + +void SI1108::ledOff(void) +{ + ledSet(0); +} + +bool SI1108::isButtonPressed(void) +{ + return previous_steady_state == HIGH && last_steady_state == LOW; +} + +bool SI1108::isButtonReleased(void) +{ + return previous_steady_state == LOW && last_steady_state == HIGH; +} + +void SI1108::setRelay(int chNum, int state) +{ + if(chNum < 1 || chNum > ARRLEN(ch_lookup)) + { + return; + } + + digitalWrite(ch_lookup[chNum - 1][0], GET_STATE(ch_lookup[chNum - 1][1], state)); +} + +int SI1108::getRelay(int chNum) +{ + if(chNum < 1 || chNum > ARRLEN(ch_lookup)) + { + return -1; + } + + return GET_STATE(ch_lookup[chNum - 1][1], digitalRead(ch_lookup[chNum - 1][0])); +} + +void SI1108::allOnRelay(void) +{ + for(int i = 0; i < ARRLEN(ch_lookup); i++) + { + digitalWrite(ch_lookup[i][0], GET_STATE(ch_lookup[i][1], HIGH)); + } +} + +void SI1108::allOffRelay(void) +{ + for(int i = 0; i < ARRLEN(ch_lookup); i++) + { + digitalWrite(ch_lookup[i][0], GET_STATE(ch_lookup[i][1], LOW)); + } +} + +void SI1108::openRelay1(void) +{ + setRelay(1, HIGH); +} + +void SI1108::closeRelay1(void) +{ + setRelay(1, LOW); +} + +int SI1108::getRelay1(void) +{ + return getRelay(1); +} + +void SI1108::openRelay2(void) +{ + setRelay(2, HIGH); +} + +void SI1108::closeRelay2(void) +{ + setRelay(2, LOW); +} + +int SI1108::getRelay2(void) +{ + return getRelay(2); +} + +void SI1108::openRelay3(void) +{ + setRelay(3, HIGH); +} + +void SI1108::closeRelay3(void) +{ + setRelay(3, LOW); +} + +int SI1108::getRelay3(void) +{ + return getRelay(3); +} + +void SI1108::openRelay4(void) +{ + setRelay(4, HIGH); +} + +void SI1108::closeRelay4(void) +{ + setRelay(4, LOW); +} + +int SI1108::getRelay4(void) +{ + return getRelay(4); +} + +void SI1108::openRelay5(void) +{ + setRelay(5, HIGH); +} + +void SI1108::closeRelay5(void) +{ + setRelay(5, LOW); +} + +int SI1108::getRelay5(void) +{ + return getRelay(5); +} + +void SI1108::openRelay6(void) +{ + setRelay(6, HIGH); +} + +void SI1108::closeRelay6(void) +{ + setRelay(6, LOW); +} + +int SI1108::getRelay6(void) +{ + return getRelay(6); +} + +void SI1108::openRelay7(void) +{ + setRelay(7, HIGH); +} + +void SI1108::closeRelay7(void) +{ + setRelay(7, LOW); +} + +int SI1108::getRelay7(void) +{ + return getRelay(7); +} + +void SI1108::openRelay8(void) +{ + setRelay(8, HIGH); +} + +void SI1108::closeRelay8(void) +{ + setRelay(8, LOW); +} + +int SI1108::getRelay8(void) +{ + return getRelay(8); +} \ No newline at end of file diff --git a/src/si1108.h b/src/si1108.h new file mode 100644 index 0000000..2569157 --- /dev/null +++ b/src/si1108.h @@ -0,0 +1,287 @@ +/** + @file si1108.h + + @authors Diode IoT Inc. + + @authors Kadir Sevil + + @copyright Copyright (c) 2021-2022 Diode Iot Inc. All rights reserved. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#ifndef SI1108_H +#define SI1108_H + +#include + +/** + @class SI1108 + + @brief SI1108 geliştirme kartı sınıfı. +*/ +class SI1108 +{ + public: + SI1108(void); + + ~SI1108(void); + + /** + @brief Objeyi başlat. + + @param[in] debounce_time Kartın üzerinde bulunan BOOT butonunun ms cinsinden debounce süresi. Varsayılan değeri 50. + */ + void init(unsigned long debounce_time = 50); + + /** + @brief Objeyi sonlandır. + */ + void deinit(void); + + /** + @brief Kartın üzerinde bulunan BOOT butonu için debounce işlemlerini yerine getirir. Bir döngü içerisinde çağrılmalıdır. + */ + void loop(void); + + /** + @brief Kart üzerindeki ledi ayarla. + + @param[in] state 0: Led kapalı, 1: Led açık. + */ + void ledSet(int state); + + /** + @brief Kart üzerindeki ledi aç. + */ + void ledOn(void); + + /** + @brief Kart üzerindeki ledi kapat. + */ + void ledOff(void); + + /** + @brief Kartın üzerinde bulunan BOOT butonuna basılma durumunu kontrol eder. + + @retval true Butona basılmış. + + @retval false Butona basılmamış. + */ + bool isButtonPressed(void); + + /** + @brief Kartın üzerinde bulunan BOOT butonunu bırakma durumunu kontrol eder. + + @retval true Buton bırakılmış. + + @retval false Buton bırakılmamış. + */ + bool isButtonReleased(void); + + /** + @brief Röleyi açar ya da kapatır. + + @param[in] chNum Rölenin kanal numarası. + + @param[in] state 0: Kapalı, 1: Açık. + */ + void setRelay(int chNum, int state); + + /** + @brief Rölenin açık/kapalı durumunu döndürür. + + @param[in] chNum Rölenin kanal numarası. + + @retval 0 Röle kapalı. + @retval 1 Röle açık. + */ + int getRelay(int chNum); + + /** + @brief Tüm röleleri açar. + */ + void allOnRelay(void); + + /** + @brief Tüm röleleri kapatır. + */ + void allOffRelay(void); + + /** + @brief Röle1'i aç. + */ + void openRelay1(void); + + /** + @brief Röle1'i kapat. + */ + void closeRelay1(void); + + /** + @brief Röle1'in durumunu döndür. + + @retval 0 Röle kapalı. + @retval 1 Röle açık. + */ + int getRelay1(void); + + /** + @brief Röle2'yi aç. + */ + void openRelay2(void); + + /** + @brief Röle2'yi kapat. + */ + void closeRelay2(void); + + /** + @brief Röle2'in durumunu döndür. + + @retval 0 Röle kapalı. + @retval 1 Röle açık. + */ + int getRelay2(void); + + /** + @brief Röle3'ü aç. + */ + void openRelay3(void); + + /** + @brief Röle3'ü kapat. + */ + void closeRelay3(void); + + /** + @brief Röle3'ün durumunu döndür. + + @retval 0 Röle kapalı. + @retval 1 Röle açık. + */ + int getRelay3(void); + + /** + @brief Röle4'ü aç. + */ + void openRelay4(void); + + /** + @brief Röle4'ü kapat. + */ + void closeRelay4(void); + + /** + @brief Röle4'ün durumunu döndür. + + @retval 0 Röle kapalı. + @retval 1 Röle açık. + */ + int getRelay4(void); + + /** + @brief Röle5'i aç. + */ + void openRelay5(void); + + /** + @brief Röle5'i kapat. + */ + void closeRelay5(void); + + /** + @brief Röle5'in durumunu döndür. + + @retval 0 Röle kapalı. + @retval 1 Röle açık. + */ + int getRelay5(void); + + /** + @brief Röle6'yı aç. + */ + void openRelay6(void); + + /** + @brief Röle6'yı kapat. + */ + void closeRelay6(void); + + /** + @brief Röle6'nın durumunu döndür. + + @retval 0 Röle kapalı. + @retval 1 Röle açık. + */ + int getRelay6(void); + + /** + @brief Röle7'yi aç. + */ + void openRelay7(void); + + /** + @brief Röle7'yi kapat. + */ + void closeRelay7(void); + + /** + @brief Röle7'nin durumunu döndür. + + @retval 0 Röle kapalı. + @retval 1 Röle açık. + */ + int getRelay7(void); + + /** + @brief Röle8'i aç. + */ + void openRelay8(void); + + /** + @brief Röle8'i kapat. + */ + void closeRelay8(void); + + /** + @brief Röle8'in durumunu döndür. + + @retval 0 Röle kapalı. + @retval 1 Röle açık. + */ + int getRelay8(void); + + private: + unsigned long debounce_time; + + int previous_steady_state; + + int last_steady_state; + + int last_fickle_state; + + unsigned long last_debounce_time; + + const static int led[1][2]; + + const static int button[1][2]; + + const static int ch_lookup[8][2]; +}; + +extern SI1108 si1108; + +#endif /*SI1108_H*/ \ No newline at end of file