I'm currently working on a embedded system project and we are prototyping the hardware using an Arduino Uno. So far, we need to be able to get reliable temperature readings from a temperature sensor (TMP36) and I've managed to write a library/class for this specific sensor. You can find it here:
TMP36.h
#include <Arduino.h>
class TMP36
{
public:
TMP36(int pino);
float getTempC();
void setLimSup(float a);
void setLimInf(float a);
void testLimSup();
void testLimInf();
private:
float _limSup;
float _limInf;
int _pino;
float _tensao;
float getTensao();
};
TMP36.cpp
#include "Arduino.h"
#include "TMP36.h"
#include "ArduinoUnit.h"
TMP36::TMP36 (int pino)
{
_pino = pino;
}
float TMP36::getVoltage()
{
return (analogRead(_pino) * 0.004882814);
}
float TMP36::getTempC ()
{
_tensao = getVoltage();
return (_tensao - 0.5) * 100.0;
}
void TMP36::setLimSup(float a)
{
_limSup = a;
}
void TMP36::setLimInf(float a)
{
_limInf = a;
}
void TMP36::testeLimSup()
{
test(okLimSup)
{
float reading = getTempC();
AssertLessOrEqual(reading, _limSup);
}
}
void TMP36::testeLimInf()
{
test()
{
float reading = getTempC();
assertMoreOrEqual(reading, _limInf);
}
}
To be able to test if the getTempC is within the sensor range, I've been messing around with ArduinoUnit 2, but when compiling this code:
#include "TMP36.h"
TMP36 tmp36(0);
void setup() {
Serial.begin(9600);
}
void loop() {
float temp;
temp = tmp36.getTempC();
Serial.println(temp);
delay(1000);
}
on Arduino IDE I get the following errors:
In file included from /media/pedro/Storage/Linux/Arduino/arduino-1.6.11/libraries/TMP36/TMP36.cpp:3:0:
/media/pedro/Storage/Linux/Arduino/arduino-1.6.11/libraries/TMP36/TMP36.cpp: In member function 'void TMP36::testeLimSup()':
/media/pedro/Storage/Linux/Arduino/arduino-1.6.11/libraries/ArduinoUnit/ArduinoUnit.h:591:164: error: qualified-id in declaration before '(' token
#define test(name) struct test_ ## name : TestOnce { test_ ## name() : TestOnce(F(#name)) {}; void once(); } test_ ## name ## _instance; void test_ ## name :: once()
^
/media/pedro/Storage/Linux/Arduino/arduino-1.6.11/libraries/TMP36/TMP36.cpp:34:2: note: in expansion of macro 'test'
test(okLimSup)
^
/media/pedro/Storage/Linux/Arduino/arduino-1.6.11/libraries/TMP36/TMP36.cpp: In member function 'void TMP36::testeLimInf()':
/media/pedro/Storage/Linux/Arduino/arduino-1.6.11/libraries/ArduinoUnit/ArduinoUnit.h:591:164: error: qualified-id in declaration before '(' token
#define test(name) struct test_ ## name : TestOnce { test_ ## name() : TestOnce(F(#name)) {}; void once(); } test_ ## name ## _instance; void test_ ## name :: once()
^
/media/pedro/Storage/Linux/Arduino/arduino-1.6.11/libraries/TMP36/TMP36.cpp:45:2: note: in expansion of macro 'test'
test()
^
/media/pedro/Storage/Linux/Arduino/arduino-1.6.11/libraries/TMP36/TMP36.cpp:50:1: error: expected '}' at end of input
}
^
exit status 1
Error compiling for board Arduino/Genuino Uno.
Since this is my first time UnitTesting, I'm not quite sure what does errors mean, so I need help fixing them.
Thank you!
okLimSup? Clearly it is not something that can be used withtest(okLimSup)at least not the way it's being used, but without knowing whatokLimSupis, not much can be done.