Skip to content

Commit

Permalink
integer value for settings
Browse files Browse the repository at this point in the history
  • Loading branch information
vitotai committed Feb 8, 2024
1 parent 8ce9038 commit 121aa46
Show file tree
Hide file tree
Showing 44 changed files with 30,560 additions and 30,535 deletions.
4 changes: 2 additions & 2 deletions docs/C1.BrewNCalibrate.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
After version 4.4, the calibration data survives through brews. If "Calculated by BPL" is enabled, the polynomial will be derived by the calibration data input. At least two sets of calibration data should be input to get correct formula. If only one set of data is availble, use "offset" option.
After version 4.4, the calibration data survives through brews. The maximum number of calibration pairs is 10.

When starting a log, the calibration data available will be written into the log file, so that tilt angles are recorded and gravity can be derived from the tilt angles. Otherwise, gravity data is recorded.

The calculated gravity is always temperature corrected. When inputing new data from main page, corrected gravity will be calculated automatically if beer temperature is available. However, no temperature correction if calibration data is input at "gravity device" page.
The calculated gravity is always temperature corrected. When inputing new data from main page, corrected gravity will be calculated automatically if beer temperature is available. However, no temperature correction is available if calibration data is input at "gravity device" page.
6 changes: 5 additions & 1 deletion docs/D1.RaptPillHydrometerSupport.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,8 @@ Pill broadcasts gravity and tilt angle related information, which make it possib
![Pill setup](image/pill_setup.jpg)


The MAC address used for registration and displayed on Rapt Pill's Dianostics page is calculated by taking the RAPT Pill's BLE address and subtracting 2 off the last octet. Therefore, thare are TWO addresses displayed.
The MAC address used for registration and displayed on Rapt Pill's Dianostics page is calculated by taking the RAPT Pill's BLE address and subtracting 2 off the last octet. Therefore, thare are TWO addresses displayed.

To find out Pills, click "Scan" button. The Pills don't broadcast all the time but wakeup and broadcast for a short period according its setting, like one or 15 minutes. It might take some time to "catch" the Pill, wait until the Pill shows up.

Pills report gravity as well as tilt information. If "Calculated by BPL" is enabled, the gravity is derived from the tilt information. Otherwise, the gravity from Pills will be used. The offset will be added to reported gravity. If "Calculated by BPL" is enabled, at least two sets of calibration data is necessary to derive a formula. Before a valid formula is available, no gravity data will be reported. The calibratin data will survives through brews. If the center of mass of the Pill is altered when opened for charging, the calibration data should be removed manually.
21 changes: 8 additions & 13 deletions src/BPLSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -374,17 +374,15 @@ bool BPLSettings::dejsonGravityConfig(char* json)
}

JsonArray calpts = root[KeyCalibrationPoints].as<JsonArray>();
int i=0;
int numpt=0;
for(JsonVariant v : calpts) {
JsonArray point=v.as<JsonArray>();
float raw = point[0].as<float>();
float sg = point[1].as<float>();
gdc->calPoints[i].raw=(gdc->gravityDeviceType == GravityDeviceTilt)?
SGToSetting(raw):AngleToSetting(raw);
gdc->calPoints[i].calsg=gdc->usePlato? PlatoToSetting(sg):SGToSetting(sg);
i++;
gdc->calPoints[numpt].raw= point[0].as<int>();
gdc->calPoints[numpt].calsg= point[1].as<int>();
numpt++;
if(numpt >= MaxNumberCalibrationPoints) break;
}
gdc->numCalPoints = calpts.size();
gdc->numCalPoints = numpt;


