File tree Expand file tree Collapse file tree
examples/Dallas_Temperature Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -98,6 +98,13 @@ GPIO activities details).
9898Platform classes have a public constructor allowing to create 1-wire service for
9999a particular platform (see [ above] ( #architecture-details ) ).
100100
101+ NOTE: For the convenience there has been provided ` OneWireNg_CurrentPlatform.h `
102+ header which tries to detect platform the compilation is proceeded and:
103+ * include proper platform class header,
104+ * assign ` OneWireNg_CurrentPlatform ` macro-define to the detected platform class.
105+
106+ Refer to ` examples/Dallas_Temperature ` example for the usage details.
107+
101108## Usage
102109
103110Refer to ` examples ` directory for usage details. For API details refer to sources
Original file line number Diff line number Diff line change 1010 * See the License for more information.
1111 */
1212
13- #include " OneWireNg_ArduinoAVR .h"
13+ #include " OneWireNg_CurrentPlatform .h"
1414
1515#define OW_PIN 10
1616
4747 (NULL ))))))
4848
4949#ifdef PWR_CTRL_PIN
50- static OneWireNg *ow = new OneWireNg_ArduinoAVR (OW_PIN, PWR_CTRL_PIN, false );
50+ static OneWireNg *ow = new OneWireNg_CurrentPlatform (OW_PIN, PWR_CTRL_PIN, false );
5151#else
52- static OneWireNg *ow = new OneWireNg_ArduinoAVR (OW_PIN, false );
52+ static OneWireNg *ow = new OneWireNg_CurrentPlatform (OW_PIN, false );
5353#endif
5454
5555static void printId (const OneWireNg::Id& id)
Original file line number Diff line number Diff line change @@ -63,8 +63,8 @@ class OneWireNg_ArduinoESP8266: public OneWireNg_BitBang
6363 OneWireNg_ArduinoESP8266 (unsigned pin, bool pullUp):
6464 OneWireNg_BitBang (false )
6565 {
66- assert (pin >= 0 && pin <= 16 );
67- assert (pullup && pin < 16 );
66+ assert (pin <= 16 );
67+ assert (pullUp && pin < 16 );
6868
6969 _dtaPin = pin;
7070 initDtaGpio (pullUp);
@@ -88,8 +88,8 @@ class OneWireNg_ArduinoESP8266: public OneWireNg_BitBang
8888 OneWireNg_ArduinoESP8266 (unsigned pin, unsigned pwrCtrlPin, bool pullUp):
8989 OneWireNg_BitBang (true )
9090 {
91- assert (pin >= 0 && pin <= 16 && pwrCtrlPin >= 0 && pwrCtrlPin <= 16 );
92- assert (pullup && pin < 16 );
91+ assert (pin <= 16 && pwrCtrlPin <= 16 );
92+ assert (pullUp && pin < 16 );
9393
9494 _dtaPin = pin;
9595 _pwrCtrlPin = pwrCtrlPin;
@@ -102,7 +102,7 @@ class OneWireNg_ArduinoESP8266: public OneWireNg_BitBang
102102 virtual int readGpioIn (GpioType gpio)
103103 {
104104 UNUSED (gpio);
105- return __READ_GPIO (pin );
105+ return __READ_GPIO (_dtaPin );
106106 }
107107
108108 virtual void writeGpioOut (GpioType gpio, int state)
Original file line number Diff line number Diff line change 1+ /*
2+ * Copyright (c) 2019 Piotr Stolarz
3+ * OneWireNg: Ardiono 1-wire service library
4+ *
5+ * Distributed under the 2-clause BSD License (the License)
6+ * see accompanying file LICENSE for details.
7+ *
8+ * This software is distributed WITHOUT ANY WARRANTY; without even the
9+ * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10+ * See the License for more information.
11+ */
12+
13+ #ifndef OneWireNg_CurrentPlatform
14+
15+ /*
16+ * Try to detect current platform by inspecting the environment and:
17+ * - include proper platform class header,
18+ * - assign OneWireNg_CurrentPlatform macro-define to the detected platform class.
19+ */
20+ #if defined(ARDUINO_ARCH_AVR )
21+ # include "OneWireNg_ArduinoAVR.h"
22+ # define OneWireNg_CurrentPlatform OneWireNg_ArduinoAVR
23+ #elif defined(ARDUINO_ARCH_MEGAAVR )
24+ # include "OneWireNg_ArduinoMegaAVR.h"
25+ # define OneWireNg_CurrentPlatform OneWireNg_ArduinoMegaAVR
26+ #elif defined(ARDUINO_ARCH_ESP8266 )
27+ # include "OneWireNg_ArduinoESP8266.h"
28+ # define OneWireNg_CurrentPlatform OneWireNg_ArduinoESP8266
29+ #else
30+ # define OneWireNg_CurrentPlatform
31+ # warning "Can't detect platform. Use proper class for the platform you are compiling for!"
32+ #endif
33+
34+ #endif /* OneWireNg_CurrentPlatform */
You can’t perform that action at this time.
0 commit comments