added code recommendations

and reduce functionality to the most necessary
This commit is contained in:
Helge 2022-10-04 15:48:27 +02:00
parent d5bc687844
commit 5998fe856a
30 changed files with 157 additions and 248 deletions

View File

@ -233,12 +233,10 @@
#define D_JSON_SIGNALSTRENGTH "SignalStrength"
#define D_JSON_CHIPTEMPERATURE "ChipTemperature"
#define D_JSON_RAW "Raw"
#define D_JSON_MX "Compass X-Axis"
#define D_JSON_MY "Compass Y-Axis"
#define D_JSON_MZ "Compass Z-Axis"
#define D_JSON_HEADING "Compass Heading"
#define D_JSON_MX "Induction X-Axis"
#define D_JSON_MY "Induction Y-Axis"
#define D_JSON_MZ "Induction Z-Axis"
#define D_JSON_MAGNETICFLD "Magnetic Induction"
#define D_RSLT_ENERGY "ENERGY"
#define D_RSLT_HASS_STATE "HASS_STATE"
#define D_RSLT_INFO "INFO"

View File

@ -565,11 +565,10 @@
#define D_GZ_AXIS "Gyro Z-Axis"
// xsns_33_QMC5883L.ino
#define D_MX "Compass X-Axis"
#define D_MY "Compass Y-Axis"
#define D_MZ "Compass Z-Axis"
#define D_HG "Compass Heading"
#define D_MAGNETICFLD "Magnetic Field Strength"
#define D_MX "Induction X-Axis"
#define D_MY "Induction Y-Axis"
#define D_MZ "Induction Z-Axis"
#define D_MAGNETICFLD "Magnetic Induction"
// xsns_34_hx711.ino
#define D_HX_CAL_REMOVE "Verwyder gewig"

View File

@ -565,11 +565,10 @@
#define D_GZ_AXIS "Жироскоп - ос Z"
// xsns_33_QMC5883L.ino
#define D_MX "Compass X-Axis"
#define D_MY "Compass Y-Axis"
#define D_MZ "Compass Z-Axis"
#define D_HG "Compass Heading"
#define D_MAGNETICFLD "Magnetic Field Strength"
#define D_MX "Induction X-Axis"
#define D_MY "Induction Y-Axis"
#define D_MZ "Induction Z-Axis"
#define D_MAGNETICFLD "Magnetic Induction"
// xsns_34_hx711.ino
#define D_HX_CAL_REMOVE "Премахване на тегло"

View File

@ -565,11 +565,10 @@
#define D_GZ_AXIS "Gyro Z-Axis"
// xsns_33_QMC5883L.ino
#define D_MX "Compass X-Axis"
#define D_MY "Compass Y-Axis"
#define D_MZ "Compass Z-Axis"
#define D_HG "Compass Heading"
#define D_MAGNETICFLD "Magnetic Field Strength"
#define D_MX "Induction X-Axis"
#define D_MY "Induction Y-Axis"
#define D_MZ "Induction Z-Axis"
#define D_MAGNETICFLD "Magnetic Induction"
// xsns_34_hx711.ino
#define D_HX_CAL_REMOVE "Treu el pes"

View File

@ -565,11 +565,10 @@
#define D_GZ_AXIS "Gyro osa-Z"
// xsns_33_QMC5883L.ino
#define D_MX "Compass X-Axis"
#define D_MY "Compass Y-Axis"
#define D_MZ "Compass Z-Axis"
#define D_HG "Compass Heading"
#define D_MAGNETICFLD "Magnetic Field Strength"
#define D_MX "Induction X-Axis"
#define D_MY "Induction Y-Axis"
#define D_MZ "Induction Z-Axis"
#define D_MAGNETICFLD "Magnetic Induction"
// xsns_34_hx711.ino
#define D_HX_CAL_REMOVE "Odstraňte zátěž"

View File

