-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCalibration.cpp
46 lines (38 loc) · 956 Bytes
/
Calibration.cpp
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
#include "Arduino.h"
#include "Calibration.h"
#include <SdFat.h>
#include <math.h>
Calibration::Calibration(char* name){
strncpy(this->name, name, 5);
}
Calibration::~Calibration(){
}
const unsigned int LINE_SIZE = 64;
boolean Calibration::load(){
char filename[16];
strncpy(filename, this->name, 5);
strncat(filename, "cal.csv", 7);
Serial.println(filename);
char buffer[LINE_SIZE];
ifstream sdin(filename);
if(!sdin.is_open()){
this->order = 0;
return false;
}
char comma;
sdin >> this->order;
Serial.println(this->order);
for(int i=0; i <= this->order; ++i){
sdin >> comma;
sdin >> this->parameters[i];
Serial.println(this->parameters[i]);
}
return true;
}
float Calibration::adjustReading(float reading){
float calibratedValue = 0;
for(int i=0; i <= this->order; ++i){
calibratedValue += this->parameters[i] * pow(reading, (float)this->order-i);
}
return calibratedValue;
}