mirror of
https://github.com/sascha-hemi/HGD4_reversed.git
synced 2026-03-21 02:03:56 +01:00
clean up code
This commit is contained in:
5
HGD4_reversed/.gitignore
vendored
Normal file
5
HGD4_reversed/.gitignore
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
.pio
|
||||
.vscode/.browse.c_cpp.db*
|
||||
.vscode/c_cpp_properties.json
|
||||
.vscode/launch.json
|
||||
.vscode/ipch
|
||||
10
HGD4_reversed/.vscode/extensions.json
vendored
Normal file
10
HGD4_reversed/.vscode/extensions.json
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
{
|
||||
// See http://go.microsoft.com/fwlink/?LinkId=827846
|
||||
// for the documentation about the extensions.json format
|
||||
"recommendations": [
|
||||
"platformio.platformio-ide"
|
||||
],
|
||||
"unwantedRecommendations": [
|
||||
"ms-vscode.cpptools-extension-pack"
|
||||
]
|
||||
}
|
||||
@@ -8,7 +8,7 @@
|
||||
; Please visit documentation for the other options and examples
|
||||
; https://docs.platformio.org/page/projectconf.html
|
||||
|
||||
[env:nrf52840_dk]
|
||||
[env:hgd6]
|
||||
platform = nordicnrf52
|
||||
board = hgd6
|
||||
framework = arduino
|
||||
|
||||
@@ -1,58 +1,16 @@
|
||||
#include <Arduino.h>
|
||||
#include <Wire.h>
|
||||
#include "ens210.h" // ENS210 library
|
||||
#include "SparkFun_VEML6030_Ambient_Light_Sensor.h"
|
||||
#include <SPI.h>
|
||||
#include <Adafruit_LIS3DH.h>
|
||||
#include <Adafruit_Sensor.h>
|
||||
|
||||
#define LIS3DH_CS 6
|
||||
|
||||
#define AL_ADDR 0x29
|
||||
#include "main.h"
|
||||
|
||||
SparkFun_Ambient_Light light(AL_ADDR);
|
||||
|
||||
ENS210 ens210;
|
||||
|
||||
Adafruit_LIS3DH lis = Adafruit_LIS3DH(LIS3DH_CS);
|
||||
|
||||
void busscan();
|
||||
void measuretemp();
|
||||
void lightsense();
|
||||
void powerupesp();
|
||||
|
||||
void in1_handler() {
|
||||
digitalWrite(DONE,HIGH);
|
||||
delay(1);
|
||||
digitalWrite(DONE,LOW);
|
||||
}
|
||||
Adafruit_LIS3DH acc1 = Adafruit_LIS3DH(ACCL1_CS);
|
||||
Adafruit_LIS3DH acc2 = Adafruit_LIS3DH(ACCL2_CS);
|
||||
|
||||
void setup() {
|
||||
//latch on the main power
|
||||
pinMode(PWR_LATCH , OUTPUT);
|
||||
digitalWrite(PWR_LATCH , HIGH);
|
||||
//setup watchdog feeding
|
||||
pinMode(WAKE, INPUT);
|
||||
pinMode(DONE, OUTPUT);
|
||||
attachInterrupt(digitalPinToInterrupt(WAKE), in1_handler, RISING);
|
||||
//setup Serial
|
||||
Serial.begin(115200);
|
||||
//setup I2C bus
|
||||
Wire.begin();
|
||||
//set i2c pins
|
||||
pinMode(I2C_SDA, OUTPUT);
|
||||
//needed for some boards
|
||||
in1_handler();
|
||||
//set up leds
|
||||
pinMode(RED_LED,OUTPUT);
|
||||
pinMode(GREEN_LED,OUTPUT);
|
||||
delay(100);
|
||||
digitalWrite(RED_LED,HIGH);
|
||||
digitalWrite(GREEN_LED,HIGH);
|
||||
gpioinit();
|
||||
}
|
||||
|
||||
int ptt = 0;
|
||||
|
||||
void loop() {
|
||||
Serial.println("loop");
|
||||
busscan();
|
||||
@@ -63,57 +21,68 @@ void loop() {
|
||||
delay(1000);
|
||||
}
|
||||
|
||||
void wd_handler() {
|
||||
digitalWrite(DONE,HIGH);
|
||||
delay(1);
|
||||
digitalWrite(DONE,LOW);
|
||||
}
|
||||
|
||||
|
||||
void gpioinit(){
|
||||
//latch on the main power
|
||||
pinMode(PWR_LATCH , OUTPUT);
|
||||
digitalWrite(PWR_LATCH , HIGH);
|
||||
//setup watchdog feeding
|
||||
pinMode(WAKE, INPUT);
|
||||
pinMode(DONE, OUTPUT);
|
||||
attachInterrupt(digitalPinToInterrupt(WAKE), wd_handler, RISING);
|
||||
//setup Serial
|
||||
Serial.begin(115200);
|
||||
//setup I2C bus
|
||||
Wire.begin();
|
||||
//set i2c pins
|
||||
pinMode(I2C_SDA, OUTPUT);
|
||||
//needed for some boards
|
||||
wd_handler();
|
||||
//set up leds
|
||||
pinMode(RED_LED,OUTPUT);
|
||||
pinMode(GREEN_LED,OUTPUT);
|
||||
digitalWrite(RED_LED,HIGH);
|
||||
digitalWrite(GREEN_LED,HIGH);
|
||||
//set all other pins
|
||||
pinMode(MODEM_ESP_PWR,OUTPUT);
|
||||
digitalWrite(MODEM_ESP_PWR,LOW);
|
||||
pinMode(ESP_PWR,OUTPUT);
|
||||
digitalWrite(ESP_PWR,LOW);
|
||||
pinMode(MODEM_PWRKEY,OUTPUT);
|
||||
digitalWrite(MODEM_PWRKEY,LOW);
|
||||
}
|
||||
|
||||
void powerupesp(){
|
||||
Serial.println("powering up esp");
|
||||
pinMode(29,OUTPUT);
|
||||
digitalWrite(29,HIGH);
|
||||
pinMode(45,OUTPUT);
|
||||
digitalWrite(45,HIGH);
|
||||
delay(600);
|
||||
Serial.println("Powering up esp");
|
||||
digitalWrite(MODEM_ESP_PWR,HIGH);
|
||||
digitalWrite(ESP_PWR,HIGH);
|
||||
delay(500);
|
||||
}
|
||||
|
||||
void powerupmodem(){
|
||||
Serial.println("powering up modem");
|
||||
pinMode(29,OUTPUT);
|
||||
digitalWrite(29,HIGH);
|
||||
digitalWrite(MODEM_ESP_PWR,HIGH);
|
||||
delay(600);
|
||||
pinMode(34,OUTPUT);
|
||||
digitalWrite(34,HIGH);
|
||||
digitalWrite(MODEM_PWRKEY,HIGH);
|
||||
delay(600);
|
||||
digitalWrite(34,LOW);
|
||||
digitalWrite(MODEM_PWRKEY,LOW);
|
||||
delay(600);
|
||||
}
|
||||
|
||||
void lightsense(){
|
||||
|
||||
// Possible values: .125, .25, 1, 2
|
||||
// Both .125 and .25 should be used in most cases except darker rooms.
|
||||
// A gain of 2 should only be used if the sensor will be covered by a dark
|
||||
// glass.
|
||||
float gain = .125;
|
||||
|
||||
// Possible integration times in milliseconds: 800, 400, 200, 100, 50, 25
|
||||
// Higher times give higher resolutions and should be used in darker light.
|
||||
float gain = .25;
|
||||
int time = 100;
|
||||
long luxVal = 0;
|
||||
if(light.begin())
|
||||
Serial.println("Ready to sense some light!");
|
||||
else
|
||||
Serial.println("Could not communicate with the sensor!");
|
||||
|
||||
// Again the gain and integration times determine the resolution of the lux
|
||||
// value, and give different ranges of possible light readings. Check out
|
||||
// hoookup guide for more info.
|
||||
if(!light.begin())
|
||||
Serial.println("Could not communicate with the light sensor!");
|
||||
light.setGain(gain);
|
||||
light.setIntegTime(time);
|
||||
|
||||
Serial.println("Reading settings...");
|
||||
Serial.print("Gain: ");
|
||||
float gainVal = light.readGain();
|
||||
Serial.print(gainVal, 3);
|
||||
Serial.print(" Integration Time: ");
|
||||
int timeVal = light.readIntegTime();
|
||||
Serial.println(timeVal);
|
||||
luxVal = light.readLight();
|
||||
Serial.print("Ambient Light Reading: ");
|
||||
Serial.print(luxVal);
|
||||
@@ -124,11 +93,9 @@ void measuretemp(){
|
||||
ens210.begin();
|
||||
int t_data, t_status, h_data, h_status;
|
||||
ens210.measure(&t_data, &t_status, &h_data, &h_status );
|
||||
|
||||
Serial.print( ens210.toCelsius(t_data,10)/10.0, 1 ); Serial.print(" C, ");
|
||||
Serial.print( ens210.toPercentageH(h_data,1) ); Serial.print(" %RH");
|
||||
Serial.println();
|
||||
|
||||
}
|
||||
|
||||
void busscan(){
|
||||
@@ -140,9 +107,6 @@ void busscan(){
|
||||
nDevices = 0;
|
||||
for(address = 1; address < 127; address++ )
|
||||
{
|
||||
// The i2c_scanner uses the return value of
|
||||
// the Write.endTransmisstion to see if
|
||||
// a device did acknowledge to the address.
|
||||
Wire.beginTransmission(address);
|
||||
error = Wire.endTransmission();
|
||||
|
||||
|
||||
14
HGD4_reversed/src/main.h
Normal file
14
HGD4_reversed/src/main.h
Normal file
@@ -0,0 +1,14 @@
|
||||
#include <Arduino.h>
|
||||
#include <Wire.h>
|
||||
#include <SPI.h>
|
||||
#include <Adafruit_LIS3DH.h>
|
||||
#include <Adafruit_Sensor.h>
|
||||
#include "ens210.h"
|
||||
#include "SparkFun_VEML6030_Ambient_Light_Sensor.h"
|
||||
|
||||
void busscan();
|
||||
void measuretemp();
|
||||
void lightsense();
|
||||
void powerupesp();
|
||||
void wd_handler();
|
||||
void gpioinit();
|
||||
@@ -96,6 +96,8 @@ static const uint8_t SCK = PIN_SPI_SCK ;
|
||||
static const uint8_t SDA = PIN_WIRE_SDA;
|
||||
static const uint8_t SCL = PIN_WIRE_SCL;
|
||||
|
||||
#define AL_ADDR 0x29
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user