working 1
This commit is contained in:
@@ -1,5 +1,9 @@
|
||||
#include <FanStateService.h>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
FanStateService::FanStateService(AsyncWebServer* server, FS* fs, SecurityManager* securityManager) :
|
||||
_httpEndpoint(FanSettings::read,
|
||||
FanSettings::update,
|
||||
@@ -24,7 +28,24 @@ void FanStateService::begin() {
|
||||
_state.fanStatus = DEFAULT_FAN_STATE;
|
||||
Serial.println("Starting The Fan Service + read from FS");
|
||||
_fsPersistence.readFromFS();
|
||||
|
||||
this->oneWire1.begin(_state.OneWireGPIO);
|
||||
this->sensor_intake.setOneWire(&this->oneWire1);
|
||||
this->sensor_intake.begin();
|
||||
|
||||
// attachInterrupt(_state.fanTachGPIO,handleInterrupt,RISING);
|
||||
|
||||
onConfigUpdated();
|
||||
lastpoll = millis();
|
||||
}
|
||||
|
||||
void FanStateService::SetLastPoll(unsigned long l) {
|
||||
this->lastpoll = l;
|
||||
|
||||
}
|
||||
|
||||
int FanStateService::getTachGPIO() {
|
||||
return _state.fanTachGPIO;
|
||||
}
|
||||
|
||||
void FanStateService::onConfigUpdated() {
|
||||
@@ -37,3 +58,13 @@ void FanStateService::save() {
|
||||
Serial.println(" ** Fan Write to FS ");
|
||||
_fsPersistence.writeToFS();
|
||||
}
|
||||
|
||||
void FanStateService::compute() {
|
||||
unsigned long period = millis() - this->lastpoll;
|
||||
this->sensor_intake.requestTemperatures();
|
||||
this->Tin = this->sensor_intake.getTempCByIndex(0);
|
||||
this->Tout = this->sensor_intake.getTempCByIndex(1);
|
||||
float curRpm = 60000/period*this->RPM/2; // Hall sensor = 2 tick per rotation
|
||||
Serial.print("Intake: " + (String) this->Tin + " - " + (String) this->Tout + " ["+ (String) curRpm + " RPM ]\n");
|
||||
this->RPM=0;
|
||||
}
|
||||
53
src/main.cpp
53
src/main.cpp
@@ -5,36 +5,25 @@
|
||||
*/
|
||||
#include <FanStateService.h>
|
||||
|
||||
#include <OneWire.h>
|
||||
#include <DallasTemperature.h>
|
||||
|
||||
|
||||
#define ONE_WIRE_BUS 14
|
||||
#define SERIAL_BAUD_RATE 115200
|
||||
#define PWM_PROBE_MS 5000
|
||||
|
||||
OneWire oneWire1(ONE_WIRE_BUS);
|
||||
DallasTemperature sensor_intake(&oneWire1);
|
||||
|
||||
AsyncWebServer server(80);
|
||||
|
||||
ESP8266React esp8266React(&server);
|
||||
FanStateService fanStateService = FanStateService(&server,esp8266React.getFS(),esp8266React.getSecurityManager());
|
||||
|
||||
|
||||
struct fanMonitor {
|
||||
unsigned long last_poll;
|
||||
unsigned int rpmcount;
|
||||
unsigned int last_time;
|
||||
};
|
||||
|
||||
void ICACHE_RAM_ATTR handleInterrupt( struct fanMonitor &fm ) {
|
||||
fm.rpmcount++;
|
||||
if( fm.rpmcount > 100 ) {
|
||||
fm.rpmcount=0;
|
||||
Serial.println("100 RPM");
|
||||
}
|
||||
void ICACHE_RAM_ATTR handleInterrupt() {
|
||||
fanStateService.RPM++;
|
||||
}
|
||||
|
||||
fanMonitor fm;
|
||||
|
||||
|
||||
|
||||
void setup() {
|
||||
// start serial and filesystem
|
||||
@@ -45,7 +34,6 @@ void setup() {
|
||||
|
||||
// load the initial light settings
|
||||
fanStateService.begin();
|
||||
sensor_intake.begin();
|
||||
|
||||
// Serial.println(" FAN GPIO = " + fanStateService.fan);
|
||||
|
||||
@@ -54,14 +42,22 @@ void setup() {
|
||||
lightMqttSettingsService.begin();
|
||||
*/
|
||||
|
||||
|
||||
|
||||
// pinMode(14,INPUT); // 14 = D5
|
||||
// attachInterrupt(digitalPinToInterrupt(14), handleInterrupt, RISING);
|
||||
|
||||
Serial.println("================= SETUP ================== ");
|
||||
Serial.println("Configure pin " + (String)fanStateService.getTachGPIO());
|
||||
pinMode(fanStateService.getTachGPIO(),INPUT);
|
||||
attachInterrupt(fanStateService.getTachGPIO(),handleInterrupt,RISING);
|
||||
|
||||
Serial.println("================= END ================== ");
|
||||
|
||||
|
||||
// start the server
|
||||
server.begin();
|
||||
|
||||
fm.last_poll=millis();
|
||||
|
||||
pinMode(14,INPUT); // 14 = D5
|
||||
// attachInterrupt(digitalPinToInterrupt(14), handleInterrupt, RISING);
|
||||
// attachInterrupt(14,handleInterrupt,RISING);
|
||||
|
||||
}
|
||||
|
||||
@@ -70,14 +66,9 @@ void setup() {
|
||||
void loop() {
|
||||
// run the framework's loop function
|
||||
|
||||
if( ( millis() - fm.last_poll ) > PWM_PROBE_MS ) {
|
||||
fm.last_poll = millis();
|
||||
Serial.print((String) fm.last_poll + " - Compute");
|
||||
sensor_intake.requestTemperatures();
|
||||
float T1 = sensor_intake.getTempCByIndex(0);
|
||||
float T2 = sensor_intake.getTempCByIndex(1);
|
||||
Serial.print("Intake: " + (String) T1 + " - " + (String) T2 + "\n");
|
||||
|
||||
if( ( millis() - fanStateService.lastpoll ) > PWM_PROBE_MS ) {
|
||||
fanStateService.compute();
|
||||
fanStateService.SetLastPoll(millis());
|
||||
}
|
||||
|
||||
esp8266React.loop();
|
||||
|
||||
Reference in New Issue
Block a user