From a038b4f9875d06be339d3abb33967ec9a89c2f8a Mon Sep 17 00:00:00 2001 From: iperry Date: Fri, 8 Jan 2010 01:22:43 +0000 Subject: changed math.h to wiring_math.h to avoid collision with newlib's math library git-svn-id: https://leaflabs.googlecode.com/svn/trunk/library@99 749a229e-a60e-11de-b98f-4500b42dc123 --- Makefile | 2 +- src/main.cpp | 15 +++++++++------ src/wiring/math.cpp | 38 -------------------------------------- src/wiring/math.h | 30 ------------------------------ src/wiring/wiring_math.cpp | 38 ++++++++++++++++++++++++++++++++++++++ src/wiring/wiring_math.h | 32 ++++++++++++++++++++++++++++++++ 6 files changed, 80 insertions(+), 75 deletions(-) delete mode 100644 src/wiring/math.cpp delete mode 100644 src/wiring/math.h create mode 100644 src/wiring/wiring_math.cpp create mode 100644 src/wiring/wiring_math.h diff --git a/Makefile b/Makefile index b25a9b9..58678df 100644 --- a/Makefile +++ b/Makefile @@ -78,7 +78,7 @@ CSRC = lib/systick.c \ CSRC += $(STM32SRCS) -CPPSRC = wiring/math.cpp \ +CPPSRC = wiring/wiring_math.cpp \ wiring/Print.cpp \ wiring/comm/HardwareSerial.cpp \ wiring/comm/HardwareUsb.cpp \ diff --git a/src/main.cpp b/src/main.cpp index fd846ee..28a9b98 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,19 +1,22 @@ #include "wiring.h" #include "HardwareSerial.h" -#include "math.h" +#include "wiring_math.h" #include "usb.h" int ledPin = 13; int toggle=0; void setup() { - pinMode(ledPin,OUTPUT); +// pinMode(ledPin,OUTPUT); +// Serial2.begin(9600); } void loop() { - digitalWrite(ledPin,HIGH); - delay(200); - digitalWrite(ledPin,LOW); - delay(200); + asm volatile("nop"); +// digitalWrite(ledPin,HIGH); +// delay(200); +// digitalWrite(ledPin,LOW); +// delay(200); +// Serial2.println("Hello world"); } int main(void) { diff --git a/src/wiring/math.cpp b/src/wiring/math.cpp deleted file mode 100644 index 9be7dc3..0000000 --- a/src/wiring/math.cpp +++ /dev/null @@ -1,38 +0,0 @@ -#include -#include "math.h" - -/* from newlib: - * - * rand returns the next pseudo-random integer in sequence; it is a number - * between 0 and RAND_MAX (inclusive). - * - * srand does not return a result. */ - - -/* The rest copied from WMath.cpp */ -void randomSeed(unsigned int seed) { - if (seed != 0) { - srand(seed); - } -} - -long random(long howbig) { - if (howbig == 0) { - return 0; - } - return rand() % howbig; -} - -long random(long howsmall, long howbig) { - if (howsmall >= howbig) { - return howsmall; - } - long diff = howbig - howsmall; - return random(diff) + howsmall; -} - -long map(long x, long in_min, long in_max, long out_min, long out_max) { - return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min; -} - - diff --git a/src/wiring/math.h b/src/wiring/math.h deleted file mode 100644 index 8f30396..0000000 --- a/src/wiring/math.h +++ /dev/null @@ -1,30 +0,0 @@ -#ifndef _MATH_H_ -#define _MATH_H_ - -void randomSeed(unsigned int); -long random(long); -long random(long, long); -long map(long, long, long, long, long); - -#define PI 3.1415926535897932384626433832795 -#define HALF_PI 1.5707963267948966192313216916398 -#define TWO_PI 6.283185307179586476925286766559 -#define DEG_TO_RAD 0.017453292519943295769236907684886 -#define RAD_TO_DEG 57.295779513082320876798154814105 - -#define min(a,b) ((a)<(b)?(a):(b)) -#define max(a,b) ((a)>(b)?(a):(b)) -#define constrain(amt,low,high) ((amt)<(low)?(low):((amt)>(high)?(high):(amt))) -#define round(x) ((x)>=0?(long)((x)+0.5):(long)((x)-0.5)) -#define radians(deg) ((deg)*DEG_TO_RAD) -#define degrees(rad) ((rad)*RAD_TO_DEG) -#define sq(x) ((x)*(x)) - -/* undefine stdlib's abs if encountered */ -#ifdef abs -#undef abs -#endif -#define abs(x) (((x) > 0) ? (x) : -(unsigned)(x)) - -#endif - diff --git a/src/wiring/wiring_math.cpp b/src/wiring/wiring_math.cpp new file mode 100644 index 0000000..9be7dc3 --- /dev/null +++ b/src/wiring/wiring_math.cpp @@ -0,0 +1,38 @@ +#include +#include "math.h" + +/* from newlib: + * + * rand returns the next pseudo-random integer in sequence; it is a number + * between 0 and RAND_MAX (inclusive). + * + * srand does not return a result. */ + + +/* The rest copied from WMath.cpp */ +void randomSeed(unsigned int seed) { + if (seed != 0) { + srand(seed); + } +} + +long random(long howbig) { + if (howbig == 0) { + return 0; + } + return rand() % howbig; +} + +long random(long howsmall, long howbig) { + if (howsmall >= howbig) { + return howsmall; + } + long diff = howbig - howsmall; + return random(diff) + howsmall; +} + +long map(long x, long in_min, long in_max, long out_min, long out_max) { + return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min; +} + + diff --git a/src/wiring/wiring_math.h b/src/wiring/wiring_math.h new file mode 100644 index 0000000..f000bbd --- /dev/null +++ b/src/wiring/wiring_math.h @@ -0,0 +1,32 @@ +#ifndef _WIRING_MATH_H_ +#define _WIRING_MATH_H_ + +#include + +void randomSeed(unsigned int); +long random(long); +long random(long, long); +long map(long, long, long, long, long); + +#define PI 3.1415926535897932384626433832795 +#define HALF_PI 1.5707963267948966192313216916398 +#define TWO_PI 6.283185307179586476925286766559 +#define DEG_TO_RAD 0.017453292519943295769236907684886 +#define RAD_TO_DEG 57.295779513082320876798154814105 + +#define min(a,b) ((a)<(b)?(a):(b)) +#define max(a,b) ((a)>(b)?(a):(b)) +#define constrain(amt,low,high) ((amt)<(low)?(low):((amt)>(high)?(high):(amt))) +#define round(x) ((x)>=0?(long)((x)+0.5):(long)((x)-0.5)) +#define radians(deg) ((deg)*DEG_TO_RAD) +#define degrees(rad) ((rad)*RAD_TO_DEG) +#define sq(x) ((x)*(x)) + +/* undefine stdlib's abs if encountered */ +#ifdef abs +#undef abs +#endif +#define abs(x) (((x) > 0) ? (x) : -(unsigned)(x)) + +#endif + -- cgit v1.2.3