|  | @ -12,64 +12,95 @@ | 
			
		
	
		
		
			
				
					|  |  | #include "web_interface.h" |  |  | #include "web_interface.h" | 
			
		
	
		
		
			
				
					|  |  | #include "signal_process.h" |  |  | #include "signal_process.h" | 
			
		
	
		
		
			
				
					|  |  | #include "sensor_hub.h" |  |  | #include "sensor_hub.h" | 
			
		
	
		
		
			
				
					|  |  |  |  |  | #include "access_point.h" | 
			
		
	
		
		
			
				
					|  |  | 
 |  |  | 
 | 
			
		
	
		
		
			
				
					|  |  | #include "tests.h" |  |  | #include "tests.h" | 
			
		
	
		
		
			
				
					|  |  | 
 |  |  | 
 | 
			
		
	
		
		
			
				
					|  |  | using namespace rijnfel; |  |  | 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); |  |  |  | 
			
		
	
		
		
			
				
					|  |  | 
 |  |  |  | 
			
		
	
		
		
			
				
					|  |  | cAdsConverter * adsConverter; |  |  | cAdsConverter * adsConverter; | 
			
		
	
		
		
			
				
					|  |  | 
 |  |  | 
 | 
			
		
	
		
		
			
				
					|  |  | //We want different signal processing for the channels
 |  |  | //We want different signal processing for the channels
 | 
			
		
	
		
		
			
				
					|  |  | cSignalProcess signalProcess[2]; |  |  | cSignalProcess signalProcess[2]; | 
			
		
	
		
		
			
				
					|  |  | Timer procTimer; |  |  | Timer procTimer; | 
			
		
	
		
		
			
				
					|  |  | Timer rectangleTimer; |  |  | Timer rectangleTimer; | 
			
		
	
		
		
			
				
					
					|  |  | uint8_t channel = 0; |  |  | Timer _stopTimer; | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					|  |  | light::cExcitationLight mylight; |  |  | light::cExcitationLight mylight; | 
			
		
	
		
		
			
				
					|  |  | cSensorHub hub(HUB_PERIOD); |  |  | cSensorHub hub(HUB_PERIOD); | 
			
		
	
		
		
			
				
					|  |  | ads::cADS101x ads1015(0, ADC_ADDRESS); |  |  | ads::cADS101x ads1015(0, ADC_ADDRESS); | 
			
		
	
		
		
			
				
					|  |  | 
 |  |  | 
 | 
			
		
	
		
		
			
				
					|  |  |  |  |  | static bool _sensorStationRunning = false; | 
			
		
	
		
		
			
				
					|  |  |  |  |  | static bool _keepRunning = false; | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					|  |  |  |  |  | static void UpdateSensorHub() { | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 	WDT.alive(); | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 	hub.Update(); | 
			
		
	
		
		
			
				
					|  |  |  |  |  | } | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					|  |  |  |  |  | static void StopRunning() { | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 	StopSensorStation(); | 
			
		
	
		
		
			
				
					|  |  |  |  |  | } | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					|  |  |  |  |  | void StartSensorStation(int seconds) { | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 	if (_sensorStationRunning) { | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 		return; | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 	} | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 	if (seconds == 0) { | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 		_keepRunning = true; | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 	} else { | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 		_stopTimer.initializeMs(seconds * 1000, StopRunning).start(false); | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 		_keepRunning = false; | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 	} | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 	procTimer.initializeUs(HUB_PERIOD, UpdateSensorHub).start(); | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 	_sensorStationRunning = true; | 
			
		
	
		
		
			
				
					|  |  |  |  |  | } | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					|  |  |  |  |  | void StopSensorStation(void) { | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 	if (!_sensorStationRunning) | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 		return; | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 	if (!_keepRunning) { | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 		_stopTimer.stop(); | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 	} | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 	procTimer.initializeUs(HUB_PERIOD, UpdateSensorHub).stop(); | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 	_sensorStationRunning = false; | 
			
		
	
		
		
			
				
					|  |  |  |  |  | } | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					|  |  | void ChangeSampleChannel(int channel) { |  |  | void ChangeSampleChannel(int channel) { | 
			
		
	
		
		
			
				
					|  |  | 	if (channel > 0 && channel < 5) { |  |  | 	if (channel > 0 && channel < 5) { | 
			
		
	
		
		
			
				
					
					|  |  | 		hub.Stop(); |  |  | 		if (_sensorStationRunning) { | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					|  |  |  |  |  | 			hub.Stop(); | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 		} | 
			
		
	
		
		
			
				
					|  |  | 		ads1015.SetMux(static_cast<ads::eInputMux>(ads::eInputMux::AIN_0 + channel - 1)); |  |  | 		ads1015.SetMux(static_cast<ads::eInputMux>(ads::eInputMux::AIN_0 + channel - 1)); | 
			
		
	
		
		
			
				
					
					|  |  | 		hub.Start(); |  |  | 		if (_sensorStationRunning) { | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					|  |  |  |  |  | 			hub.Start(); | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 		} | 
			
		
	
		
		
			
				
					|  |  | 	} |  |  | 	} | 
			
		
	
		
		
			
				
					|  |  | } |  |  | } | 
			
		
	
		
		
			
				
					|  |  | 
 |  |  | 
 | 
			
		
	
		
		
			
				
					|  |  | void updateSensorHub() { |  |  |  | 
			
		
	
		
		
			
				
					|  |  | 	WDT.alive(); |  |  |  | 
			
		
	
		
		
			
				
					|  |  | 	hub.Update(); |  |  |  | 
			
		
	
		
		
			
				
					|  |  | } |  |  |  | 
			
		
	
		
		
			
				
					|  |  | 
 |  |  |  | 
			
		
	
		
		
			
				
					|  |  | void ready() { |  |  | void ready() { | 
			
		
	
		
		
			
				
					|  |  | 	WifiAccessPoint.config("Sensus", "", AUTH_OPEN, false, 3); |  |  |  | 
			
		
	
		
		
			
				
					|  |  | 	hub.Start(); |  |  | 	hub.Start(); | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 	access_point_config(); | 
			
		
	
		
		
			
				
					|  |  | } |  |  | } | 
			
		
	
		
		
			
				
					|  |  | 
 |  |  | 
 | 
			
		
	
		
		
			
				
					|  |  | void init() { |  |  | void init() { | 
			
		
	
		
		
			
				
					|  |  | 	spiffs_mount(); |  |  | 	spiffs_mount(); | 
			
		
	
		
		
			
				
					|  |  | 	Serial.begin(460800); |  |  | 	Serial.begin(460800); | 
			
		
	
		
		
			
				
					|  |  | 	system_update_cpu_freq(SYS_CPU_160MHZ); |  |  | 	system_update_cpu_freq(SYS_CPU_160MHZ); | 
			
		
	
		
		
			
				
					
					|  |  | 	wifi_set_sleep_type(NONE_SLEEP_T); |  |  | 	access_point_start(); | 
			
				
				
			
		
	
		
		
			
				
					|  |  | 
 |  |  |  | 
			
		
	
		
		
	
		
		
			
				
					|  |  | 	System.onReady(ready); |  |  | 	System.onReady(ready); | 
			
		
	
		
		
			
				
					|  |  | 
 |  |  | 
 | 
			
		
	
		
		
			
				
					|  |  | 	WifiAccessPoint.setIP(IPAddress(10, 0, 0, 1)); |  |  |  | 
			
		
	
		
		
			
				
					|  |  | 	WifiAccessPoint.enable(true); |  |  |  | 
			
		
	
		
		
			
				
					|  |  | 
 |  |  |  | 
			
		
	
		
		
			
				
					|  |  | 	Wire.pins(4, 5); |  |  | 	Wire.pins(4, 5); | 
			
		
	
		
		
			
				
					|  |  | 	Wire.begin(); |  |  | 	Wire.begin(); | 
			
		
	
		
		
			
				
					|  |  | 	//SET higher CPU freq & disable wifi sleep
 |  |  |  | 
			
		
	
		
		
			
				
					|  |  | 
 |  |  | 
 | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 	Serial.systemDebugOutput(false); | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 	delay(10); | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 	system_set_os_print(0); | 
			
		
	
		
		
			
				
					|  |  | 	// Turn off LED for measurements
 |  |  | 	// Turn off LED for measurements
 | 
			
		
	
		
		
			
				
					|  |  | 	hub.Stop(); |  |  | 	hub.Stop(); | 
			
		
	
		
		
			
				
					|  |  | 	pinMode(LED_PIN, OUTPUT); |  |  | 	pinMode(LED_PIN, OUTPUT); | 
			
		
	
		
		
			
				
					|  |  | 	digitalWrite(LED_PIN, 1); |  |  | 	digitalWrite(LED_PIN, 1); | 
			
		
	
		
		
			
				
					|  |  | 	ads1015.SetMux(ads::eInputMux::AIN_0); |  |  | 	ads1015.SetMux(ads::eInputMux::AIN_0); | 
			
		
	
		
		
			
				
					
					|  |  | 	ads1015.SetSampleSpeed(ads::eSampleSpeed::SPS_2400); |  |  | 	ads1015.SetSampleSpeed(ads::eSampleSpeed::SPS_3300); | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					|  |  | 	ads1015.SetGain(ads::eGainAmplifier::FSR_4_096); |  |  | 	ads1015.SetGain(ads::eGainAmplifier::FSR_4_096); | 
			
		
	
		
		
			
				
					|  |  | 	ads1015.SetOneShot(false); |  |  | 	ads1015.SetOneShot(false); | 
			
		
	
		
		
			
				
					|  |  | 	hub.SetAdc(&ads1015); |  |  | 	hub.SetAdc(&ads1015); | 
			
		
	
	
		
		
			
				
					|  | @ -83,31 +114,15 @@ void init() { | 
			
		
	
		
		
			
				
					|  |  | 	// Channel one and two are getting processed
 |  |  | 	// Channel one and two are getting processed
 | 
			
		
	
		
		
			
				
					|  |  | 	adsConverter->m_convertedSamples[0].Connect(&signalProcess[0].m_incommingData); |  |  | 	adsConverter->m_convertedSamples[0].Connect(&signalProcess[0].m_incommingData); | 
			
		
	
		
		
			
				
					|  |  | 	adsConverter->m_convertedSamples[1].Connect(&signalProcess[1].m_incommingData); |  |  | 	adsConverter->m_convertedSamples[1].Connect(&signalProcess[1].m_incommingData); | 
			
		
	
		
		
			
				
					
					|  |  | 	//signalProcess[0].m_processedData.Connect(&cWebInterface::GetInstance()->m_adc_0);
 |  |  | 	signalProcess[0].m_processedData.Connect(&cWebInterface::GetInstance()->m_adc_0); | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  | 	//signalProcess[1].m_processedData.Connect(&cWebInterface::GetInstance()->m_adc_1);
 |  |  | 	signalProcess[1].m_processedData.Connect(&cWebInterface::GetInstance()->m_adc_1); | 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
			
				
					|  |  | 	// Channel three and four are not
 |  |  | 	// Channel three and four are not
 | 
			
		
	
		
		
			
				
					
					|  |  | 	//adsConverter->m_convertedSamples[2].Connect(&cWebInterface::GetInstance()->m_adc_2);
 |  |  | 	adsConverter->m_convertedSamples[2].Connect(&cWebInterface::GetInstance()->m_adc_2); | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  | 	//adsConverter->m_convertedSamples[3].Connect(&cWebInterface::GetInstance()->m_adc_3);
 |  |  | 	adsConverter->m_convertedSamples[3].Connect(&cWebInterface::GetInstance()->m_adc_3); | 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
			
				
					|  |  | 
 |  |  | 
 | 
			
		
	
		
		
			
				
					|  |  | 	WifiEvents.onStationDisconnect(STADisconnect); |  |  |  | 
			
		
	
		
		
			
				
					|  |  | 	WifiEvents.onStationGotIP(STAGotIP); |  |  |  | 
			
		
	
		
		
			
				
					|  |  | 	cWebInterface::GetInstance()->StartServer(); |  |  | 	cWebInterface::GetInstance()->StartServer(); | 
			
		
	
		
		
			
				
					|  |  | 
 |  |  | 
 | 
			
		
	
		
		
			
				
					|  |  | 	procTimer.initializeUs(HUB_PERIOD, updateSensorHub).start(); |  |  |  | 
			
		
	
		
		
			
				
					|  |  | 	mylight.SetCurrent(500); |  |  | 	mylight.SetCurrent(500); | 
			
		
	
		
		
			
				
					|  |  | 	mylight.RectangleUpdate(); |  |  | 	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); |  |  |  | 
			
		
	
		
		
			
				
					|  |  | 	} |  |  |  | 
			
		
	
		
		
			
				
					|  |  | } |  |  |  | 
			
		
	
	
		
		
			
				
					|  | 
 |