@ -565,11 +565,10 @@
#define D_GZ_AXIS "Gyroskop Z-Achse"
// xsns_33_QMC5883L.ino
#define D_MX "Kompass X-Achse"
#define D_MY "Kompass Y-Achse"
#define D_MZ "Kompass Z-Achse"
#define D_HG "Kompass Richtung"
#define D_MAGNETICFLD "Magnet Feld Stärke"
#define D_MX "Magnetfeld X-Achse"
#define D_MY "Magnetfeld Y-Achse"
#define D_MZ "Magnetfeld Z-Achse"
#define D_MAGNETICFLD "Magnetfeldstärke"
// xsns_34_hx711.ino
#define D_HX_CAL_REMOVE "Wägegut entfernen"

View File

@ -565,11 +565,10 @@
#define D_GZ_AXIS "Gyro Z-Axis"
// xsns_33_QMC5883L.ino
#define D_MX "Compass X-Axis"
#define D_MY "Compass Y-Axis"
#define D_MZ "Compass Z-Axis"
#define D_HG "Compass Heading"
#define D_MAGNETICFLD "Magnetic Field Strength"
#define D_MX "Induction X-Axis"
#define D_MY "Induction Y-Axis"
#define D_MZ "Induction Z-Axis"
#define D_MAGNETICFLD "Magnetic Induction"
// xsns_34_hx711.ino
#define D_HX_CAL_REMOVE "Απομακρύνετε το βαρίδιο"

View File

@ -565,11 +565,10 @@
#define D_GZ_AXIS "Gyro Z-Axis"
// xsns_33_QMC5883L.ino
#define D_MX "Compass X-Axis"
#define D_MY "Compass Y-Axis"
#define D_MZ "Compass Z-Axis"
#define D_HG "Compass Heading"
#define D_MAGNETICFLD "Magnetic Field Strength"
#define D_MX "Induction X-Axis"
#define D_MY "Induction Y-Axis"
#define D_MZ "Induction Z-Axis"
#define D_MAGNETICFLD "Magnetic Induction"
// xsns_34_hx711.ino
#define D_HX_CAL_REMOVE "Remove weight"

View File

@ -565,11 +565,10 @@
#define D_GZ_AXIS "Girós. Eje Z"
// xsns_33_QMC5883L.ino
#define D_MX "Compass X-Axis"
#define D_MY "Compass Y-Axis"
#define D_MZ "Compass Z-Axis"
#define D_HG "Compass Heading"
#define D_MAGNETICFLD "Magnetic Field Strength"
#define D_MX "Induction X-Axis"
#define D_MY "Induction Y-Axis"
#define D_MZ "Induction Z-Axis"
#define D_MAGNETICFLD "Magnetic Induction"
// xsns_34_hx711.ino
#define D_HX_CAL_REMOVE "Remover Peso"

View File

@ -565,11 +565,10 @@
#define D_GZ_AXIS "Gyro Axe-Z"
// xsns_33_QMC5883L.ino
#define D_MX "Compass X-Axis"
#define D_MY "Compass Y-Axis"
#define D_MZ "Compass Z-Axis"
#define D_HG "Compass Heading"
#define D_MAGNETICFLD "Magnetic Field Strength"
#define D_MX "Induction X-Axis"
#define D_MY "Induction Y-Axis"
#define D_MZ "Induction Z-Axis"
#define D_MAGNETICFLD "Magnetic Induction"
// xsns_34_hx711.ino
#define D_HX_CAL_REMOVE "Retirer la charge"

View File

@ -565,11 +565,10 @@
#define D_GZ_AXIS "Gyro Z-as"
// xsns_33_QMC5883L.ino
#define D_MX "Compass X-Axis"
#define D_MY "Compass Y-Axis"
#define D_MZ "Compass Z-Axis"
#define D_HG "Compass Heading"
#define D_MAGNETICFLD "Magnetic Field Strength"
#define D_MX "Induction X-Axis"
#define D_MY "Induction Y-Axis"
#define D_MZ "Induction Z-Axis"
#define D_MAGNETICFLD "Magnetic Induction"
// xsns_34_hx711.ino
#define D_HX_CAL_REMOVE "Gewicht fuortsmite"

