Browse Source

tidy code

master
Max Reble 4 years ago
parent
commit
df09c4b71f
  1. 45
      src/MessenSensoren.cpp
  2. 19
      src/main.cpp

45
src/MessenSensoren.cpp

@ -1,11 +1,11 @@
// Sensoren lesen // Sensoren lesen
#include <arduino.h> #include <Arduino.h>
#include "MessenSensoren.h" #include "MessenSensoren.h"
#include <Wire.h> #include <Wire.h>
#include "myi2c.h" #include "myI2C.h"
#include "bme280.h" #include "bme280.h"
#include "bh1750.h" #include "BH1750.h"
#include "hseSensorProtocol.h" #include "hseSensorProtocol.h"
#define I2C_POWER 5 // bei Feather M0 #define I2C_POWER 5 // bei Feather M0
@ -15,8 +15,7 @@
HseSP hse(2, 60); HseSP hse(2, 60);
void init_Messen(void) void init_Messen() {
{
int i; int i;
Serial.println("PowerOn I2C"); Serial.println("PowerOn I2C");
@ -30,8 +29,7 @@ Wire.begin();
// Hardware detection, liste was angeschlossen ist // Hardware detection, liste was angeschlossen ist
Serial.println("I2C Hardware detection"); Serial.println("I2C Hardware detection");
if ( I2C_Test(BME280_ADR) != 0xFF ) if (I2C_Test(BME280_ADR) != 0xFF) {
{
Set_I2C_Adresse(BME280_ADR); Set_I2C_Adresse(BME280_ADR);
i = I2C_read8(BME280_REGISTER_CHIPID); i = I2C_read8(BME280_REGISTER_CHIPID);
Serial1.print(F("BMx280 Chip ID = 0x")); Serial1.print(F("BMx280 Chip ID = 0x"));
@ -40,25 +38,21 @@ if ( I2C_Test(BME280_ADR) != 0xFF )
if (i == 0x60) Serial1.println(F(" = BME280")); if (i == 0x60) Serial1.println(F(" = BME280"));
} }
if ( I2C_Test(0x77) != 0xFF ) if (I2C_Test(0x77) != 0xFF) {
{
Serial.println("BMP180 gefunden"); Serial.println("BMP180 gefunden");
} }
if ( I2C_Test(0x38) != 0xFF ) if (I2C_Test(0x38) != 0xFF) {
{
Serial.println(F("AHT10 gefunden")); Serial.println(F("AHT10 gefunden"));
} }
// such BH1730 // such BH1730
if ( I2C_Test(0x29) != 0xFF ) if (I2C_Test(0x29) != 0xFF) {
{
Serial.println("BH1730 gefunden"); Serial.println("BH1730 gefunden");
} }
// such BH1750 // such BH1750
if ( I2C_Test(0x23) != 0xFF ) if (I2C_Test(0x23) != 0xFF) {
{
Serial.println("BH1750 gefunden"); Serial.println("BH1750 gefunden");
BH1750_Init(); BH1750_Init();
} }
@ -66,11 +60,10 @@ Serial.println("ende");
} }
//-------------------------- //--------------------------
void MessenSensoren(void) void MessenSensoren() {
{ int i;
int i,status, error;
float t, p, h; float t, p, h;
long lVisLux; unsigned int lVisLux;
Set_I2C_Adresse(BME280_ADR); Set_I2C_Adresse(BME280_ADR);
@ -78,14 +71,12 @@ i = I2C_read8(BME280_REGISTER_CHIPID);
bme280_readCoefficients(); bme280_readCoefficients();
if ( i== 0x58) if (i == 0x58) {
{
I2C_write8(BME280_REGISTER_CONTROL, 0x3F); I2C_write8(BME280_REGISTER_CONTROL, 0x3F);
delay(50); // gib ihm Zeit zum messen delay(50); // gib ihm Zeit zum messen
} }
if ( i== 0x60) if (i == 0x60) {
{
//Set before CONTROL_meas (DS 5.4.3) //Set before CONTROL_meas (DS 5.4.3)
I2C_write8(BME280_REGISTER_CONTROLHUMID, 0x05); //16x oversampling I2C_write8(BME280_REGISTER_CONTROLHUMID, 0x05); //16x oversampling
I2C_write8(BME280_REGISTER_CONTROL, 0xB7); // 16x ovesampling, normal mode I2C_write8(BME280_REGISTER_CONTROL, 0xB7); // 16x ovesampling, normal mode
@ -96,14 +87,13 @@ if ( i== 0x60)
//---------------- //----------------
t = bme280_readTemperature(); t = bme280_readTemperature();
p = bme280_readPressure()/100.0; p = bme280_readPressure() / 100.0f;
h = bme280_readHumidity(); h = bme280_readHumidity();
I2C_write8(BME280_REGISTER_CONTROL, 0x3C); // Sleep Mode I2C_write8(BME280_REGISTER_CONTROL, 0x3C); // Sleep Mode
// such BH1750 // such BH1750
if ( I2C_Test(0x23) != 0xFF ) if (I2C_Test(0x23) != 0xFF) {
{
// BH1750 = HY30 Licht Sensor // BH1750 = HY30 Licht Sensor
BH1750_Init(); BH1750_Init();
lVisLux = BH1750_ReadLux(); lVisLux = BH1750_ReadLux();
@ -134,7 +124,4 @@ Serial.println(lVisLux);
// hse.addVoltage(fUb/1000.0); // in Volt // hse.addVoltage(fUb/1000.0); // in Volt
// hse.addCounter(uiOnStd); // Zeit On // hse.addCounter(uiOnStd); // Zeit On
} }

19
src/main.cpp

@ -40,20 +40,6 @@
#include "hseSensorProtocol.h" #include "hseSensorProtocol.h"
#include "MessenSensoren.h" #include "MessenSensoren.h"
//
// For normal use, we require that you edit the sketch to replace FILLMEIN
// with values assigned by the TTN console. However, for regression tests,
// we want to be able to compile these scripts. The regression tests define
// COMPILE_REGRESSION_TEST, and in that case we define FILLMEIN to a non-
// working but innocuous value.
//
#ifdef COMPILE_REGRESSION_TEST
# define FILLMEIN 0
#else
# warning "You must replace the values marked FILLMEIN with real values from the TTN control panel!"
# define FILLMEIN (##)
#endif
// This EUI must be in little-endian format, so least-significant-byte // This EUI must be in little-endian format, so least-significant-byte
// first. When copying an EUI from ttnctl output, this means to reverse // first. When copying an EUI from ttnctl output, this means to reverse
// the bytes. For TTN issued EUIs the last bytes should be 0xD5, 0xB3, // the bytes. For TTN issued EUIs the last bytes should be 0xD5, 0xB3,
@ -75,7 +61,6 @@ static const u1_t PROGMEM APPKEY[16] = {0xca, 0x96, 0x9a, 0x15, 0x76, 0x5d, 0xaf
void os_getDevKey(u1_t *buf) { memcpy_P(buf, APPKEY, 16); } void os_getDevKey(u1_t *buf) { memcpy_P(buf, APPKEY, 16); }
static uint8_t mydata[] = "Hello, world!"; static uint8_t mydata[] = "Hello, world!";
static osjob_t sendjob; static osjob_t sendjob;
@ -143,8 +128,7 @@ void printHex2(unsigned v) {
} }
void do_send(__attribute__((unused)) osjob_t *j) {
void do_send(osjob_t *j) {
// Check if there is not a current TX/RX job running // Check if there is not a current TX/RX job running
if (LMIC.opmode & OP_TXRXPEND) { if (LMIC.opmode & OP_TXRXPEND) {
Serial.println(F("OP_TXRXPEND, not sending")); Serial.println(F("OP_TXRXPEND, not sending"));
@ -226,7 +210,6 @@ void onEvent(ev_t ev) {
case EV_REJOIN_FAILED: case EV_REJOIN_FAILED:
Serial.println(F("EV_REJOIN_FAILED")); Serial.println(F("EV_REJOIN_FAILED"));
break; break;
break;
case EV_TXCOMPLETE: case EV_TXCOMPLETE:
Serial.println(F("EV_TXCOMPLETE (includes waiting for RX windows)")); Serial.println(F("EV_TXCOMPLETE (includes waiting for RX windows)"));
if (LMIC.txrxFlags & TXRX_ACK) if (LMIC.txrxFlags & TXRX_ACK)

Loading…
Cancel
Save