initial
This commit is contained in:
68
overCurrentProt.cpp
Normal file
68
overCurrentProt.cpp
Normal file
@ -0,0 +1,68 @@
|
||||
#include <arduino.h>
|
||||
#include <stdint.h>
|
||||
#include "overCurrentProt.h"
|
||||
|
||||
|
||||
|
||||
volatile bool overCurrentMarker;
|
||||
|
||||
void overCurrentProtServiceRoutine() {
|
||||
// switch off current
|
||||
digitalWrite(CURRENT_SHUTDOWN, CURRENT_OFF);
|
||||
|
||||
// set marker
|
||||
overCurrentMarker = true;
|
||||
|
||||
Serial.println("X");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
OverCurrentProtCmd::OverCurrentProtCmd(OverCurrentProt *overCurrentProt) : m_overCurrentProt(overCurrentProt) {
|
||||
}
|
||||
|
||||
String OverCurrentProtCmd::exec(String params) {
|
||||
return String("") + m_overCurrentProt->getEventCnt();
|
||||
}
|
||||
|
||||
OverCurrentResetCmd::OverCurrentResetCmd(OverCurrentProt *overCurrentProt) : m_overCurrentProt(overCurrentProt) {
|
||||
}
|
||||
|
||||
String OverCurrentResetCmd::exec(String params) {
|
||||
m_overCurrentProt->resetEventCnt();
|
||||
return "done";
|
||||
}
|
||||
|
||||
|
||||
|
||||
OverCurrentProt::OverCurrentProt() : m_overCurrentProtCmd(this), m_overCurrentResetCmd(this),
|
||||
m_eventCnt(0), m_timestamp(0) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
void OverCurrentProt::begin(CmdServer *cmdServer) {
|
||||
m_overCurrentProtCmd.registerYourself(cmdServer);
|
||||
m_overCurrentResetCmd.registerYourself(cmdServer);
|
||||
pinMode(CURRENT_SHUTDOWN, OUTPUT);
|
||||
digitalWrite(CURRENT_SHUTDOWN, CURRENT_ON);
|
||||
overCurrentMarker = false;
|
||||
pinMode(CURRENT_INTERRUPT, INPUT);
|
||||
attachInterrupt(CURRENT_INTERRUPT, overCurrentProtServiceRoutine, FALLING);
|
||||
Serial.println("OC ready");
|
||||
}
|
||||
|
||||
|
||||
void OverCurrentProt::exec() {
|
||||
if ((m_timestamp == 0) && overCurrentMarker) {
|
||||
m_eventCnt++;
|
||||
m_timestamp = millis();
|
||||
}
|
||||
|
||||
if ((m_timestamp != 0) && ((m_timestamp + TURN_ON_DELAY) < millis())) {
|
||||
overCurrentMarker = false;
|
||||
m_timestamp = 0;
|
||||
digitalWrite(CURRENT_SHUTDOWN, CURRENT_ON);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user