View File

@ -565,11 +565,10 @@
#define D_GZ_AXIS "Gyro Z-Axis"
// xsns_33_QMC5883L.ino
#define D_MX "Compass X-Axis"
#define D_MY "Compass Y-Axis"
#define D_MZ "Compass Z-Axis"
#define D_HG "Compass Heading"
#define D_MAGNETICFLD "Magnetic Field Strength"
#define D_MX "Induction X-Axis"
#define D_MY "Induction Y-Axis"
#define D_MZ "Induction Z-Axis"
#define D_MAGNETICFLD "Magnetic Induction"
// xsns_34_hx711.ino
#define D_HX_CAL_REMOVE "הסר משקל"

View File

@ -565,11 +565,10 @@
#define D_GZ_AXIS "Giroszkóp Z-tengely"
// xsns_33_QMC5883L.ino
#define D_MX "Compass X-Axis"
#define D_MY "Compass Y-Axis"
#define D_MZ "Compass Z-Axis"
#define D_HG "Compass Heading"
#define D_MAGNETICFLD "Magnetic Field Strength"
#define D_MX "Induction X-Axis"
#define D_MY "Induction Y-Axis"
#define D_MZ "Induction Z-Axis"
#define D_MAGNETICFLD "Magnetic Induction"
// xsns_34_hx711.ino
#define D_HX_CAL_REMOVE "Távolítsa el a súlyt"

View File

@ -565,11 +565,10 @@
#define D_GZ_AXIS "Giroscopio asse Z"
// xsns_33_QMC5883L.ino
#define D_MX "Compass X-Axis"
#define D_MY "Compass Y-Axis"
#define D_MZ "Compass Z-Axis"
#define D_HG "Compass Heading"
#define D_MAGNETICFLD "Magnetic Field Strength"
#define D_MX "Induction X-Axis"
#define D_MY "Induction Y-Axis"
#define D_MZ "Induction Z-Axis"
#define D_MAGNETICFLD "Magnetic Induction"
// xsns_34_hx711.ino
#define D_HX_CAL_REMOVE "Rimuovi peso"

View File

@ -565,11 +565,10 @@
#define D_GZ_AXIS "Gyro Z-Axis"
// xsns_33_QMC5883L.ino
#define D_MX "Compass X-Axis"
#define D_MY "Compass Y-Axis"
#define D_MZ "Compass Z-Axis"
#define D_HG "Compass Heading"
#define D_MAGNETICFLD "Magnetic Field Strength"
#define D_MX "Induction X-Axis"
#define D_MY "Induction Y-Axis"
#define D_MZ "Induction Z-Axis"
#define D_MAGNETICFLD "Magnetic Induction"
// xsns_34_hx711.ino
#define D_HX_CAL_REMOVE "중량 제거"

View File

@ -565,11 +565,10 @@
#define D_GZ_AXIS "Gyro Z-as"
// xsns_33_QMC5883L.ino
#define D_MX "Compass X-Axis"
#define D_MY "Compass Y-Axis"
#define D_MZ "Compass Z-Axis"
#define D_HG "Compass Heading"
#define D_MAGNETICFLD "Magnetic Field Strength"
#define D_MX "Induction X-Axis"
#define D_MY "Induction Y-Axis"
#define D_MZ "Induction Z-Axis"
#define D_MAGNETICFLD "Magnetic Induction"
// xsns_34_hx711.ino
#define D_HX_CAL_REMOVE "Verwijder gewicht"

View File

@ -565,11 +565,10 @@
#define D_GZ_AXIS "Odchylenie Oś-Z"
// xsns_33_QMC5883L.ino
#define D_MX "Compass X-Axis"
#define D_MY "Compass Y-Axis"
#define D_MZ "Compass Z-Axis"
#define D_HG "Compass Heading"
#define D_MAGNETICFLD "Magnetic Field Strength"
#define D_MX "Induction X-Axis"
#define D_MY "Induction Y-Axis"
#define D_MZ "Induction Z-Axis"
#define D_MAGNETICFLD "Magnetic Induction"
// xsns_34_hx711.ino
#define D_HX_CAL_REMOVE "Usuń wagę"

