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.

131 lines
3.5 KiB

7 years ago
#include <user_config.h>
#include <SmingCore/SmingCore.h>
#include <SmingCore/HardwareSerial.h>
#include "ads101x.h"
#include <hardware.h>
#include "excitation_light.h"
#include "sensor_hub.h"
#include "sensor_settings.h"
#include "double_buffer.h"
#include "web_interface.h"
#include <stdint.h>
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;
Timer rectangleTimer;
ads::cADS101x adc(0, ADC_ADDRESS);
7 years ago
uint8_t channel = 0;
light::cExcitationLight mylight;
7 years ago
cSensorHub hub(HUB_PERIOD);
void SettingsTest() {
channel++;
if (channel > 3) {
channel = 0;
cWebInterface::GetInstance()->PrintValues();
}
adc.SetMux(static_cast<ads::eInputMux>(ads::eInputMux::AIN_0 + channel));
Serial.printf("Settings: %d\n\r", adc.GetSettings());
}
void AdcTest() {
channel++;
if (channel > 3) {
channel = 0;
}
adc.SetMux(static_cast<ads::eInputMux>(ads::eInputMux::AIN_0 + channel));
ads::ads_sample_t sample = adc.RawSample();
Serial.printf("raw: %d converted: %d channel: %d\n\r", sample.rawSample,
adc.ConvertSample(sample), sample.mux);
}
void updateSensorHub() {
hub.Update();
}
void adcCallback(cDoubleBuffer<ads::ads_sample_t> & buffer) {
7 years ago
channel++;
if (channel > 3) {
channel = 0;
cWebInterface::GetInstance()->PrintValues();
Serial.printf("Settings: %d\n\r", adc.GetSettings());
7 years ago
}
cWebInterface::GetInstance()->UpdateAdc(adc, buffer);
adc.SetMux(static_cast<ads::eInputMux>(ads::eInputMux::AIN_0 + channel));
7 years ago
}
void ready()
{
debugf("READY!");
// If AP is enabled:
debugf("AP. ip: %s mac: %s", WifiAccessPoint.getIP().toString().c_str(), WifiAccessPoint.getMAC().c_str());
}
7 years ago
void init() {
spiffs_mount();
7 years ago
Serial.begin(460800);
system_update_cpu_freq(SYS_CPU_160MHZ);
wifi_set_sleep_type(NONE_SLEEP_T);
System.onReady(ready);
WifiAccessPoint.enable(true);
WifiAccessPoint.setIP(IPAddress(10, 0, 0, 1)); //TODO
WifiAccessPoint.config("UppSense Photometer", "Sexy", AUTH_WPA2_PSK, false, 3, 200);
//scl, sda
Wire.pins(4, 5);
7 years ago
Wire.begin();
//SET higher CPU freq & disable wifi sleep
//WDT.enable(false);
// Turn off LED for measurements
7 years ago
pinMode(LED_PIN, OUTPUT);
digitalWrite(LED_PIN, 1);
7 years ago
adc.SetMux(ads::eInputMux::AIN_0);
adc.SetSampleSpeed(ads::eSampleSpeed::SPS_3300);
adc.SetGain(ads::eGainAmplifier::FSR_4_096);
adc.SetOneShot(false);
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()->StartServer();
procTimer.initializeMs(HUB_PERIOD, updateSensorHub).start();
//procTimer.initializeMs(1000, AdcTest).start();
//procTimer.initializeMs(5000, SettingsTest).start();
//mylight.SetCurrent(5000);
//mylight.RectangleUpdate();
}
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
}