added test of availabillty

This commit is contained in:
Helge 2022-10-04 18:16:49 +02:00
parent 31c94424a9
commit a7a26dc9a1
1 changed files with 12 additions and 6 deletions

View File

@ -220,12 +220,15 @@ struct QMC5883L_s
int16_t MX, MY, MZ; int16_t MX, MY, MZ;
int16_t temp; int16_t temp;
uint16_t scalar; uint16_t scalar;
bool ready;
} *QMC5883L = nullptr; } *QMC5883L = nullptr;
// Initialise the device // Initialise the device
void QMC5883L_Init() void QMC5883L_Init()
{ {
QMC5883L = (QMC5883L_s *)calloc(1, sizeof(struct QMC5883L_s));
QMC5883L->ready = false;
if (!I2cSetDevice(QMC5883L_ADDR)) if (!I2cSetDevice(QMC5883L_ADDR))
{ {
return; return;
@ -239,7 +242,7 @@ void QMC5883L_Init()
// write config // write config
if (I2cWrite8(QMC5883L_ADDR, QMC5883L_CONFIG, QMC5883L_CONFIG_OS256 | QMC5883L_CONFIG_8GAUSS | QMC5883L_CONFIG_100HZ | QMC5883L_CONFIG_CONT) == false) if (I2cWrite8(QMC5883L_ADDR, QMC5883L_CONFIG, QMC5883L_CONFIG_OS256 | QMC5883L_CONFIG_8GAUSS | QMC5883L_CONFIG_100HZ | QMC5883L_CONFIG_CONT) == false)
return; return;
QMC5883L = (QMC5883L_s*) calloc(1, sizeof(struct QMC5883L_s)); QMC5883L->ready = true;
} }
//Read the magnetic data //Read the magnetic data
@ -301,12 +304,14 @@ bool Xsns33(byte function)
{ {
return false; return false;
} }
if (FUNC_INIT == function)
{
QMC5883L_Init();
}
else if (QMC5883L->ready == true)
{
switch (function) switch (function)
{ {
case FUNC_INIT:
QMC5883L_Init();
break;
case FUNC_JSON_APPEND: case FUNC_JSON_APPEND:
QMC5883L_Show(1); QMC5883L_Show(1);
break; break;
@ -319,6 +324,7 @@ bool Xsns33(byte function)
break; break;
#endif // USE_WEBSERVER #endif // USE_WEBSERVER
} }
}
return true; return true;
} }
#endif // USE_QMC5883L #endif // USE_QMC5883L