View File

@ -565,11 +565,10 @@
#define D_GZ_AXIS "Giro Eixo-Z"
// xsns_33_QMC5883L.ino
#define D_MX "Compass X-Axis"
#define D_MY "Compass Y-Axis"
#define D_MZ "Compass Z-Axis"
#define D_HG "Compass Heading"
#define D_MAGNETICFLD "Magnetic Field Strength"
#define D_MX "Induction X-Axis"
#define D_MY "Induction Y-Axis"
#define D_MZ "Induction Z-Axis"
#define D_MAGNETICFLD "Magnetic Induction"
// xsns_34_hx711.ino
#define D_HX_CAL_REMOVE "Remover calibragem"

View File

@ -565,11 +565,10 @@
#define D_GZ_AXIS "Gyro Z-Axis"
// xsns_33_QMC5883L.ino
#define D_MX "Compass X-Axis"
#define D_MY "Compass Y-Axis"
#define D_MZ "Compass Z-Axis"
#define D_HG "Compass Heading"
#define D_MAGNETICFLD "Magnetic Field Strength"
#define D_MX "Induction X-Axis"
#define D_MY "Induction Y-Axis"
#define D_MZ "Induction Z-Axis"
#define D_MAGNETICFLD "Magnetic Induction"
// xsns_34_hx711.ino
#define D_HX_CAL_REMOVE "Remover peso"

View File

@ -565,11 +565,10 @@
#define D_GZ_AXIS "Gyro Axa-Z"
// xsns_33_QMC5883L.ino
#define D_MX "Compass X-Axis"
#define D_MY "Compass Y-Axis"
#define D_MZ "Compass Z-Axis"
#define D_HG "Compass Heading"
#define D_MAGNETICFLD "Magnetic Field Strength"
#define D_MX "Induction X-Axis"
#define D_MY "Induction Y-Axis"
#define D_MZ "Induction Z-Axis"
#define D_MAGNETICFLD "Magnetic Induction"
// xsns_34_hx711.ino
#define D_HX_CAL_REMOVE "Elimină greutatea"

View File

@ -565,11 +565,10 @@
#define D_GZ_AXIS "Gyro Z-Axis"
// xsns_33_QMC5883L.ino
#define D_MX "Compass X-Axis"
#define D_MY "Compass Y-Axis"
#define D_MZ "Compass Z-Axis"
#define D_HG "Compass Heading"
#define D_MAGNETICFLD "Magnetic Field Strength"
#define D_MX "Induction X-Axis"
#define D_MY "Induction Y-Axis"
#define D_MZ "Induction Z-Axis"
#define D_MAGNETICFLD "Magnetic Induction"
// xsns_34_hx711.ino
#define D_HX_CAL_REMOVE "Remove weight"

View File

@ -565,11 +565,10 @@
#define D_GZ_AXIS "Gyro os-Z"
// xsns_33_QMC5883L.ino
#define D_MX "Compass X-Axis"
#define D_MY "Compass Y-Axis"
#define D_MZ "Compass Z-Axis"
#define D_HG "Compass Heading"
#define D_MAGNETICFLD "Magnetic Field Strength"
#define D_MX "Induction X-Axis"
#define D_MY "Induction Y-Axis"
#define D_MZ "Induction Z-Axis"
#define D_MAGNETICFLD "Magnetic Induction"
// xsns_34_hx711.ino
#define D_HX_CAL_REMOVE "Odstráňte záťaž"

View File

@ -565,11 +565,10 @@
#define D_GZ_AXIS "Gyro Z-Axel"
// xsns_33_QMC5883L.ino
#define D_MX "Compass X-Axis"
#define D_MY "Compass Y-Axis"
#define D_MZ "Compass Z-Axis"
#define D_HG "Compass Heading"
#define D_MAGNETICFLD "Magnetic Field Strength"
#define D_MX "Induction X-Axis"
#define D_MY "Induction Y-Axis"
#define D_MZ "Induction Z-Axis"
#define D_MAGNETICFLD "Magnetic Induction"
// xsns_34_hx711.ino
#define D_HX_CAL_REMOVE "Ta bort vikter"