#if SupportTiltHydrometer
Expand Down Expand Up @@ -443,11 +441,8 @@ String BPLSettings::jsonGravityConfig(void){
JsonArray points = root.createNestedArray(KeyCalibrationPoints);
for(int i=0;i< gdc->numCalPoints;i++){
JsonArray point= points.createNestedArray();
float raw=(gdc->gravityDeviceType == GravityDeviceTilt)?
SGFromSetting(gdc->calPoints[i].raw):AngleFromSetting(gdc->calPoints[i].raw);
float gravity= gdc->usePlato? PlatoFromSetting(gdc->calPoints[i].calsg):SGFromSetting(gdc->calPoints[i].calsg);
point.add(raw);
point.add(gravity);
point.add(gdc->calPoints[i].raw);
point.add(gdc->calPoints[i].calsg);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/BPLSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ typedef struct _TimeInformation{

#define AngleFromSetting(a) ((float)(a) /100.0)
#define AngleToSetting(a) ((uint16_t)((a) * 100.0))

#define MaxNumberCalibrationPoints 10

typedef struct _CalibrationPoint{
uint16_t raw;
Expand All @@ -70,7 +70,7 @@ typedef struct _GravityDeviceConfiguration{
uint8_t stableThreshold;
uint8_t usePlato;
uint8_t _padding[6];
CalibrationPoint calPoints[10];
CalibrationPoint calPoints[MaxNumberCalibrationPoints];
uint8_t _unused2;
}GravityDeviceConfiguration;

Expand Down
24 changes: 14 additions & 10 deletions src/BrewLogger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1117,22 +1117,26 @@ BrewLogger::BrewLogger(void){

GravityDeviceConfiguration *gdc=theSettings.GravityConfig();

int idx = _allocByte(2 + 4 * gdc->numCalPoints);

if(idx < 0) return;
int start = _allocByte(2 + 4 * gdc->numCalPoints);
if(start < 0) return;

//
_writeBuffer(idx++, CalibrationDataTag);
_writeBuffer(idx++,gdc->numCalPoints);
_writeBuffer(start, CalibrationDataTag);
_writeBuffer(start + 1,gdc->numCalPoints);
int idx=2;

for(int i=0;i<gdc->numCalPoints;i++){
_writeBuffer(idx++,(uint8_t) (gdc->calPoints[i].raw >>8));
_writeBuffer(idx++,(uint8_t) (gdc->calPoints[i].raw & 0xFF));
_writeBuffer(idx++,(uint8_t) (gdc->calPoints[i].calsg >>8));
_writeBuffer(idx++,(uint8_t) (gdc->calPoints[i].calsg &0xFF));
_writeBuffer(start + idx,(uint8_t) (gdc->calPoints[i].raw >>8));
idx++;
_writeBuffer(start + idx,(uint8_t) (gdc->calPoints[i].raw & 0xFF));
idx++;
_writeBuffer(start + idx,(uint8_t) (gdc->calPoints[i].calsg >>8));
idx++;
_writeBuffer(start + idx,(uint8_t) (gdc->calPoints[i].calsg &0xFF));
idx++;
}

_commitData(idx,2 + 4 * gdc->numCalPoints);
_commitData(start,idx);
}

void BrewLogger::_addGravityRecord(bool isOg, uint16_t gravity){
Expand Down
2 changes: 1 addition & 1 deletion src/BrewLogger.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@

#define FillTag 0xF7
#define OriginGravityTag 0xF8
#define CalibrationPointTag 0xF9
#define DeviceTypeTag 0xF9
#define IgnoredCalPointMaskTag 0xFA

#define SpecificGravityTag 0xFB
Expand Down
10 changes: 4 additions & 6 deletions src/BrewPiLess.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1155,7 +1155,7 @@ void periodicalReport(void)
// last update
G["u"] = externalData.lastUpdate();
// gravity
G["g"] = (int)(externalData.gravity() * 1000);
G["g"] = (int)((externalData.gravity() +0.0005) * 1000);
// temperature
G["t"] = (int)(externalData.auxTemp() * 100);
// RSSI, for all devices
Expand Down Expand Up @@ -1217,20 +1217,18 @@ class LogHandler:public AsyncWebHandler
request->send(200,"application/json",brewLogger.fsinfo());
}else if(request->hasParam("start")){
String filename=request->getParam("start")->value();
DBG_PRINTF("start logging:%s\n",filename.c_str());
bool cal=false;
float tiltwater, hydroreading;
if(request->hasParam("tw") && request->hasParam("hr")){
if(request->hasParam("raw")){
cal=true;
tiltwater=request->getParam("tw")->value().toFloat();
hydroreading=request->getParam("hr")->value().toFloat();
}
bool wobf=false;

if(request->hasParam("wobf")){
wobf = ( 0!= request->getParam("wobf")->value().toInt());
}

DBG_PRINTF("start logging:%s, cal:%d, wobf:%d\n",filename.c_str(),cal,wobf);

if(brewLogger.startSession(filename.c_str(),cal,wobf)){
request->send(200,"application/json","{}");
notifyLogStatus();
Expand Down
6 changes: 2 additions & 4 deletions src/ExternalData.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ extern BrewPiProxy brewPi;
#define ErrorMissingField 3
#define ErrorUnknownSource 4

#define MaxCalibrationPoints 16

#define C2F(t) ((t)*1.8+32)

class SimpleFilter
Expand All @@ -70,8 +68,8 @@ class ExternalData;

class FormulaKeeper{
protected:
float _calTilts[MaxCalibrationPoints];
float _calGravities[MaxCalibrationPoints];
float _calTilts[MaxNumberCalibrationPoints];
float _calGravities[MaxNumberCalibrationPoints];
uint8_t _numberOfPoints;
float _lastTilt;
float _lastGravity;
Expand Down
4 changes: 2 additions & 2 deletions src/FormulaKeeper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ bool FormulaKeeper::setTilt(float tilt,uint32_t time){
_lastTilt = tilt;

DBG_PRINTF(" setTilt:%.4f\n",tilt);
if(_lastGravity != INVALID_SG && _numberOfPoints < MaxCalibrationPoints){
if(_lastGravity != INVALID_SG && _numberOfPoints < MaxNumberCalibrationPoints){
addPoint(_lastTilt,_lastGravity);
_lastGravity = INVALID_SG;
return true;
Expand All @@ -58,7 +58,7 @@ bool FormulaKeeper::addGravity(float sg){

DBG_PRINTF(" addGravity:%.4f\n",sg);

if(_lastTilt != INVALID_TILT && _numberOfPoints < MaxCalibrationPoints){
if(_lastTilt != INVALID_TILT && _numberOfPoints < MaxNumberCalibrationPoints){
addPoint(_lastTilt,sg);
return true;
}else{
Expand Down
Loading

0 comments on commit 121aa46

Please sign in to comment.