From f3d9ab9a982527bd707cc2a3392560b516a87361 Mon Sep 17 00:00:00 2001 From: Brett Hagman Date: Tue, 13 Aug 2013 15:58:55 -0400 Subject: [PATCH 1/2] Created a new branch for the next major release, including adding Properties to classes. --- ExampleLibrary.cpp | 24 +++++++++++------ ExampleLibrary.h | 27 ++++++++++--------- .../ExampleLibraryExample.pde | 8 +++++- 3 files changed, 38 insertions(+), 21 deletions(-) diff --git a/ExampleLibrary.cpp b/ExampleLibrary.cpp index 7a35e35..4dea46d 100644 --- a/ExampleLibrary.cpp +++ b/ExampleLibrary.cpp @@ -1,7 +1,7 @@ -/* $Id$ /* || @author Brett Hagman || @url http://wiring.org.co/ +|| @contribution Alexander Brevig || || @description || | Example Wiring Library @@ -20,10 +20,12 @@ || Constructor */ -ExampleLibrary::ExampleLibrary(int direction) -: total(0) +ExampleLibrary::ExampleLibrary(int value) +: increment(ExampleLibrary::incrementAssignSafteyGuard), // Prepare our ConstrainedProperty 'increment' + total(_total) // Prepare our ConstantProperty 'total' { - setIncrement(direction); + increment = 1; + increment = value; } @@ -33,9 +35,14 @@ ExampleLibrary::ExampleLibrary(int direction) void ExampleLibrary::doThatThing() { - total += increment; + _total += increment; - Serial.println(total, DEC); + Serial.println(_total, DEC); +} + +void ExampleLibrary::reset() +{ + _total = 0; } @@ -43,8 +50,9 @@ void ExampleLibrary::doThatThing() || Private Methods */ -void ExampleLibrary::setIncrement(int value) +bool ExampleLibrary::incrementAssignSafteyGuard(int value) { - increment = value; + // Accept any value except 0. + return value != 0; } diff --git a/ExampleLibrary.h b/ExampleLibrary.h index 93e1b9b..8dd4ff0 100644 --- a/ExampleLibrary.h +++ b/ExampleLibrary.h @@ -1,6 +1,7 @@ /* || @author Brett Hagman || @url http://wiring.org.co/ +|| @contribution Alexander Brevig || || @description || | Example Wiring Library @@ -15,7 +16,12 @@ #ifndef EXAMPLELIBRARY_H #define EXAMPLELIBRARY_H +#if WIRING < 200 + #error This library requires Wiring Framework 2.0.0+ +#endif + #include +#include "WProperty.h" /* || ExampleLibrary version @@ -26,14 +32,6 @@ #define EXAMPLELIBRARY_VERSION 10000 -/* -|| Public Constants -*/ - -static const int FORWARD = 1; -static const int BACKWARD = -1 - - /* || Class */ @@ -42,18 +40,23 @@ class ExampleLibrary { public: // Constructor - ExampleLibrary(int direction); + ExampleLibrary(int value = 1); // Methods void doThatThing(); + void reset(); + + // Properties + ConstrainedProperty increment; + ConstantProperty total; private: // Methods - void setIncrement(int value); + static bool incrementAssignSafteyGuard(int value); // Members - int increment; - int total; + int _increment; + int _total; }; diff --git a/examples/ExampleLibraryExample/ExampleLibraryExample.pde b/examples/ExampleLibraryExample/ExampleLibraryExample.pde index d99f881..3c61134 100644 --- a/examples/ExampleLibraryExample/ExampleLibraryExample.pde +++ b/examples/ExampleLibraryExample/ExampleLibraryExample.pde @@ -1,6 +1,7 @@ /* || @author Brett Hagman || @url http://wiring.org.co/ +|| @contribution Alexander Brevig || || @description || | An Example for the Example Wiring Library @@ -14,7 +15,7 @@ #include -ExampleLibrary widget = ExampleLibrary(FORWARD); +ExampleLibrary widget = ExampleLibrary(); void setup() @@ -29,5 +30,10 @@ void loop() { widget.doThatThing(); + if (widget.total <= 0) + widget.increment = 1; + if (widget.total >= 10) + widget.increment = -1; + delay(500); } From a338ad617a16de2467e36414aaafa7a19ca505e0 Mon Sep 17 00:00:00 2001 From: Brett Hagman Date: Tue, 13 Aug 2013 16:48:24 -0400 Subject: [PATCH 2/2] Minor changes. --- ExampleLibrary.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ExampleLibrary.h b/ExampleLibrary.h index 8dd4ff0..9310521 100644 --- a/ExampleLibrary.h +++ b/ExampleLibrary.h @@ -21,15 +21,16 @@ #endif #include +// This is temporary, as WProperty.h will be included from Wiring.h #include "WProperty.h" /* || ExampleLibrary version -|| @Version 1.0.0 +|| @Version 2.0.0 */ -// Version below is 1 00 00 (integer representation of above) -#define EXAMPLELIBRARY_VERSION 10000 +// Version below is 2 00 00 (integer representation of above) +#define EXAMPLELIBRARY_VERSION 20000 /* @@ -55,7 +56,6 @@ class ExampleLibrary static bool incrementAssignSafteyGuard(int value); // Members - int _increment; int _total; };