View File

@ -565,11 +565,10 @@
#define D_GZ_AXIS "Gyro Z-Axis"
// xsns_33_QMC5883L.ino
#define D_MX "Compass X-Axis"
#define D_MY "Compass Y-Axis"
#define D_MZ "Compass Z-Axis"
#define D_HG "Compass Heading"
#define D_MAGNETICFLD "Magnetic Field Strength"
#define D_MX "Induction X-Axis"
#define D_MY "Induction Y-Axis"
#define D_MZ "Induction Z-Axis"
#define D_MAGNETICFLD "Magnetic Induction"
// xsns_34_hx711.ino
#define D_HX_CAL_REMOVE "Remove weight"

View File

@ -565,11 +565,10 @@
#define D_GZ_AXIS "Орієнт Вісь-Z"
// xsns_33_QMC5883L.ino
#define D_MX "Compass X-Axis"
#define D_MY "Compass Y-Axis"
#define D_MZ "Compass Z-Axis"
#define D_HG "Compass Heading"
#define D_MAGNETICFLD "Magnetic Field Strength"
#define D_MX "Induction X-Axis"
#define D_MY "Induction Y-Axis"
#define D_MZ "Induction Z-Axis"
#define D_MAGNETICFLD "Magnetic Induction"
// xsns_34_hx711.ino
#define D_HX_CAL_REMOVE "Remove weight"

View File

@ -565,11 +565,10 @@
#define D_GZ_AXIS "Gyro Z-Axis"
// xsns_33_QMC5883L.ino
#define D_MX "Compass X-Axis"
#define D_MY "Compass Y-Axis"
#define D_MZ "Compass Z-Axis"
#define D_HG "Compass Heading"
#define D_MAGNETICFLD "Magnetic Field Strength"
#define D_MX "Induction X-Axis"
#define D_MY "Induction Y-Axis"
#define D_MZ "Induction Z-Axis"
#define D_MAGNETICFLD "Magnetic Induction"
// xsns_34_hx711.ino
#define D_HX_CAL_REMOVE "Remove weight"

View File

@ -565,11 +565,10 @@
#define D_GZ_AXIS "绕Z轴旋转的角速度"
// xsns_33_QMC5883L.ino
#define D_MX "Compass X-Axis"
#define D_MY "Compass Y-Axis"
#define D_MZ "Compass Z-Axis"
#define D_HG "Compass Heading"
#define D_MAGNETICFLD "Magnetic Field Strength"
#define D_MX "Induction X-Axis"
#define D_MY "Induction Y-Axis"
#define D_MZ "Induction Z-Axis"
#define D_MAGNETICFLD "Magnetic Induction"
// xsns_34_hx711.ino
#define D_HX_CAL_REMOVE "去除重量"

View File

@ -565,11 +565,10 @@
#define D_GZ_AXIS "陀螺儀 Z-軸"
// xsns_33_QMC5883L.ino
#define D_MX "Compass X-Axis"
#define D_MY "Compass Y-Axis"
#define D_MZ "Compass Z-Axis"
#define D_HG "Compass Heading"
#define D_MAGNETICFLD "Magnetic Field Strength"
#define D_MX "Induction X-Axis"
#define D_MY "Induction Y-Axis"
#define D_MZ "Induction Z-Axis"
#define D_MAGNETICFLD "Magnetic Induction"
// xsns_34_hx711.ino
#define D_HX_CAL_REMOVE "移除重量"

View File

