mirror of
https://github.com/usatiuk/EggbotWireless.git
synced 2025-10-26 16:57:48 +01:00
disable 12v after 20s of inactivity
This commit is contained in:
9
Firmware/EggbotWireless/include/Globals.h
Normal file
9
Firmware/EggbotWireless/include/Globals.h
Normal file
@@ -0,0 +1,9 @@
|
||||
#ifndef GLOBALS_H
|
||||
#define GLOBALS_H
|
||||
|
||||
#include <Arduino.h>
|
||||
#include "Power.h"
|
||||
|
||||
Power power;
|
||||
|
||||
#endif // GLOBALS_H
|
||||
@@ -6,10 +6,14 @@
|
||||
#include "Config.h"
|
||||
|
||||
class Power {
|
||||
private:
|
||||
bool enabled12v = false;
|
||||
|
||||
public:
|
||||
Power();
|
||||
void disable12v();
|
||||
void enable12v();
|
||||
bool isEnabled12v();
|
||||
};
|
||||
|
||||
#endif // POWER_H
|
||||
@@ -2,9 +2,19 @@
|
||||
|
||||
Power::Power() {
|
||||
pinMode(pin12v, OUTPUT);
|
||||
enable12v();
|
||||
disable12v();
|
||||
}
|
||||
|
||||
void Power::disable12v() { digitalWrite(pin12v, false); }
|
||||
void Power::disable12v() {
|
||||
digitalWrite(pin12v, false);
|
||||
enabled12v = false;
|
||||
}
|
||||
|
||||
void Power::enable12v() { digitalWrite(pin12v, true); }
|
||||
void Power::enable12v() {
|
||||
digitalWrite(pin12v, true);
|
||||
enabled12v = true;
|
||||
}
|
||||
|
||||
bool Power::isEnabled12v() {
|
||||
return enabled12v;
|
||||
}
|
||||
@@ -2,6 +2,8 @@
|
||||
#include <ESP8266WiFi.h>
|
||||
#include <Ticker.h>
|
||||
#include <Wire.h>
|
||||
#include "Globals.h"
|
||||
#include "Power.h"
|
||||
#include "GCodeParser.h"
|
||||
#include "common/Commands.h"
|
||||
|
||||
@@ -71,18 +73,28 @@ void execCommand(Command command) {
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
Wire.begin(12, 13);
|
||||
pinMode(5, OUTPUT);
|
||||
digitalWrite(5, true);
|
||||
power.enable12v();
|
||||
}
|
||||
|
||||
unsigned long commandTime = 0;
|
||||
constexpr unsigned long commandTimeout = 20000;
|
||||
|
||||
void loop() {
|
||||
if(millis() - commandTime > commandTimeout) {
|
||||
power.disable12v();
|
||||
}
|
||||
while (Serial.available() > 0) {
|
||||
char inChar = Serial.read();
|
||||
inString += inChar;
|
||||
|
||||
if (inChar == '\n') {
|
||||
inString.trim();
|
||||
if(!power.isEnabled12v()){
|
||||
power.enable12v();
|
||||
delay(100);
|
||||
}
|
||||
execCommand(parseGCode(inString));
|
||||
commandTime = millis();
|
||||
unsigned long reqTime = millis();
|
||||
while (waitingForNext) {
|
||||
while (!Wire.available()) {
|
||||
|
||||
Reference in New Issue
Block a user