Qualia  0.2
Arduino.h
Go to the documentation of this file.
1 
6 #ifndef Arduino_Compat_h
7 #define Arduino_Compat_h
8 
9 #include <qualia/core/common.h>
10 
11 #if !is_arduino()
12 
13 #include <stdlib.h>
14 #include <string.h>
15 #include <math.h>
16 
17 #if is_avr()
18 #include "new.h"
19 #endif
20 
21 #include "binary.h"
22 
23 #ifndef true
24  #define true 0x1
25 #endif
26 
27 #ifndef false
28  #define false 0x0
29 #endif
30 
31 #define PI 3.1415926535897932384626433832795
32 #define HALF_PI 1.5707963267948966192313216916398
33 #define TWO_PI 6.283185307179586476925286766559
34 #define DEG_TO_RAD 0.017453292519943295769236907684886
35 #define RAD_TO_DEG 57.295779513082320876798154814105
36 
37 #ifdef __GNUC__
38  // min/max are undefined in bits/c++config.h so we define them as templates
39  // note that this might yield different results than what you will get on Arduino (which uses macros)
40  template<typename T> T min(T a, T b) { return a < b ? a : b; }
41  template<typename T> T max(T a, T b) { return a > b ? a : b; }
42 #else
43  #define min(a,b) ((a)<(b)?(a):(b))
44  #define max(a,b) ((a)>(b)?(a):(b))
45 #endif
46 
47 #ifndef WIN32
48  #ifdef abs
49  #undef abs
50  #endif
51  #define abs(x) ((x)>=0?(x):-(x))
52 #endif
53 
54 #define constrain(amt,low,high) ((amt)<(low)?(low):((amt)>(high)?(high):(amt)))
55 #define round(x) ((x)>=0?(long)((x)+0.5):(long)((x)-0.5))
56 #define radians(deg) ((deg)*DEG_TO_RAD)
57 #define degrees(rad) ((rad)*RAD_TO_DEG)
58 #define sq(x) ((x)*(x))
59 
60 #define lowByte(w) ((uint8_t) ((w) & 0xff))
61 #define highByte(w) ((uint8_t) ((w) >> 8))
62 
63 #define bitRead(value, bit) (((value) >> (bit)) & 0x01)
64 #define bitSet(value, bit) ((value) |= (1UL << (bit)))
65 #define bitClear(value, bit) ((value) &= ~(1UL << (bit)))
66 #define bitWrite(value, bit, bitvalue) (bitvalue ? bitSet(value, bit) : bitClear(value, bit))
67 
68 typedef unsigned int word;
69 
70 #define bit(b) (1UL << (b))
71 
72 typedef uint8_t boolean;
73 typedef uint8_t byte;
74 
75 #ifdef __cplusplus
76 extern "C"{
77 #endif
78 
79 unsigned long millis(void);
80 unsigned long micros(void);
81 void delay(unsigned long);
82 void delayMicroseconds(unsigned int us);
83 
84 #ifdef __cplusplus
85 } // extern "C"
86 #endif
87 
88 
89 #ifdef __cplusplus
90 
91 #include "Stream.h" // in replacement of #include "HardwareSerial.h"
92 
93 // WMath prototypes
94 
95 uint16_t makeWord(uint16_t w);
96 uint16_t makeWord(byte h, byte l);
97 
98 #define word(...) makeWord(__VA_ARGS__)
99 
100 long random(long);
101 long random(long, long);
102 void randomSeed(unsigned int);
103 long map(long, long, long, long, long);
104 
105 #endif
106 
107 #if is_computer()
108 // PROGMEM PSTR() macro compat
109 #define PSTR(x) (x)
110 #endif
111 
112 #endif // !is_arduino()
113 
114 #endif