@ -715,8 +715,8 @@
// Reference: https://cdn-learn.adafruit.com/downloads/pdf/adafruit-led-backpack.pdf
// #define SEVENSEG_ADDRESS1 0x70 // No longer used. Use MTX_ADDRESS1 - MTX_ADDRESS8 instead to specify I2C address of sevenseg displays
// #define USE_DISPLAY_SH1106 // [DisplayModel 7] [I2cDriver6] Enable SH1106 Oled 128x64 display (I2C addresses 0x3C and 0x3D)
#define USE_QMC5883L // USE_QMC5883L compass sensor
#define USE_QMC5883L_Temp 22 // compass sensor temperatur are not calibrated (only relativ measurement) and need an absolute ground value in °C (see datasheet)
#define USE_QMC5883L // USE_QMC5883L magnetic induction sensor, (I2C address 0x0D)
#define QMC5883L_TEMP_SHIFT 23 // sensor temperature are not calibrated (only relativ measurement) and need an absolute ground value in °C (see datasheet)
#endif // USE_I2C

View File

@ -214,93 +214,50 @@
/* Mode values for the CONFIG2 register */
#define QMC5883L_CONFIG2_RESET 0b10000000
/* Apparently M_PI isn't available in all environments. */
#ifndef M_PI
#define M_PI 3.14159265358979323846264338327950288
#endif
// data field
struct QMC5883L_s
{
int16_t MX, MY, MZ;
int16_t temp;
uint16_t scalar;
} *QMC5883L = nullptr;
// data field
struct {
int16_t MX = 0, MY = 0, MZ = 0, HG = 0;
int16_t xhigh = 0, yhigh = 0, xlow = 0, ylow = 0;
int16_t temp = 0;
uint16_t scalar = 0;
uint8_t status;
bool ready = false;
uint8_t i2c_address = QMC5883L_ADDR;
} QMC5883L;
// Initialise the device
void QMC5883L_Init()
{
if (!I2cSetDevice(QMC5883L.i2c_address)) { return; }
I2cSetActiveFound(QMC5883L.i2c_address, "QMC5883L");
if (!I2cSetDevice(QMC5883L_ADDR))
{
return;
}
I2cSetActiveFound(QMC5883L_ADDR, "QMC5883L");
// reset QMC5883L
if (I2cWrite8(QMC5883L.i2c_address, QMC5883L_CONFIG2, QMC5883L_CONFIG2_RESET) == false) return; // Software Reset
// writeRegister(QMC5883L_CONFIG2,QMC5883L_CONFIG2_RESET); // Software Reset
//writeRegister(QMC5883L_RESET, 0x01);
if (I2cWrite8(QMC5883L.i2c_address, QMC5883L_RESET, 0x01) == false) return;
if (I2cWrite8(QMC5883L_ADDR, QMC5883L_CONFIG2, QMC5883L_CONFIG2_RESET) == false)
return; // Software Reset
if (I2cWrite8(QMC5883L_ADDR, QMC5883L_RESET, 0x01) == false)
return;
// write config
//writeRegister(QMC5883L_CONFIG, QMC5883L_CONFIG_OS256 | QMC5883L_CONFIG_8GAUSS | QMC5883L_CONFIG_10HZ | QMC5883L_CONFIG_CONT);
if (I2cWrite8(QMC5883L.i2c_address, QMC5883L_CONFIG, QMC5883L_CONFIG_OS256 | QMC5883L_CONFIG_8GAUSS | QMC5883L_CONFIG_10HZ | QMC5883L_CONFIG_CONT) == false) return;
QMC5883L.ready = true;
if (I2cWrite8(QMC5883L_ADDR, QMC5883L_CONFIG, QMC5883L_CONFIG_OS256 | QMC5883L_CONFIG_8GAUSS | QMC5883L_CONFIG_100HZ | QMC5883L_CONFIG_CONT) == false)
return;
QMC5883L = (QMC5883L_s*) calloc(1, sizeof(struct QMC5883L_s));
}
//Read the magnetic data
void QMC5883L_read_data(void)
{
if(QMC5883L.ready != true) return;
uint8_t data = 0;
// check if chip is ready to provice data
//if (!readRegister(QMC5883L_STATUS, 1)) return; // read error
if (!I2cValidRead8(&data, QMC5883L.i2c_address, QMC5883L_STATUS)) return; // read error
//if (!(Wire.read() & QMC5883L_STATUS_DRDY)) return; // chip not yet ready, next round try again
if (!(data & QMC5883L_STATUS_DRDY)) return; // chip not yet ready, next round try again
// QMC5883 reading data
//if (readRegister(QMC5883L_X_LSB, 6) != 6) return; // read error, select LSB register
//QMC5883L.MX = Wire.read() | (Wire.read() << 8);
//QMC5883L.MY = Wire.read() | (Wire.read() << 8);
//QMC5883L.MZ = Wire.read() | (Wire.read() << 8);
if (!(I2cRead8(QMC5883L_ADDR, QMC5883L_STATUS) & QMC5883L_STATUS_DRDY))
return; // chip not yet ready, next round try again
int16_t x = 0;
int16_t y = 0;
if (I2cValidReadS16(&x, QMC5883L.i2c_address, QMC5883L_X_LSB) == false) return; // read error, select LSB register
if (I2cValidReadS16(&y, QMC5883L.i2c_address, QMC5883L_Y_LSB) == false) return; // read error, select LSB register
if (I2cValidReadS16(&QMC5883L.MZ, QMC5883L.i2c_address, QMC5883L_Z_LSB) == false) return; // read error, select LSB register
QMC5883L.MX = x;
QMC5883L.MY = y;
// calculate azimut, heading
if(x < QMC5883L.xlow) QMC5883L.xlow = x;
if(x > QMC5883L.xhigh) QMC5883L.xhigh = x;
if(y < QMC5883L.ylow) QMC5883L.ylow = y;
if(y > QMC5883L.yhigh) QMC5883L.yhigh = y;
/* Bail out if not enough data is available. */
if( QMC5883L.xlow == QMC5883L.xhigh || QMC5883L.ylow == QMC5883L.yhigh ) return;
/* Recenter the measurement by subtracting the average */
x -= (QMC5883L.xhigh + QMC5883L.xlow) / 2;
y -= (QMC5883L.yhigh + QMC5883L.ylow) / 2;
/* Rescale the measurement to the range observed. */
float fx = (float) x / (QMC5883L.xhigh - QMC5883L.xlow);
float fy = (float) y / (QMC5883L.yhigh - QMC5883L.ylow);
x = -atan2(fy, fx) * 180.0 / M_PI;
x += 180; // no negative numbers
QMC5883L.HG = x;
QMC5883L->MX = I2cReadS16_LE(QMC5883L_ADDR, QMC5883L_X_LSB); // select LSB register
QMC5883L->MY = I2cReadS16_LE(QMC5883L_ADDR, QMC5883L_Y_LSB);
QMC5883L->MZ = I2cReadS16_LE(QMC5883L_ADDR, QMC5883L_Z_LSB);
// calculate scalar magnetic induction
QMC5883L.scalar = sqrt((QMC5883L.MX * QMC5883L.MX) + (QMC5883L.MY * QMC5883L.MY) + (QMC5883L.MZ * QMC5883L.MZ));
// get temperature
//if (readRegister(QMC5883L_TEMP_LSB, 2) != 2) return; // read error
if (I2cValidReadS16(&QMC5883L.temp, QMC5883L.i2c_address, QMC5883L_TEMP_LSB) == false) return; // read error, select LSB register
//t = Wire.read() | (Wire.read() << 8);
QMC5883L.temp = (QMC5883L.temp / 100) + USE_QMC5883L_Temp;
QMC5883L->scalar = sqrt((QMC5883L->MX * QMC5883L->MX) + (QMC5883L->MY * QMC5883L->MY) + (QMC5883L->MZ * QMC5883L->MZ));
// get temperature
QMC5883L->temp = (I2cReadS16_LE(QMC5883L_ADDR, QMC5883L_TEMP_LSB) / 100) + QMC5883L_TEMP_SHIFT;
}
/*********************************************************************************************\
@ -313,7 +270,6 @@ const char HTTP_SNS_QMC5883L[] PROGMEM =
"{s}QMC5883L " D_MY "{m}%d " D_UNIT_MICROTESLA "{e}" // {s} = <tr><th>, {m} = </th><td>, {e} = </td></tr>
"{s}QMC5883L " D_MZ "{m}%d " D_UNIT_MICROTESLA "{e}" // {s} = <tr><th>, {m} = </th><td>, {e} = </td></tr>
"{s}QMC5883L " D_MAGNETICFLD "{m}%d " D_UNIT_MICROTESLA "{e}" // {s} = <tr><th>, {m} = </th><td>, {e} = </td></tr>
"{s}QMC5883L " D_HG "{m}%d " D_UNIT_DEGREE "{e}" // {s} = <tr><th>, {m} = </th><td>, {e} = </td></tr>
"{s}QMC5883L " D_TEMPERATURE "{m}%d " D_UNIT_DEGREE D_UNIT_CELSIUS "{e}"; // {s} = <tr><th>, {m} = </th><td>, {e} = </td></tr>
const char HTTP_SNS_QMC5883L_ERROR[] PROGMEM =
@ -325,27 +281,13 @@ void QMC5883L_Show(uint8_t json)
{
if (json)
{
if (QMC5883L.ready != true)
{
AddLog(LOG_LEVEL_INFO, PSTR("QMC5883L: " D_ERROR " %x" ), QMC5883L.status);
return;
}
else
{
ResponseAppend_P(PSTR(",\"QMC5883L\":{\"" D_JSON_MX "\":%d,\"" D_JSON_MY "\":%d,\"" D_JSON_MZ "\":%d,\"" D_JSON_MAGNETICFLD "\":%u,\"" D_JSON_HEADING "\":%d,\"" D_JSON_TEMPERATURE "\":%d}"), QMC5883L.MX, QMC5883L.MY, QMC5883L.MZ, QMC5883L.scalar, QMC5883L.HG, QMC5883L.temp);
}
ResponseAppend_P(PSTR(",\"QMC5883L\":{\"" D_JSON_MX "\":%d,\"" D_JSON_MY "\":%d,\"" D_JSON_MZ "\":%d,\"" D_JSON_MAGNETICFLD "\":%u,\"" D_JSON_TEMPERATURE "\":%d}"), QMC5883L->MX, QMC5883L->MY, QMC5883L->MZ, QMC5883L->scalar, QMC5883L->temp);
}
#ifdef USE_WEBSERVER
else
{
if (QMC5883L.ready != true)
{
WSContentSend_PD(HTTP_SNS_QMC5883L_ERROR, D_ERROR);
}
else
{
WSContentSend_PD(HTTP_SNS_QMC5883L, QMC5883L.MX, QMC5883L.MY, QMC5883L.MZ, QMC5883L.scalar, QMC5883L.HG, QMC5883L.temp);
}
WSContentSend_PD(HTTP_SNS_QMC5883L, QMC5883L->MX, QMC5883L->MY, QMC5883L->MZ, QMC5883L->scalar, QMC5883L->temp);
}
#endif
}
@ -361,26 +303,22 @@ bool Xsns33(byte function)
return false;
}
if (FUNC_INIT == function) {
QMC5883L_Init();
}
else
if (QMC5883L.ready == true)
switch (function)
{
switch (function)
{
case FUNC_JSON_APPEND:
QMC5883L_Show(1);
break;
case FUNC_EVERY_SECOND:
QMC5883L_read_data();
break;
case FUNC_INIT:
QMC5883L_Init();
break;
case FUNC_JSON_APPEND:
QMC5883L_Show(1);
break;
case FUNC_EVERY_SECOND:
QMC5883L_read_data();
break;
#ifdef USE_WEBSERVER
case FUNC_WEB_SENSOR:
QMC5883L_Show(0);
break;
case FUNC_WEB_SENSOR:
QMC5883L_Show(0);
break;
#endif // USE_WEBSERVER
}
}
return true;
}