-
Notifications
You must be signed in to change notification settings - Fork 120
/
RepRapFirmware.h
176 lines (137 loc) · 4.24 KB
/
RepRapFirmware.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
/****************************************************************************************************
RepRapFirmware - Main Include
This includes all the other include files in the right order and defines some globals.
No other definitions or information should be in here.
-----------------------------------------------------------------------------------------------------
Version 0.1
18 November 2012
Adrian Bowyer
RepRap Professional Ltd
http://reprappro.com
Licence: GPL
****************************************************************************************************/
#ifndef REPRAPFIRMWARE_H
#define REPRAPFIRMWARE_H
#include <cstddef> // for size_t
#include <cfloat>
#include <cstdarg>
// Module numbers and names, used for diagnostics and debug
enum Module
{
modulePlatform = 0,
moduleNetwork = 1,
moduleWebserver = 2,
moduleGcodes = 3,
moduleMove = 4,
moduleHeat = 5,
moduleDda = 6, // not yet implemented in zpl fork
modulePrintMonitor = 7,
noModule = 15
};
static const char *moduleName[] =
{
"Platform",
"Network",
"Webserver",
"GCodes",
"Move",
"Heat",
"DDA",
"PrintMonitor",
"?","?","?","?","?","?","?",
"none"
};
// Warn of what's to come, so we can use pointers to classes...
class Network;
class Platform;
class Webserver;
class GCodes;
class Move;
class Heat;
class Tool;
class PrintMonitor;
class RepRap;
class FileStore;
// A single instance of the RepRap class contains all the others
extern RepRap reprap;
// Functions and globals not part of any class
extern "C" void debugPrintf(const char* fmt, ...);
bool StringEndsWith(const char* string, const char* ending);
bool StringStartsWith(const char* string, const char* starting);
bool StringEquals(const char* s1, const char* s2);
int StringContains(const char* string, const char* match);
// Macro to give us the number of elements in an array
#define ARRAY_SIZE(_x) (sizeof(_x)/sizeof(_x[0]))
// Macro to give us the highest valid index into an array i.e. one less than the size
#define ARRAY_UPB(_x) (ARRAY_SIZE(_x) - 1)
// Macro to assign an array from an initializer list
#if __cplusplus >= 201103L
// This version relies on C++'11 features (add '-std=gnu++11' to your CPP compiler flags)
#define ARRAY_INIT(_dest, _init) {static const decltype(_dest) _temp = _init; memcpy(_dest, _temp, sizeof(_dest)); }
#else
// This version relies on a gcc extension that is available only in older compilers
#define ARRAY_INIT(_dest, _init) _dest = _init
#define nullptr (0)
#endif
// Class to describe a string buffer, including its length. This saves passing buffer lengths around everywhere.
class StringRef
{
char *p; // pointer to the storage
size_t len; // number of characters in the storage
public:
StringRef(char *pp, size_t pl) : p(pp), len(pl) { }
size_t Length() const { return len; }
size_t strlen() const;
char *Pointer() { return p; }
const char *Pointer() const { return p; }
char& operator[](size_t index) { return p[index]; }
char operator[](size_t index) const { return p[index]; }
void Clear() { p[0] = 0; }
int printf(const char *fmt, ...);
int vprintf(const char *fmt, va_list vargs);
int catf(const char *fmt, ...);
size_t copy(const char* src);
size_t cat(const char *src);
};
extern StringRef scratchString;
#include "Arduino.h"
#include "Configuration.h"
#include "Network.h"
#include "Platform.h"
#include "Webserver.h"
#include "GCodes.h"
#include "Move.h"
#include "Heat.h"
#include "Tool.h"
#include "PrintMonitor.h"
#include "Reprap.h"
// std::min and std::max don't seem to work with this variant of gcc, so define our own ones here
// We use these only with primitive types, so pass them directly instead of by const reference
#undef min
#undef max
template<class X> inline X min(X _a, X _b)
{
return (_a < _b) ? _a : _b;
}
template<class X> inline X max(X _a, X _b)
{
return (_a > _b) ? _a : _b;
}
// Specialisations for float and double to handle NANs properly
template<> inline float min(float _a, float _b)
{
return (isnan(_a) || _a < _b) ? _a : _b;
}
template<> inline float max(float _a, float _b)
{
return (isnan(_a) || _a > _b) ? _a : _b;
}
template<> inline double min(double _a, double _b)
{
return (isnan(_a) || _a < _b) ? _a : _b;
}
template<> inline double max(double _a, double _b)
{
return (isnan(_a) || _a > _b) ? _a : _b;
}
#endif