mirror of
https://github.com/letscontrolit/ESPEasy.git
synced 2026-09-12 01:24:04 +00:00
[P121] Remove obsolete Arduino 1.0 check, use f suffix for float values
This commit is contained in:
@@ -25,18 +25,9 @@
|
||||
* BSD license, all text above must be included in any redistribution
|
||||
*/
|
||||
|
||||
#if ARDUINO >= 100
|
||||
#include "Arduino.h"
|
||||
#else
|
||||
#include "WProgram.h"
|
||||
#endif
|
||||
|
||||
#ifdef __AVR_ATtiny85__
|
||||
#include "TinyWireM.h"
|
||||
#define Wire TinyWireM
|
||||
#else
|
||||
#include <Wire.h>
|
||||
#endif
|
||||
|
||||
#include <limits.h>
|
||||
|
||||
@@ -59,13 +50,8 @@ static float _hmc5883_Gauss_LSB_Z = 980.0F; // Varies with gain
|
||||
/**************************************************************************/
|
||||
void Adafruit_HMC5883_Unified::write8(byte address, byte reg, byte value) {
|
||||
Wire.beginTransmission(address);
|
||||
#if ARDUINO >= 100
|
||||
Wire.write((uint8_t)reg);
|
||||
Wire.write((uint8_t)value);
|
||||
#else
|
||||
Wire.send(reg);
|
||||
Wire.send(value);
|
||||
#endif
|
||||
Wire.endTransmission();
|
||||
}
|
||||
|
||||
@@ -78,18 +64,10 @@ byte Adafruit_HMC5883_Unified::read8(byte address, byte reg) {
|
||||
byte value;
|
||||
|
||||
Wire.beginTransmission(address);
|
||||
#if ARDUINO >= 100
|
||||
Wire.write((uint8_t)reg);
|
||||
#else
|
||||
Wire.send(reg);
|
||||
#endif
|
||||
Wire.endTransmission();
|
||||
Wire.requestFrom(address, (byte)1);
|
||||
#if ARDUINO >= 100
|
||||
value = Wire.read();
|
||||
#else
|
||||
value = Wire.receive();
|
||||
#endif
|
||||
Wire.endTransmission();
|
||||
|
||||
return value;
|
||||
@@ -103,11 +81,7 @@ byte Adafruit_HMC5883_Unified::read8(byte address, byte reg) {
|
||||
void Adafruit_HMC5883_Unified::read() {
|
||||
// Read the magnetometer
|
||||
Wire.beginTransmission((byte)HMC5883_ADDRESS_MAG);
|
||||
#if ARDUINO >= 100
|
||||
Wire.write(HMC5883_REGISTER_MAG_OUT_X_H_M);
|
||||
#else
|
||||
Wire.send(HMC5883_REGISTER_MAG_OUT_X_H_M);
|
||||
#endif
|
||||
Wire.endTransmission();
|
||||
Wire.requestFrom((byte)HMC5883_ADDRESS_MAG, (byte)6);
|
||||
|
||||
@@ -119,21 +93,12 @@ void Adafruit_HMC5883_Unified::read() {
|
||||
uint8_t ylo = 0;
|
||||
if (Wire.available() == 6) {
|
||||
// Note high before low (different than accel)
|
||||
#if ARDUINO >= 100
|
||||
xhi = Wire.read();
|
||||
xlo = Wire.read();
|
||||
zhi = Wire.read();
|
||||
zlo = Wire.read();
|
||||
yhi = Wire.read();
|
||||
ylo = Wire.read();
|
||||
#else
|
||||
xhi = Wire.receive();
|
||||
xlo = Wire.receive();
|
||||
zhi = Wire.receive();
|
||||
zlo = Wire.receive();
|
||||
yhi = Wire.receive();
|
||||
ylo = Wire.receive();
|
||||
#endif
|
||||
}
|
||||
|
||||
// Shift values to create properly formed integer (low byte first)
|
||||
@@ -142,7 +107,7 @@ void Adafruit_HMC5883_Unified::read() {
|
||||
_magData.z = (int16_t)(zlo | ((int16_t)zhi << 8));
|
||||
|
||||
// ToDo: Calculate orientation
|
||||
_magData.orientation = 0.0;
|
||||
_magData.orientation = 0.0f;
|
||||
}
|
||||
|
||||
/***************************************************************************
|
||||
@@ -192,32 +157,32 @@ void Adafruit_HMC5883_Unified::setMagGain(hmc5883MagGain gain) {
|
||||
|
||||
switch (gain) {
|
||||
case HMC5883_MAGGAIN_1_3:
|
||||
_hmc5883_Gauss_LSB_XY = 1100;
|
||||
_hmc5883_Gauss_LSB_Z = 980;
|
||||
_hmc5883_Gauss_LSB_XY = 1100.0f;
|
||||
_hmc5883_Gauss_LSB_Z = 980.0f;
|
||||
break;
|
||||
case HMC5883_MAGGAIN_1_9:
|
||||
_hmc5883_Gauss_LSB_XY = 855;
|
||||
_hmc5883_Gauss_LSB_Z = 760;
|
||||
_hmc5883_Gauss_LSB_XY = 855.0f;
|
||||
_hmc5883_Gauss_LSB_Z = 760.0f;
|
||||
break;
|
||||
case HMC5883_MAGGAIN_2_5:
|
||||
_hmc5883_Gauss_LSB_XY = 670;
|
||||
_hmc5883_Gauss_LSB_Z = 600;
|
||||
_hmc5883_Gauss_LSB_XY = 670.0f;
|
||||
_hmc5883_Gauss_LSB_Z = 600.0f;
|
||||
break;
|
||||
case HMC5883_MAGGAIN_4_0:
|
||||
_hmc5883_Gauss_LSB_XY = 450;
|
||||
_hmc5883_Gauss_LSB_Z = 400;
|
||||
_hmc5883_Gauss_LSB_XY = 450.0f;
|
||||
_hmc5883_Gauss_LSB_Z = 400.0f;
|
||||
break;
|
||||
case HMC5883_MAGGAIN_4_7:
|
||||
_hmc5883_Gauss_LSB_XY = 400;
|
||||
_hmc5883_Gauss_LSB_Z = 255;
|
||||
_hmc5883_Gauss_LSB_XY = 400.0f;
|
||||
_hmc5883_Gauss_LSB_Z = 255.0f;
|
||||
break;
|
||||
case HMC5883_MAGGAIN_5_6:
|
||||
_hmc5883_Gauss_LSB_XY = 330;
|
||||
_hmc5883_Gauss_LSB_Z = 295;
|
||||
_hmc5883_Gauss_LSB_XY = 330.0f;
|
||||
_hmc5883_Gauss_LSB_Z = 295.0f;
|
||||
break;
|
||||
case HMC5883_MAGGAIN_8_1:
|
||||
_hmc5883_Gauss_LSB_XY = 230;
|
||||
_hmc5883_Gauss_LSB_Z = 205;
|
||||
_hmc5883_Gauss_LSB_XY = 230.0f;
|
||||
_hmc5883_Gauss_LSB_Z = 205.0f;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -264,7 +229,7 @@ void Adafruit_HMC5883_Unified::getSensor(sensor_t *sensor) {
|
||||
sensor->sensor_id = _sensorID;
|
||||
sensor->type = SENSOR_TYPE_MAGNETIC_FIELD;
|
||||
sensor->min_delay = 0;
|
||||
sensor->max_value = 800; // 8 gauss == 800 microTesla
|
||||
sensor->min_value = -800; // -8 gauss == -800 microTesla
|
||||
sensor->resolution = 0.2; // 2 milligauss == 0.2 microTesla
|
||||
sensor->max_value = 800.0f; // 8 gauss == 800 microTesla
|
||||
sensor->min_value = -800.0f; // -8 gauss == -800 microTesla
|
||||
sensor->resolution = 0.2f; // 2 milligauss == 0.2 microTesla
|
||||
}
|
||||
|
||||
@@ -90,7 +90,7 @@ boolean Plugin_121(uint8_t function, struct EventStruct *event, String& string)
|
||||
case PLUGIN_WEBFORM_LOAD:
|
||||
{
|
||||
addFormFloatNumberBox(F("Declination Angle"), F("pdecl"), PCONFIG_FLOAT(0), -180.0f, 180.0f, 2, 0.01f);
|
||||
PCONFIG_FLOAT(1) = PCONFIG_FLOAT(0) * M_PI / 180.0; // convert from degree to radian
|
||||
PCONFIG_FLOAT(1) = PCONFIG_FLOAT(0) * M_PI / 180.0f; // convert from degree to radian
|
||||
addUnit(F("degree"));
|
||||
success = true;
|
||||
break;
|
||||
@@ -139,11 +139,11 @@ boolean Plugin_121(uint8_t function, struct EventStruct *event, String& string)
|
||||
}
|
||||
|
||||
if (heading < 0) {
|
||||
heading += 2 * PI;
|
||||
heading += 2.0f * PI;
|
||||
}
|
||||
|
||||
if (heading > 2 * PI) {
|
||||
heading -= 2 * PI;
|
||||
if (heading > 2.0f * PI) {
|
||||
heading -= 2.0f * PI;
|
||||
}
|
||||
|
||||
UserVar[event->BaseVarIndex + 3] = heading * 180.0f / M_PI;
|
||||
|
||||
Reference in New Issue
Block a user