UppSense17- Open Source sensor for chemical analysis based on fuoresence.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

86 lines
2.3 KiB

7 years ago
#include <user_config.h>
#include <SmingCore/SmingCore.h>
#include <SmingCore/HardwareSerial.h>
#include "ads101x.h"
#include "sensor_hub.h"
#include "sensor_settings.h"
#include "double_buffer.h"
#include "web_interface.h"
#include <stdint.h>
7 years ago
#define LED_PIN 2 // GPIO2
static const int HUB_PERIOD = 5;
static const int ADC_TIMEBASE = 250;
static const int ADC_PERIOD = 5;
static const uint8_t ADC_ADDRESS = 0x48;
7 years ago
using namespace rijnfel;
void STADisconnect(String ssid, uint8_t ssid_len, uint8_t bssid[6],
uint8_t reason);
void STAGotIP(IPAddress ip, IPAddress mask, IPAddress gateway);
7 years ago
Timer procTimer;
ads::cADS101x adc(0, ADC_ADDRESS);
7 years ago
uint8_t channel = 0;
cSensorHub hub(HUB_PERIOD);
int test = 0;
void updateSensorHub() {
hub.Update();
}
void adcCallback(cDoubleBuffer<ads::ads_sample_t> & buffer) {
7 years ago
channel++;
if (channel > 3) {
channel = 0;
cWebInterface::GetInstance()->PrintValues();
7 years ago
}
cWebInterface::GetInstance()->UpdateAdc(adc, buffer);
adc.SetMux(static_cast<ads::eInputMux>(ads::eInputMux::AIN_0 + channel));
7 years ago
}
void init() {
spiffs_mount();
7 years ago
Serial.begin(460800);
Wire.pins(4, 5);
7 years ago
Wire.begin();
//SET higher CPU freq & disable wifi sleep
system_update_cpu_freq(SYS_CPU_160MHZ);
wifi_set_sleep_type(NONE_SLEEP_T);
//WDT.enable(false);
7 years ago
pinMode(LED_PIN, OUTPUT);
adc.SetMux(ads::eInputMux::AIN_0);
adc.SetSampleSpeed(ads::eSampleSpeed::SPS_3300);
hub.SetAdc(&adc);
cSensorSettings<ads::ads_sample_t> * adcSettings;
adcSettings = new cSensorSettings<ads::ads_sample_t>(&adcCallback,
ADC_TIMEBASE, ADC_PERIOD);
hub.SetAdcSettings(adcSettings);
WifiEvents.onStationDisconnect(STADisconnect);
WifiEvents.onStationGotIP(STAGotIP);
/* WifiAccessPoint.setIP(IPAddress(10, 0, 0, 1)); //TODO
WifiAccessPoint.config("Sensus", "", AUTH_OPEN, false, 3);*/
cWebInterface::GetInstance()->Start();
procTimer.initializeMs(HUB_PERIOD, updateSensorHub).start();
}
void STADisconnect(String ssid, uint8_t ssid_len, uint8_t bssid[6],
uint8_t reason) {
if (!WifiAccessPoint.isEnabled()) {
WifiStation.disconnect();
WifiAccessPoint.enable(true);
WifiStation.connect();
}
}
void STAGotIP(IPAddress ip, IPAddress mask, IPAddress gateway) {
if (WifiAccessPoint.isEnabled()) {
WifiAccessPoint.enable(false);
}
// Add commands to be executed after successfully connecting to AP and got IP from it
7 years ago
}