Skip to content

Commit

Permalink
Add SQM detection logic
Browse files Browse the repository at this point in the history
  • Loading branch information
knro committed Jul 3, 2024
1 parent 913c233 commit 8198fbc
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 11 deletions.
22 changes: 12 additions & 10 deletions indi-aagcloudwatcher-ng/CloudWatcherController_ng.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -756,20 +756,22 @@ bool CloudWatcherController::getValues(int *internalSupplyVoltage, int *ambientT
{
char inputBuffer[BLOCK_SIZE * 4] = {0};

int r = getCloudWatcherAnswer(inputBuffer, 5);
auto blocks = 4;
if (sqmSensorStatus == SQM_UNDETECTED)
blocks = 3;

if (!r)
getCloudWatcherAnswer(inputBuffer, blocks);

if (blocks == 4)
{
return false;
auto res = sscanf(inputBuffer, "!6 %d!4 %d!8 %d!5 %d", &zenerV, &ldrRes, &ldrFreq, &rainSensTemp);
// If SQM Light sensor is not installed, then we skip the !8 block and read the rest
sqmSensorStatus = (res == 4) ? SQM_DETECTED : SQM_UNDETECTED;
}

int res = sscanf(inputBuffer, "!6 %d!4 %d!8 %d!5 %d", &zenerV, &ldrRes, &ldrFreq,
&rainSensTemp);

// If SQM Light sensor is not installed, then we skip the !8 block and read the rest
if (res != 4)
// In case above fails due to undetected SQM, fallback here
if (blocks == 3 || sqmSensorStatus == SQM_UNDETECTED)
{
int res = sscanf(inputBuffer, "!6 %d!4 %d!5 %d", &zenerV, &ldrRes, &rainSensTemp);
auto res = sscanf(inputBuffer, "!6 %d!4 %d!5 %d", &zenerV, &ldrRes, &rainSensTemp);
if (res != 3)
return false;
}
Expand Down
15 changes: 14 additions & 1 deletion indi-aagcloudwatcher-ng/CloudWatcherController_ng.h
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,19 @@ class CloudWatcherController
*/
int totalReadings = 0;


/**
* is SQM selector detected?
*/
enum
{
SQM_UNKNOWN,
SQM_DETECTED,
SQM_UNDETECTED,
};
int sqmSensorStatus = SQM_UNKNOWN;


/**
* Print a buffer of chars. Just for debugging
* @param buffer the buffer to be printed
Expand Down Expand Up @@ -379,7 +392,7 @@ class CloudWatcherController
* and Rain Sensor Temperature values of the AAG Cloud Watcher
* @param internalSupplyVoltage where the sensor value will be stored
* @param ambientTemperature where the sensor value will be stored
* @param ldrValue where the sensor value will be
* @param ldrValue where the sensor value will be
* @param ldrFreqValue where the sensor value in K will be stored, if Firmware >= 5.88
* @param rainSensorTemperature where the sensor value will be stored
* @return true if succesfully read. false otherwise.
Expand Down

0 comments on commit 8198fbc

Please sign in to comment.