RelayClass
This commit is contained in:
@@ -11,3 +11,8 @@ Adress 0x21
|
||||
## 2.0 LCD
|
||||
The LCD display is driven on the same i2c bus as the keypad.
|
||||
|
||||
nterface Definition
|
||||
BYTE BIT
|
||||
7 (MSB) 6 5 4 3 2 1 0 (LSB)
|
||||
I2C slave address L H L L A2 A1 A0 R/W
|
||||
I/O data bus P7 P6 P5 P4 P3 P2 P1 P0
|
||||
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
+1
-1
@@ -1 +1 @@
|
||||
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><title>doorlock_pwa</title><meta name="viewport" content="width=device-width,initial-scale=1"><meta name="mobile-web-app-capable" content="yes"><meta name="apple-mobile-web-app-capable" content="yes"><link rel="apple-touch-icon" href="/assets/icons/apple-touch-icon.png"><link rel="manifest" href="/manifest.json"><meta name="theme-color" content="#673ab8"><style>*{box-sizing:border-box}html{font-family:Helvetica,sans-serif;font-size:16px}body,html{height:100%}body{background-color:#fff;margin:0;padding:0;width:100%}</style><link href="/bundle.45d14.css" rel="stylesheet" media="only x" onload="this.media='all'"><noscript><link rel="stylesheet" href="/bundle.45d14.css"></noscript></head><body><script defer="defer" src="/bundle.357e7.js"></script><script nomodule="" src="/polyfills.058fb.js"></script></body></html>
|
||||
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><title>doorlock_pwa</title><meta name="viewport" content="width=device-width,initial-scale=1"><meta name="mobile-web-app-capable" content="yes"><meta name="apple-mobile-web-app-capable" content="yes"><link rel="apple-touch-icon" href="/assets/icons/apple-touch-icon.png"><link rel="manifest" href="/manifest.json"><meta name="theme-color" content="#673ab8"><style>*{box-sizing:border-box}html{font-family:Helvetica,sans-serif;font-size:16px}body,html{height:100%}body{background-color:#fff;margin:0;padding:0;width:100%}</style><link href="/bundle.3bf6c.css" rel="stylesheet" media="only x" onload="this.media='all'"><noscript><link rel="stylesheet" href="/bundle.3bf6c.css"></noscript></head><body><script defer="defer" src="/bundle.4bdf3.js"></script><script nomodule="" src="/polyfills.914a6.js"></script></body></html>
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
+7
-5
@@ -1,6 +1,6 @@
|
||||
#include "Config.h"
|
||||
|
||||
Config::Config()
|
||||
Config::Config(const char* filepath): _filepath(filepath)
|
||||
{
|
||||
if (!LittleFS.begin())
|
||||
{
|
||||
@@ -12,10 +12,13 @@ Config::~Config()
|
||||
{
|
||||
free(buffer);
|
||||
}
|
||||
|
||||
bool Config::setFilePath(const char* filepath){
|
||||
this->_filepath = filepath;
|
||||
return loadBin();
|
||||
}
|
||||
bool Config::loadBin()
|
||||
{
|
||||
File config_file = LittleFS.open("/settings", "r");
|
||||
File config_file = LittleFS.open(_filepath, "r");
|
||||
//if (buffer == nullptr) // Allocate only once
|
||||
// buffer = (uint8_t *)malloc(CONFIG_SIZE);
|
||||
if (config_file.available())
|
||||
@@ -23,7 +26,6 @@ bool Config::loadBin()
|
||||
config_file.read(buffer, CONFIG_SIZE);
|
||||
buffer[OFFSET_SSID + 0x1F] = 0x00; // ensure ssid and password are terminated with a null character
|
||||
buffer[OFFSET_PASS + 0x1F] = 0x00;
|
||||
|
||||
}
|
||||
config_file.close();
|
||||
return true;
|
||||
@@ -31,7 +33,7 @@ bool Config::loadBin()
|
||||
|
||||
bool Config::saveBin()
|
||||
{
|
||||
File config_file = LittleFS.open("/settings", "w");
|
||||
File config_file = LittleFS.open(_filepath, "w");
|
||||
config_file.write(buffer, CONFIG_SIZE);
|
||||
delay(100);
|
||||
config_file.close();
|
||||
|
||||
+3
-2
@@ -16,7 +16,7 @@ private:
|
||||
uint8_t *buffer = (uint8_t *)malloc(CONFIG_SIZE);
|
||||
|
||||
public:
|
||||
Config();
|
||||
Config(const char* filepath);
|
||||
~Config();
|
||||
const char *SSID = (char *)(buffer + OFFSET_SSID);
|
||||
const char *PASS = (char *)(buffer + OFFSET_PASS);
|
||||
@@ -26,7 +26,8 @@ public:
|
||||
uint8_t &mode = *(buffer + OFFSET_MODE);
|
||||
uint8_t &fail_timeout = *(buffer+OFFSET_FAIL_TIMEOUT);
|
||||
uint8_t &hold_time = *(buffer+OFFSET_HOLD_TIME);
|
||||
|
||||
const char* _filepath;
|
||||
bool setFilePath(const char* filepath);
|
||||
bool loadConfig();
|
||||
bool loadBin();
|
||||
bool saveBin();
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
#include "Relais.h"
|
||||
|
||||
Relais::Relais(uint8_t pin)
|
||||
{
|
||||
pinMode(pin, OUTPUT);
|
||||
digitalWrite(_pin, 1);
|
||||
_pin = pin;
|
||||
}
|
||||
void Relais::cylce()
|
||||
{
|
||||
if (!_state)
|
||||
return;
|
||||
if (millis() > _call_time)
|
||||
{
|
||||
digitalWrite(_pin, 1);
|
||||
_state = false;
|
||||
Serial.println("Relay released.");
|
||||
}
|
||||
}
|
||||
void Relais::activate(uint8_t seconds)
|
||||
{
|
||||
Serial.println("Relay activated for "+String(seconds)+" Seconds.");
|
||||
digitalWrite(_pin, 0);
|
||||
_state = true;
|
||||
_call_time = millis() + seconds * 1000;
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
#pragma once
|
||||
#include <Arduino.h>
|
||||
#include <Wire.h>
|
||||
|
||||
class Relais
|
||||
{
|
||||
public:
|
||||
Relais(uint8_t pin);
|
||||
void cylce();
|
||||
void activate(uint8_t seconds);
|
||||
|
||||
private:
|
||||
unsigned long _call_time = 0;
|
||||
bool _state = false;
|
||||
uint8_t _pin;
|
||||
};
|
||||
+4
-3
@@ -1,8 +1,8 @@
|
||||
#include "Rfid.h"
|
||||
#define SS_PIN D8
|
||||
#define RST_PIN D1
|
||||
#define RST_PIN D0
|
||||
#define RFID_TIMEOUT 3000
|
||||
Rfid::Rfid(/* args */) : _mfrc522(SS_PIN)
|
||||
Rfid::Rfid(/* args */) : _mfrc522(SS_PIN, RST_PIN)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -33,11 +33,12 @@ void Rfid::scan()
|
||||
{
|
||||
_status = 1;
|
||||
#ifdef DEBUG
|
||||
Serial.print(this->_rfid);
|
||||
_mfrc522.PICC_DumpToSerial(&(_mfrc522.uid));
|
||||
#endif
|
||||
this->_lastRfid = this->_rfid;
|
||||
this->_lastRfidScan = millis();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+6
-3
@@ -8,17 +8,18 @@
|
||||
#include "WebConsole.h"
|
||||
#include "UserDb.h"
|
||||
#include "Config.h"
|
||||
#include "Relais.h"
|
||||
|
||||
// File config
|
||||
Config config;
|
||||
userdb::UserDb userdatabase("userdb.csv");
|
||||
Config config("/settings");
|
||||
userdb::UserDb userdatabase("/userdb.csv");
|
||||
webconsole::WebConsole web;
|
||||
// Rfid
|
||||
Rfid rfid;
|
||||
// i2C Bus
|
||||
#define PIN_WIRE_SDA D3
|
||||
#define PIN_WIRE_SCL D4
|
||||
|
||||
Relais relay(D1);
|
||||
Keyboard keyboard(200);
|
||||
Interface iface;
|
||||
void setup()
|
||||
@@ -38,6 +39,7 @@ void setup()
|
||||
|
||||
void loop()
|
||||
{
|
||||
relay.cylce();
|
||||
rfid.scan();
|
||||
web.serve();
|
||||
keyboard.scanAsync();
|
||||
@@ -74,6 +76,7 @@ void loop()
|
||||
{
|
||||
iface.greetUser(login_user.first_name + " " + login_user.last_name);
|
||||
Serial.println("Logon from User " + login_user.toString());
|
||||
relay.activate(config.hold_time);
|
||||
}
|
||||
iface.render();
|
||||
}
|
||||
Reference in New Issue
Block a user