fix signed unsigned warnings
This commit is contained in:
parent
d048c44b75
commit
75b720f564
|
@ -19,3 +19,4 @@ lib_deps=
|
||||||
bogde/HX711@^0.7.5
|
bogde/HX711@^0.7.5
|
||||||
marcoschwartz/LiquidCrystal_I2C@^1.1.4
|
marcoschwartz/LiquidCrystal_I2C@^1.1.4
|
||||||
https://github.com/arduino-libraries/Servo
|
https://github.com/arduino-libraries/Servo
|
||||||
|
https://github.com/emilv/ArduinoSort/
|
105
src/main.cpp
105
src/main.cpp
|
@ -6,6 +6,7 @@
|
||||||
#include <EEPROM.h>
|
#include <EEPROM.h>
|
||||||
#include <Wire.h>
|
#include <Wire.h>
|
||||||
#include <LiquidCrystal_I2C.h>
|
#include <LiquidCrystal_I2C.h>
|
||||||
|
#include <ArduinoSort.h>
|
||||||
|
|
||||||
#define EEPROMVERSION 1
|
#define EEPROMVERSION 1
|
||||||
|
|
||||||
|
@ -82,10 +83,10 @@ String receivedString ="";
|
||||||
|
|
||||||
char tempstring[16]; //for dtostrf
|
char tempstring[16]; //for dtostrf
|
||||||
|
|
||||||
long time_lastlcd=0;
|
unsigned long time_lastlcd=0;
|
||||||
long looptimelcd_margin=0; //if >0 loop took longer than expected
|
unsigned long looptimelcd_margin=0; //if >0 loop took longer than expected
|
||||||
uint8_t fps=DEFAULT_FPS; //EEPROM
|
uint8_t fps=DEFAULT_FPS; //EEPROM
|
||||||
long time_lcdwait=1000/fps;
|
unsigned long time_lcdwait=1000/fps;
|
||||||
String lcd0=""; //lcd line 0
|
String lcd0=""; //lcd line 0
|
||||||
String lcd1=""; // " 1
|
String lcd1=""; // " 1
|
||||||
#define LCD_BACKLIGHT_TIME 20000
|
#define LCD_BACKLIGHT_TIME 20000
|
||||||
|
@ -96,17 +97,18 @@ uint32_t lcd_backlight_offtimer=0;
|
||||||
String lcd0_buffer="";
|
String lcd0_buffer="";
|
||||||
String lcd1_buffer="";
|
String lcd1_buffer="";
|
||||||
|
|
||||||
long time_lastadc=0;
|
unsigned long time_lastadc=0;
|
||||||
long looptimeadc_margin=0;
|
unsigned long looptimeadc_margin=0;
|
||||||
uint8_t spsadc=DEFAULT_SPSADC; //eeprom
|
uint8_t spsadc=DEFAULT_SPSADC; //eeprom
|
||||||
long time_adcwait=1000/spsadc;
|
unsigned long time_adcwait=1000/spsadc;
|
||||||
int adc_readings=1; //ca. 700ms for 5 readings, ca 75ms for 1 reading, readings=1 10times = 747ms
|
int adc_readings=1; //ca. 700ms for 5 readings, ca 75ms for 1 reading, readings=1 10times = 747ms
|
||||||
|
|
||||||
double weight=0;
|
double weight=0;
|
||||||
#define ADCMEDIANVALUES_MAX 31 //needs to be uneven, maximum number, for array declaration
|
#define ADCMEDIANVALUES_MAX 31 //needs to be uneven, maximum number, for array declaration
|
||||||
double weightseries[ADCMEDIANVALUES_MAX]; //last n values for median filter
|
float weightseries[ADCMEDIANVALUES_MAX]; //last n values for median filter
|
||||||
int adcmedianvalues=DEFAULT_ADCMEDIANVALUES; //needs to be uneven //eeprom
|
uint16_t adcmedianvalues=DEFAULT_ADCMEDIANVALUES; //needs to be uneven //eeprom
|
||||||
int adcmedianposition=0;
|
float adcFilterKeepMedianvaluesFactor=0.8; //how many lowest and highest values will be removed from the array before avaraging (as factor). 0.0 means only median is used. 1.0 means all values are used.
|
||||||
|
uint16_t adcmedianposition=0;
|
||||||
|
|
||||||
float calibrationWeight=100; //gramms
|
float calibrationWeight=100; //gramms
|
||||||
|
|
||||||
|
@ -170,11 +172,12 @@ String toString(double w,uint8_t dec);
|
||||||
String toString(double w);
|
String toString(double w);
|
||||||
String toWeightString(double w,uint8_t dec,uint8_t len);
|
String toWeightString(double w,uint8_t dec,uint8_t len);
|
||||||
String toWeightString(double w);
|
String toWeightString(double w);
|
||||||
double getWeightSeriesMax();
|
float getWeightSeriesMax();
|
||||||
double getWeightSeriesMin();
|
float getWeightSeriesMin();
|
||||||
double getWeightMedian();
|
double getWeightMedian();
|
||||||
double getVoltage();
|
double getWeightFiltered();
|
||||||
double getCurrent();
|
float getVoltage();
|
||||||
|
float getCurrent();
|
||||||
String menuentry_string();
|
String menuentry_string();
|
||||||
void menuentry_set(uint8_t presstype);
|
void menuentry_set(uint8_t presstype);
|
||||||
void menuentry_back(uint8_t presstype);
|
void menuentry_back(uint8_t presstype);
|
||||||
|
@ -311,7 +314,8 @@ void loop() {
|
||||||
}
|
}
|
||||||
lcd0=toStringBar(weight,0,1000);
|
lcd0=toStringBar(weight,0,1000);
|
||||||
//lcd1=toWeightString(weight)+"g";
|
//lcd1=toWeightString(weight)+"g";
|
||||||
lcd1=toWeightString(getWeightMedian())+"g";
|
//lcd1=toWeightString(getWeightMedian())+"g";
|
||||||
|
lcd1=toWeightString(getWeightFiltered())+"g";
|
||||||
|
|
||||||
//___
|
//___
|
||||||
if (btn_back_press==2){ //press BACK to tare
|
if (btn_back_press==2){ //press BACK to tare
|
||||||
|
@ -883,7 +887,7 @@ String menuentry_string(){ //second line string if entry selected
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
double getCurrent()
|
float getCurrent()
|
||||||
{
|
{
|
||||||
uint16_t _current=0;
|
uint16_t _current=0;
|
||||||
for (uint8_t i=0;i<N_CURRENTREADINGS;i++){
|
for (uint8_t i=0;i<N_CURRENTREADINGS;i++){
|
||||||
|
@ -893,7 +897,7 @@ double getCurrent()
|
||||||
return _current*CURRENTMULTIPLIER+0.00001;
|
return _current*CURRENTMULTIPLIER+0.00001;
|
||||||
}
|
}
|
||||||
|
|
||||||
double getVoltage()
|
float getVoltage()
|
||||||
{
|
{
|
||||||
return analogRead(PIN_VOLTAGE)*VOLTAGEMULTIPLIER+0.00001;
|
return analogRead(PIN_VOLTAGE)*VOLTAGEMULTIPLIER+0.00001;
|
||||||
}
|
}
|
||||||
|
@ -901,14 +905,14 @@ double getVoltage()
|
||||||
double getWeightMedian() //return median weight from weightseries
|
double getWeightMedian() //return median weight from weightseries
|
||||||
{
|
{
|
||||||
boolean mask[adcmedianvalues]; //true=disabled value
|
boolean mask[adcmedianvalues]; //true=disabled value
|
||||||
for (int i=0;i<adcmedianvalues;i++)
|
for (uint16_t i=0;i<adcmedianvalues;i++)
|
||||||
mask[i]=false;
|
mask[i]=false;
|
||||||
double cmin=MAXDOUBLEVALUE; int cmin_i=0;
|
float cmin=MAXDOUBLEVALUE; uint16_t cmin_i=0;
|
||||||
double cmax=0; int cmax_i=0;
|
float cmax=0; uint16_t cmax_i=0;
|
||||||
while(cmin!=cmax){ //stop when only one value left
|
while(cmin!=cmax){ //stop when only one value left
|
||||||
cmin=MAXDOUBLEVALUE;
|
cmin=MAXDOUBLEVALUE;
|
||||||
cmax=-MAXDOUBLEVALUE-1;
|
cmax=-MAXDOUBLEVALUE-1;
|
||||||
for (int i=0;i<adcmedianvalues;i++){
|
for (uint16_t i=0;i<adcmedianvalues;i++){
|
||||||
if (!mask[i]){
|
if (!mask[i]){
|
||||||
if (weightseries[i]<cmin){
|
if (weightseries[i]<cmin){
|
||||||
cmin=weightseries[i];
|
cmin=weightseries[i];
|
||||||
|
@ -927,19 +931,64 @@ double getWeightMedian() //return median weight from weightseries
|
||||||
return cmax;
|
return cmax;
|
||||||
}
|
}
|
||||||
|
|
||||||
double getWeightSeriesMin()
|
double getWeightFiltered() {
|
||||||
|
boolean mask[adcmedianvalues]; //true=disabled value
|
||||||
|
for (uint16_t i=0;i<adcmedianvalues;i++)
|
||||||
|
mask[i]=false;
|
||||||
|
float cmin=MAXDOUBLEVALUE; uint16_t cmin_i=0;
|
||||||
|
float cmax=0; uint16_t cmax_i=0;
|
||||||
|
//while(cmin!=cmax){ //stop when only one value left
|
||||||
|
uint16_t _valuesLeft=adcmedianvalues;
|
||||||
|
|
||||||
|
|
||||||
|
while (_valuesLeft>2 && _valuesLeft>(uint16_t)(adcmedianvalues*adcFilterKeepMedianvaluesFactor))
|
||||||
{
|
{
|
||||||
double cmin=MAXDOUBLEVALUE;
|
cmin=MAXDOUBLEVALUE;
|
||||||
for (int i=0;i<adcmedianvalues;i++){
|
cmax=-MAXDOUBLEVALUE-1;
|
||||||
|
for (uint16_t i=0;i<adcmedianvalues;i++){
|
||||||
|
if (!mask[i]){
|
||||||
|
if (weightseries[i]<cmin){
|
||||||
|
cmin=weightseries[i];
|
||||||
|
cmin_i=i;
|
||||||
|
}
|
||||||
|
if (weightseries[i]>cmax){
|
||||||
|
cmax=weightseries[i];
|
||||||
|
cmax_i=i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
mask[cmin_i]=true;
|
||||||
|
mask[cmax_i]=true;
|
||||||
|
_valuesLeft-=2; //2 values have been masked out
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
double sum=0;
|
||||||
|
uint16_t meanvalues=0;
|
||||||
|
for (uint16_t i=0;i<adcmedianvalues;i++){
|
||||||
|
if (!mask[i]) { //not masked out
|
||||||
|
sum+=weightseries[i];
|
||||||
|
meanvalues++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return sum/meanvalues;
|
||||||
|
}
|
||||||
|
|
||||||
|
float getWeightSeriesMin()
|
||||||
|
{
|
||||||
|
float cmin=MAXDOUBLEVALUE;
|
||||||
|
for (uint16_t i=0;i<adcmedianvalues;i++){
|
||||||
if (weightseries[i]<cmin)
|
if (weightseries[i]<cmin)
|
||||||
cmin=weightseries[i];
|
cmin=weightseries[i];
|
||||||
}
|
}
|
||||||
return cmin;
|
return cmin;
|
||||||
}
|
}
|
||||||
double getWeightSeriesMax()
|
float getWeightSeriesMax()
|
||||||
{
|
{
|
||||||
double cmax=0;
|
float cmax=0;
|
||||||
for (int i=0;i<adcmedianvalues;i++){
|
for (uint16_t i=0;i<adcmedianvalues;i++){
|
||||||
if (weightseries[i]>cmax)
|
if (weightseries[i]>cmax)
|
||||||
cmax=weightseries[i];
|
cmax=weightseries[i];
|
||||||
}
|
}
|
||||||
|
@ -1087,7 +1136,7 @@ uint16_t EEPROMReadInt(uint8_t paddr){
|
||||||
void EEPROMWriteDouble(int ee, double value)
|
void EEPROMWriteDouble(int ee, double value)
|
||||||
{
|
{
|
||||||
byte* p = (byte*)(void*)&value;
|
byte* p = (byte*)(void*)&value;
|
||||||
for (int i = 0; i < sizeof(value); i++)
|
for (uint16_t i = 0; i < sizeof(value); i++)
|
||||||
EEPROM.write(ee++, *p++);
|
EEPROM.write(ee++, *p++);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1095,7 +1144,7 @@ double EEPROMReadDouble(int ee)
|
||||||
{
|
{
|
||||||
double value = 0.0;
|
double value = 0.0;
|
||||||
byte* p = (byte*)(void*)&value;
|
byte* p = (byte*)(void*)&value;
|
||||||
for (int i = 0; i < sizeof(value); i++)
|
for (uint16_t i = 0; i < sizeof(value); i++)
|
||||||
*p++ = EEPROM.read(ee++);
|
*p++ = EEPROM.read(ee++);
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue