diff --git a/src/ExtendedSerial.h b/src/ExtendedSerial.h
new file mode 100644
index 0000000..d3432ef
--- /dev/null
+++ b/src/ExtendedSerial.h
@@ -0,0 +1,164 @@
+//-----------------------------------------------------------------------------
+// Decorator for Arduino's Stream class, which is a/o implemented by Serial
+//-----------------------------------------------------------------------------
+//
+// Copyright (C) 2018 Arend Lammertink
+//
+// This library is free software; you can redistribute it and/or modify it
+// under the terms of the GNU Lesser General Public License as published by
+// the Free Software Foundation, version 3.
+//
+// This library is distributed in the hope that it will be useful, but WITHOUT
+// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+// FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+// for more details.
+//
+// You should have received a copy of the GNU Lesser General Public License
+// along with this library. If not, see .
+//
+//-----------------------------------------------------------------------------
+//
+//
+// Description:
+//
+// The Serial class in Arduino is derived from the Stream class, which on it's
+// turn is derived from the Print class. In these, there is no support for
+// reading/writing integers or floats in binary form.
+//
+// In order to add this functionality, we use the Decorator pattern:
+//
+// https://cpppatterns.com/patterns/decorator.html
+//
+// The ExtendedSerial class is derived from the Stream class and thus
+// implements all methods which are present in the Stream class, while it adds
+// a number of new methods to send and receive values in binary format as well
+// as support for printing Fix16 fixed point numbers. Also, all the methods
+// from the HardwareSerial class are implemented.
+//
+// It can be instantiated using an existing ExtendedSerial instance, such as
+// Serial, Serial1, etc:
+//
+// ExtentedSerial mySerial(Serial);
+//
+// It can then be used just like any other Serial, like:
+//
+// mySerial.begin(9600);
+// mySerial.println("Hello, world!");
+//
+// In additon to the standard methods, one can also send and receive ints,
+// floats and Fix16s in binary format. Both the send and receive methods
+// return the number of bytes transferred. For example:
+//
+// float f=1.23;
+// mySerial.send(f);
+//
+// float g;
+// if( !mySerial.receive(g) ) { mySerial.println("No data available"); }
+//
+//-----------------------------------------------------------------------------
+
+//-----------------------------------------------------------------------------
+// Multi-include protection
+//-----------------------------------------------------------------------------
+
+#ifndef _EXTENDED_SERIAL_H
+#define _EXTENDED_SERIAL_H
+
+//-----------------------------------------------------------------------------
+// Includes
+//-----------------------------------------------------------------------------
+
+#include
+#include
+
+//-----------------------------------------------------------------------------
+// ExtendedSerial class
+//-----------------------------------------------------------------------------
+
+class ExtendedSerial : public Stream
+{
+
+ public:
+ ExtendedSerial(HardwareSerial& s) : _s(s) {}
+
+ // Methods delegated to existing Serial instance
+ void begin(unsigned long baud) { begin(baud, SERIAL_8N1); }
+ void begin(unsigned long b, uint8_t m) { _s.begin(b,m); }
+ void end() { _s.end(); }
+ virtual int available(void) { return _s.available(); }
+ virtual int peek(void) { return _s.peek(); }
+ virtual int read(void) { return _s.read(); }
+ virtual void flush(void) { return _s.flush(); }
+ virtual size_t write(uint8_t n) { return _s.write(n); }
+ virtual size_t write(const uint8_t* b,size_t sz) { return _s.write(b,sz); }
+ inline size_t write(unsigned long n) { return write((uint8_t)n); }
+ inline size_t write(long n) { return write((uint8_t)n); }
+ inline size_t write(unsigned int n) { return write((uint8_t)n); }
+ inline size_t write(int n) { return write((uint8_t)n); }
+ virtual int availableForWrite(void) { return _s.availableForWrite(); }
+ operator bool() { return true; }
+
+ // Extra methods
+ size_t print( Fix16 f, int d = 2) { return print( (double)f,d); }
+ size_t println(Fix16 f, int d = 2) { return println((double)f,d); }
+
+ size_t receive(uint8_t* buf, size_t sz)
+ {
+ if( available() < sz ) return 0;
+
+ for( int i=0; i
#include "interpolate.h"
#include "toString.h"
+#include "ExtendedSerial.h"
#ifdef AVR
#include
@@ -104,19 +105,30 @@
class Map
{
public:
- virtual int memSize() const =0;
+ virtual int memSize() const =0;
-#ifdef AVR
+ virtual bool updateEeprom(uint8_t* dest) const =0;
+ virtual bool readEeprom( const uint8_t* src) =0;
- virtual bool updateEeprom(uint8_t* dest) const =0;
- virtual bool readEeprom(const uint8_t* src) =0;
+ virtual void printTo( Print& p, const uint8_t tabsize = 4,
+ const char delim = ' ' )=0;
-#endif
+ virtual void sendTo( ExtendedSerial& s) =0;
+
+ void initReceive( uint16_t offset, size_t nr_bytes)
+ { bytesToReceive=nr_bytes; bytesReceived=0; curOffset=offset; }
+
+ bool receiveDone()
+ { return bytesReceived >= bytesToReceive; }
+
+ virtual bool receiveFrom( ExtendedSerial& s)
+ { return receiveDone(); }
- virtual void printTo( Print& p, const uint8_t tabsize = 4,
- const char delim = ' ') =0;
+ protected:
-// virtual void printBinaryTo( Print& p)
+ size_t bytesToReceive;
+ size_t bytesReceived;
+ uint16_t curOffset;
};
@@ -134,33 +146,31 @@ class Map2D : public Map
for( int i=0; i(xss[i]); }
- }
+ for( int i=0; i(xss[i]); }
+ }
- int getXInt( int i ) { return 0<=i(xs[i]) : 0; }
+ int getXInt( int i ) { return 0<=i(xs[i]) : 0; }
- float getXFloat( int i ) { return 0<=i(xs[i]) : 0; }
+ float getXFloat( int i ) { return 0<=i(xs[i]) : 0; }
- void setYs( const Y* yss )
- { memcpy( ys, yss, S*sizeof(Y) ); }
+ void setYs( const Y* yss ) { memcpy( ys, yss, S*sizeof(Y) ); }
void setYsFromFloat( const float* yss )
{
for( int i=0; i(yss[i]); }
}
- int getYInt( int i ) { return 0<=i(ys[i]) : 0; }
+ int getYInt( int i ) { return 0<=i(ys[i]) : 0; }
- float getYFloat( int i ) { return 0<=i(ys[i]) : 0; }
+ float getYFloat( int i ) { return 0<=i(ys[i]) : 0; }
#ifdef AVR
@@ -169,7 +179,7 @@ class Map2D : public Map
if( !eeprom_is_ready() ) return false;
eeprom_update_block( xs, dest, sizeof(xs) );
- eeprom_update_block( ys, dest+sizeof(xs), sizeof(ys) );
+ eeprom_update_block( ys, dest+ sizeof(xs), sizeof(ys) );
return true;
}
@@ -179,7 +189,7 @@ class Map2D : public Map
if( !eeprom_is_ready() ) return false;
eeprom_read_block( xs, src, sizeof(xs) );
- eeprom_read_block( ys, src+sizeof(xs), sizeof(ys) );
+ eeprom_read_block( ys, src+ sizeof(xs), sizeof(ys) );
return true;
}
@@ -187,8 +197,7 @@ class Map2D : public Map
#ifdef ARDUINO // Initialization from array in PROGMEM
- void setXs_P( const X* xss )
- { memcpy_P( xs, xss, S*sizeof(X) ); }
+ void setXs_P( const X* xss ) { memcpy_P( xs, xss, S*sizeof(X) ); }
void setXsFromFloat_P( const float* xss )
{
@@ -196,9 +205,8 @@ class Map2D : public Map
xs[i] = static_cast(pgm_read_float_near(xss+i)); }
}
- void setYs_P( const Y* yss )
- { memcpy_P( ys, yss, S*sizeof(Y) ); }
-
+ void setYs_P( const Y* yss ) { memcpy_P( ys, yss, S*sizeof(Y) ); }
+
void setYsFromFloat_P( const float* yss )
{
for( int i=0; i= bytesToReceive
+ }
+
Y f( X x ) // approximate f(x)
{
@@ -266,28 +306,28 @@ class Map2D : public Map
// 3D lookup table / fuel map. X axis must be sorted in ascending order.
//-----------------------------------------------------------------------------
-template // R,S: size, X,Y: data type
+template // R,C: size, X,Y: data type
class Map3D : public Map
{
public:
Map3D()
{
for( int i=0; i(xss[i]); }
+ for( int i=0; i(xss[i]); }
}
- int getX1Int( int i ) { return 0<=i(x1s[i]) : 0; }
- int getX2Int( int i ) { return 0<=i(x2s[i]) : 0; }
+ int getX1Int( int i ) { return 0<=i(x1s[i]) : 0; }
+ int getX2Int( int i ) { return 0<=i(x2s[i]) : 0; }
- float getX1Float( int i ) { return 0<=i(x1s[i]) : 0; }
- float getX2Float( int i ) { return 0<=i(x2s[i]) : 0; }
+ float getX1Float( int i ) { return 0<=i(x1s[i]) : 0; }
+ float getX2Float( int i ) { return 0<=i(x2s[i]) : 0; }
void setYs( const Y* yss )
- { memcpy( ys, yss, R*S*sizeof(Y) ); }
-
+ { memcpy( ys, yss, R*C*sizeof(Y) ); }
void setYsFromFloat( const float* yss )
{
- for( int i=0; i(yss[i]); }
}
int getYInt( int i, int j )
- { return 0<=i(ys[i][j]) : 0; }
+ { return 0<=i(ys[i][j]) : 0; }
float getYFloat( int i, int j )
- { return 0<=i(ys[i][j]) : 0; }
-
-#ifdef AVR
+ { return 0<=i(ys[i][j]) : 0; }
virtual bool updateEeprom(uint8_t* dest) const
{
@@ -344,15 +381,11 @@ class Map3D : public Map
return true;
}
-#endif
#ifdef ARDUINO // Initialize from array in PROGMEM
- void setX1s_P( const X* x1ss )
- { memcpy_P( x1s, x1ss, R*sizeof(X) ); }
-
- void setX2s_P( const X* x2ss )
- { memcpy_P( x2s, x2ss, S*sizeof(X) ); }
+ void setX1s_P( const X* x1ss ) { memcpy_P( x1s, x1ss, R*sizeof(X) ); }
+ void setX2s_P( const X* x2ss ) { memcpy_P( x2s, x2ss, C*sizeof(X) ); }
void setX1sFromFloat_P( const float* xss )
{
@@ -362,42 +395,41 @@ class Map3D : public Map
void setX2sFromFloat_P( const float* xss )
{
- for( int i=0; i(pgm_read_float_near(xss+i)); }
}
- void setYs_P( const Y* yss )
- { memcpy_P( ys, yss, R*S*sizeof(Y) ); }
+ void setYs_P( const Y* yss ) { memcpy_P( ys, yss, R*C*sizeof(Y) ); }
void setYsFromFloat_P( const float* yss )
{
- for( int i=0; i( pgm_read_float_near(yss+i) ); }
}
#endif
- void printTo( Print& p, const uint8_t tabsize = 4, const char delim = ' ')
+ virtual void printTo( Print& p, const uint8_t tabsize = 4, const char delim = ' ' )
{
const char spaceChar=' ';
-
+
// p.println( table title ); // TODO
p.println();
- for (int y = 0; y < x2Size(); y++)
+ for( int x = 0; x < R; x++ )
{
- const char* _x2 = toString(x2s[y]);
+ const char* _x1 = toString(x1s[x]);
- for( uint16_t idx=0; idx=0; x--) // TS likes rows in reverse order
+ {
+ for (int y = 0; y < C; x++)
+ { s.send( ys[x][y] ); }
+ }
+ }
+
+ virtual bool receiveFrom( ExtendedSerial& s)
+ {
+ const size_t x1end = R*sizeof(X);
+ const size_t x2end = x1end + C*sizeof(X);
+ const size_t yend = x2end + R*C*sizeof(Y);
+
+ while( (curOffset < x1end) && !receiveDone() )
+ {
+ int idx = curOffset / sizeof(X);
+
+ size_t recvd = s.receive(x1s[idx]);
+
+ if( recvd) { curOffset += recvd; }
+ else return false; // avoid infinite loop when we receive nothing.
+ }
+
+ while( (curOffset < x2end) && !receiveDone() )
+ {
+ int idx = (curOffset - x1end) / sizeof(X);
+
+ size_t recvd = s.receive(x2s[idx]);
+
+ if( recvd) { curOffset += recvd; }
+ else return false; // avoid infinite loop when we receive nothing.
+ }
+
+ while( (curOffset < yend) && !receiveDone() )
+ {
+ int idx = (curOffset - x2end) / sizeof(Y);
+
+ //int idx1 = idx/C;
+ int idx1 = R - 1 - idx/C; // TS likes the rows in reverse order
+ int idx2 = idx%C;
+
+ size_t recvd = s.receive(ys[idx1][idx2]);
+
+ if( recvd) { curOffset += recvd; }
+ else return false; // avoid infinite loop when we receive nothing.
+ }
+
+ return receiveDone(); // bytesReceived >= bytesToReceive
+ }
+
Y f( X x1, X x2 )
{
if (x1 < x1s[0]) { x1 = x1s[0]; } // minimum
if (x1 > x1s[R-1]) { x1 = x1s[R-1]; } // maximum
if (x2 < x2s[0]) { x2 = x2s[0]; } // minimum
- if (x2 > x2s[S-1]) { x2 = x2s[S-1]; } // maximum
+ if (x2 > x2s[C-1]) { x2 = x2s[C-1]; } // maximum
int i=0, j=R-1, m;
@@ -436,7 +524,7 @@ class Map3D : public Map
else j = m;
}
- int k=S-1;
+ int k=C-1;
j=0;
// find j, such that x2s[j] <= x2 < x2s[k] using bisection
@@ -454,9 +542,9 @@ class Map3D : public Map
protected:
- X x1s[S];
- X x2s[S];
- Y ys[R][S];
+ X x1s[R];
+ X x2s[C];
+ Y ys[R][C];
};
diff --git a/src/examples/test2d/test2d.ino b/src/examples/test2d/test2d.ino
index 0073b91..69b12ae 100644
--- a/src/examples/test2d/test2d.ino
+++ b/src/examples/test2d/test2d.ino
@@ -29,7 +29,7 @@
using namespace std;
-#define BAUDRATE 9600
+#define BAUDRATE 115200
// Stuff needed for printing
FILE serial_stdout;
@@ -103,8 +103,11 @@ void setup()
Map2D<8, int16_t, int8_t> testInt8;
testInt8.setXs_P(xs);
testInt8.setYs_P(ys8);
+ testInt8.printTo( Serial );
testInt8.updateEeprom(0);
+ testInt8.printTo( Serial );
testInt8.readEeprom(0);
+ testInt8.printTo( Serial );
Map2D<8, int16_t, Fix16> testFix16;
testFix16.setXs_P(xs);
diff --git a/src/gen_spec1D.py b/src/gen_spec1D.py
index 67fa8ec..b6a5ca8 100755
--- a/src/gen_spec1D.py
+++ b/src/gen_spec1D.py
@@ -1,25 +1,12 @@
#!/usr/bin/python
-print "//-----------------------------------------------------------------------------"
-print "//"
-print "// Copyright (C) 2018 Arend Lammertink"
-print "//"
-print "// This program is free software; you can redistribute it and/or modify it"
-print "// under the terms of the GNU General Public License as published by the Free"
-print "// Software Foundation, version 3."
-print "//"
-print "// This program is distributed in the hope that it will be useful, but WITHOUT"
-print "// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or"
-print "// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for"
-print "// more details."
-print "//"
-print "// You should have received a copy of the GNU Lesser General Public License"
-print "// along with this program. If not, see ."
-print "//-----------------------------------------------------------------------------"
-print
-print"//-----------------------------------------------------------------------------"
+from utils import *
+
+print inc_header
+
+print sep
print"// 1D specialization for integers by casting to Fix16, generated by script "
-print"//-----------------------------------------------------------------------------"
+print sep
print
print
diff --git a/src/gen_spec2D.py b/src/gen_spec2D.py
index 60b3540..9f3da3c 100755
--- a/src/gen_spec2D.py
+++ b/src/gen_spec2D.py
@@ -1,25 +1,12 @@
#!/usr/bin/python
-print "//-----------------------------------------------------------------------------"
-print "//"
-print "// Copyright (C) 2018 Arend Lammertink"
-print "//"
-print "// This program is free software; you can redistribute it and/or modify it"
-print "// under the terms of the GNU General Public License as published by the Free"
-print "// Software Foundation, version 3."
-print "//"
-print "// This program is distributed in the hope that it will be useful, but WITHOUT"
-print "// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or"
-print "// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for"
-print "// more details."
-print "//"
-print "// You should have received a copy of the GNU Lesser General Public License"
-print "// along with this program. If not, see ."
-print "//-----------------------------------------------------------------------------"
-print
-print"//-----------------------------------------------------------------------------"
+from utils import *
+
+print inc_header
+
+print sep
print"// 2D specialization for integers by casting to Fix16, generated by script."
-print"//-----------------------------------------------------------------------------"
+print sep
print
print
diff --git a/src/interpol1d_spec.h b/src/interpol1d_spec.h
index 796243c..8f98b38 100644
--- a/src/interpol1d_spec.h
+++ b/src/interpol1d_spec.h
@@ -2,17 +2,18 @@
//
// Copyright (C) 2018 Arend Lammertink
//
-// This program is free software; you can redistribute it and/or modify it
-// under the terms of the GNU General Public License as published by the Free
-// Software Foundation, version 3.
+// This library is free software; you can redistribute it and/or modify it
+// under the terms of the GNU Lesser General Public License as published by
+// the Free Software Foundation, version 3.
//
-// This program is distributed in the hope that it will be useful, but WITHOUT
+// This library is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
-// more details.
+// FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+// for more details.
//
// You should have received a copy of the GNU Lesser General Public License
-// along with this program. If not, see .
+// along with this library. If not, see .
+//
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
diff --git a/src/interpol2d_spec.h b/src/interpol2d_spec.h
index be660b6..1eb7a64 100644
--- a/src/interpol2d_spec.h
+++ b/src/interpol2d_spec.h
@@ -2,17 +2,18 @@
//
// Copyright (C) 2018 Arend Lammertink
//
-// This program is free software; you can redistribute it and/or modify it
-// under the terms of the GNU General Public License as published by the Free
-// Software Foundation, version 3.
+// This library is free software; you can redistribute it and/or modify it
+// under the terms of the GNU Lesser General Public License as published by
+// the Free Software Foundation, version 3.
//
-// This program is distributed in the hope that it will be useful, but WITHOUT
+// This library is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
-// more details.
+// FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+// for more details.
//
// You should have received a copy of the GNU Lesser General Public License
-// along with this program. If not, see .
+// along with this library. If not, see .
+//
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
@@ -23,299 +24,464 @@
#ifndef _interpol2d_spec_h
#define _interpol2d_spec_h
+template<>
inline int8_t interpolate( int8_t x1, int8_t x2,
int8_t x_1, int8_t x_2, int8_t x_3, int8_t x_4,
int8_t y_1, int8_t y_2, int8_t y_3, int8_t y_4 )
{
- return static_cast< int16_t >(
- interpolate( static_cast(x1),
- static_cast(x2),
- static_cast(x_1),
- static_cast(x_2),
- static_cast(x_3),
- static_cast(x_4),
- static_cast(y_1),
- static_cast(y_2),
- static_cast(y_3),
- static_cast(y_4) ));
+#ifdef DEBUG
+ Fix16 retval = (
+#else
+ return static_cast(static_cast(
+#endif
+ interpolate( static_cast(static_cast(x1)),
+ static_cast(static_cast(x2)),
+ static_cast(static_cast(x_1)),
+ static_cast(static_cast(x_2)),
+ static_cast(static_cast(x_3)),
+ static_cast(static_cast(x_4)),
+ static_cast(static_cast(y_1)),
+ static_cast(static_cast(y_2)),
+ static_cast(static_cast(y_3)),
+ static_cast(static_cast(y_4)) )
+#ifndef DEBUG
+ ));
+#else
+ return static_cast(static_cast(retval));
+#endif
}
+template<>
inline uint8_t interpolate( int8_t x1, int8_t x2,
int8_t x_1, int8_t x_2, int8_t x_3, int8_t x_4,
uint8_t y_1, uint8_t y_2, uint8_t y_3, uint8_t y_4 )
{
- return static_cast< int16_t >(
- interpolate( static_cast(x1),
- static_cast(x2),
- static_cast(x_1),
- static_cast(x_2),
- static_cast(x_3),
- static_cast(x_4),
- static_cast(y_1),
- static_cast(y_2),
- static_cast(y_3),
- static_cast(y_4) ));
+#ifdef DEBUG
+ Fix16 retval = (
+#else
+ return static_cast(static_cast(
+#endif
+ interpolate( static_cast(static_cast(x1)),
+ static_cast(static_cast(x2)),
+ static_cast(static_cast(x_1)),
+ static_cast(static_cast(x_2)),
+ static_cast(static_cast(x_3)),
+ static_cast(static_cast(x_4)),
+ static_cast(static_cast(y_1)),
+ static_cast(static_cast(y_2)),
+ static_cast(static_cast(y_3)),
+ static_cast(static_cast(y_4)) )
+#ifndef DEBUG
+ ));
+#else
+ return static_cast(static_cast(retval));
+#endif
}
+template<>
inline int16_t interpolate( int8_t x1, int8_t x2,
int8_t x_1, int8_t x_2, int8_t x_3, int8_t x_4,
int16_t y_1, int16_t y_2, int16_t y_3, int16_t y_4 )
{
- return static_cast< int16_t >(
- interpolate( static_cast(x1),
- static_cast(x2),
- static_cast(x_1),
- static_cast(x_2),
- static_cast(x_3),
- static_cast(x_4),
+#ifdef DEBUG
+ Fix16 retval = (
+#else
+ return static_cast(
+#endif
+ interpolate( static_cast(static_cast(x1)),
+ static_cast(static_cast(x2)),
+ static_cast(static_cast(x_1)),
+ static_cast(static_cast(x_2)),
+ static_cast(static_cast(x_3)),
+ static_cast(static_cast(x_4)),
static_cast(y_1),
static_cast(y_2),
static_cast(y_3),
- static_cast(y_4) ));
+ static_cast(y_4) )
+#ifndef DEBUG
+ );
+#else
+ return static_cast(retval);
+#endif
}
+template<>
inline uint16_t interpolate( int8_t x1, int8_t x2,
int8_t x_1, int8_t x_2, int8_t x_3, int8_t x_4,
uint16_t y_1, uint16_t y_2, uint16_t y_3, uint16_t y_4 )
{
- return static_cast< int32_t >(
- interpolate( static_cast(x1),
- static_cast(x2),
- static_cast(x_1),
- static_cast(x_2),
- static_cast(x_3),
- static_cast(x_4),
+#ifdef DEBUG
+ Fix16 retval = (
+#else
+ return static_cast(static_cast(
+#endif
+ interpolate( static_cast(static_cast(x1)),
+ static_cast(static_cast(x2)),
+ static_cast(static_cast(x_1)),
+ static_cast(static_cast(x_2)),
+ static_cast(static_cast(x_3)),
+ static_cast(static_cast(x_4)),
static_cast(static_cast(y_1)),
static_cast(static_cast(y_2)),
static_cast(static_cast(y_3)),
- static_cast(static_cast(y_4)) ));
+ static_cast(static_cast(y_4)) )
+#ifndef DEBUG
+ ));
+#else
+ return static_cast(static_cast(retval));
+#endif
}
+template<>
inline Fix16 interpolate( int8_t x1, int8_t x2,
int8_t x_1, int8_t x_2, int8_t x_3, int8_t x_4,
Fix16 y_1, Fix16 y_2, Fix16 y_3, Fix16 y_4 )
{
- return static_cast< Fix16 >(
- interpolate( static_cast(x1),
- static_cast(x2),
- static_cast(x_1),
- static_cast(x_2),
- static_cast(x_3),
- static_cast(x_4),
- static_cast(y_1),
- static_cast(y_2),
- static_cast(y_3),
- static_cast(y_4) ));
+#ifdef DEBUG
+ Fix16 retval = (
+#else
+ return
+#endif
+ interpolate( static_cast(static_cast(x1)),
+ static_cast(static_cast(x2)),
+ static_cast(static_cast(x_1)),
+ static_cast(static_cast(x_2)),
+ static_cast(static_cast(x_3)),
+ static_cast(static_cast(x_4)),
+ y_1,
+ y_2,
+ y_3,
+ y_4 )
+#ifndef DEBUG
+ ;
+#else
+ return retval;
+#endif
}
+template<>
inline float interpolate( int8_t x1, int8_t x2,
int8_t x_1, int8_t x_2, int8_t x_3, int8_t x_4,
float y_1, float y_2, float y_3, float y_4 )
{
- return static_cast< float >(
+#ifdef DEBUG
+ float retval = (
+#else
+ return
+#endif
interpolate( static_cast(x1),
static_cast(x2),
static_cast(x_1),
static_cast(x_2),
static_cast(x_3),
static_cast(x_4),
- static_cast(y_1),
- static_cast(y_2),
- static_cast(y_3),
- static_cast(y_4) ));
+ y_1,
+ y_2,
+ y_3,
+ y_4 )
+#ifndef DEBUG
+ ;
+#else
+ return retval;
+#endif
}
+template<>
inline double interpolate( int8_t x1, int8_t x2,
int8_t x_1, int8_t x_2, int8_t x_3, int8_t x_4,
double y_1, double y_2, double y_3, double y_4 )
{
- return static_cast< double >(
+#ifdef DEBUG
+ double retval = (
+#else
+ return
+#endif
interpolate( static_cast(x1),
static_cast(x2),
static_cast(x_1),
static_cast(x_2),
static_cast(x_3),
static_cast(x_4),
- static_cast(y_1),
- static_cast(y_2),
- static_cast(y_3),
- static_cast(y_4) ));
+ y_1,
+ y_2,
+ y_3,
+ y_4 )
+#ifndef DEBUG
+ ;
+#else
+ return retval;
+#endif
}
+template<>
inline int8_t interpolate( uint8_t x1, uint8_t x2,
uint8_t x_1, uint8_t x_2, uint8_t x_3, uint8_t x_4,
int8_t y_1, int8_t y_2, int8_t y_3, int8_t y_4 )
{
- return static_cast< int16_t >(
- interpolate( static_cast(x1),
- static_cast(x2),
- static_cast(x_1),
- static_cast(x_2),
- static_cast(x_3),
- static_cast(x_4),
- static_cast(y_1),
- static_cast(y_2),
- static_cast(y_3),
- static_cast(y_4) ));
+#ifdef DEBUG
+ Fix16 retval = (
+#else
+ return static_cast(static_cast(
+#endif
+ interpolate( static_cast(static_cast(x1)),
+ static_cast(static_cast(x2)),
+ static_cast(static_cast(x_1)),
+ static_cast(static_cast(x_2)),
+ static_cast(static_cast(x_3)),
+ static_cast(static_cast(x_4)),
+ static_cast(static_cast(y_1)),
+ static_cast(static_cast(y_2)),
+ static_cast(static_cast(y_3)),
+ static_cast(static_cast(y_4)) )
+#ifndef DEBUG
+ ));
+#else
+ return static_cast(static_cast(retval));
+#endif
}
+template<>
inline uint8_t interpolate( uint8_t x1, uint8_t x2,
uint8_t x_1, uint8_t x_2, uint8_t x_3, uint8_t x_4,
uint8_t y_1, uint8_t y_2, uint8_t y_3, uint8_t y_4 )
{
- return static_cast< int16_t >(
- interpolate( static_cast(x1),
- static_cast(x2),
- static_cast(x_1),
- static_cast(x_2),
- static_cast(x_3),
- static_cast(x_4),
- static_cast(y_1),
- static_cast(y_2),
- static_cast(y_3),
- static_cast(y_4) ));
+#ifdef DEBUG
+ Fix16 retval = (
+#else
+ return static_cast(static_cast(
+#endif
+ interpolate( static_cast(static_cast(x1)),
+ static_cast(static_cast(x2)),
+ static_cast