Skip to content

Commit 7297c96

Browse files
committed
OneWireNg_CurrentPlatform added
1 parent b5ce865 commit 7297c96

4 files changed

Lines changed: 49 additions & 8 deletions

File tree

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,13 @@ GPIO activities details).
9898
Platform classes have a public constructor allowing to create 1-wire service for
9999
a 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

103110
Refer to `examples` directory for usage details. For API details refer to sources

examples/Dallas_Temperature/Dallas_Temperature.ino

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
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

@@ -47,9 +47,9 @@
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

5555
static void printId(const OneWireNg::Id& id)

src/OneWireNg_ArduinoESP8266.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff 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)

src/OneWireNg_CurrentPlatform.h

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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 */

0 commit comments

Comments
 (0)