RelayClass

This commit is contained in:
Jean Jacques Avril 2022-04-10 15:13:23 +02:00
parent 156e095d4d
commit c6ad3f2259
14 changed files with 73 additions and 19 deletions

View File

@ -11,3 +11,8 @@ Adress 0x21
## 2.0 LCD ## 2.0 LCD
The LCD display is driven on the same i2c bus as the keypad. 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

1
data/s/bundle.3bf6c.css Normal file

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

2
data/s/bundle.4bdf3.js Normal file

File diff suppressed because one or more lines are too long

View File

@ -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

View File

@ -1,6 +1,6 @@
#include "Config.h" #include "Config.h"
Config::Config() Config::Config(const char* filepath): _filepath(filepath)
{ {
if (!LittleFS.begin()) if (!LittleFS.begin())
{ {
@ -12,10 +12,13 @@ Config::~Config()
{ {
free(buffer); free(buffer);
} }
bool Config::setFilePath(const char* filepath){
this->_filepath = filepath;
return loadBin();
}
bool Config::loadBin() bool Config::loadBin()
{ {
File config_file = LittleFS.open("/settings", "r"); File config_file = LittleFS.open(_filepath, "r");
//if (buffer == nullptr) // Allocate only once //if (buffer == nullptr) // Allocate only once
// buffer = (uint8_t *)malloc(CONFIG_SIZE); // buffer = (uint8_t *)malloc(CONFIG_SIZE);
if (config_file.available()) if (config_file.available())
@ -23,7 +26,6 @@ bool Config::loadBin()
config_file.read(buffer, CONFIG_SIZE); config_file.read(buffer, CONFIG_SIZE);
buffer[OFFSET_SSID + 0x1F] = 0x00; // ensure ssid and password are terminated with a null character buffer[OFFSET_SSID + 0x1F] = 0x00; // ensure ssid and password are terminated with a null character
buffer[OFFSET_PASS + 0x1F] = 0x00; buffer[OFFSET_PASS + 0x1F] = 0x00;
} }
config_file.close(); config_file.close();
return true; return true;
@ -31,7 +33,7 @@ bool Config::loadBin()
bool Config::saveBin() bool Config::saveBin()
{ {
File config_file = LittleFS.open("/settings", "w"); File config_file = LittleFS.open(_filepath, "w");
config_file.write(buffer, CONFIG_SIZE); config_file.write(buffer, CONFIG_SIZE);
delay(100); delay(100);
config_file.close(); config_file.close();

View File

@ -16,7 +16,7 @@ private:
uint8_t *buffer = (uint8_t *)malloc(CONFIG_SIZE); uint8_t *buffer = (uint8_t *)malloc(CONFIG_SIZE);
public: public:
Config(); Config(const char* filepath);
~Config(); ~Config();
const char *SSID = (char *)(buffer + OFFSET_SSID); const char *SSID = (char *)(buffer + OFFSET_SSID);
const char *PASS = (char *)(buffer + OFFSET_PASS); const char *PASS = (char *)(buffer + OFFSET_PASS);
@ -26,7 +26,8 @@ public:
uint8_t &mode = *(buffer + OFFSET_MODE); uint8_t &mode = *(buffer + OFFSET_MODE);
uint8_t &fail_timeout = *(buffer+OFFSET_FAIL_TIMEOUT); uint8_t &fail_timeout = *(buffer+OFFSET_FAIL_TIMEOUT);
uint8_t &hold_time = *(buffer+OFFSET_HOLD_TIME); uint8_t &hold_time = *(buffer+OFFSET_HOLD_TIME);
const char* _filepath;
bool setFilePath(const char* filepath);
bool loadConfig(); bool loadConfig();
bool loadBin(); bool loadBin();
bool saveBin(); bool saveBin();

26
src/Relais.cpp Normal file
View File

@ -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;
}

16
src/Relais.h Normal file
View File

@ -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;
};

View File

@ -1,8 +1,8 @@
#include "Rfid.h" #include "Rfid.h"
#define SS_PIN D8 #define SS_PIN D8
#define RST_PIN D1 #define RST_PIN D0
#define RFID_TIMEOUT 3000 #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; _status = 1;
#ifdef DEBUG #ifdef DEBUG
Serial.print(this->_rfid); _mfrc522.PICC_DumpToSerial(&(_mfrc522.uid));
#endif #endif
this->_lastRfid = this->_rfid; this->_lastRfid = this->_rfid;
this->_lastRfidScan = millis(); this->_lastRfidScan = millis();
} }
} }
} }

View File

@ -8,17 +8,18 @@
#include "WebConsole.h" #include "WebConsole.h"
#include "UserDb.h" #include "UserDb.h"
#include "Config.h" #include "Config.h"
#include "Relais.h"
// File config // File config
Config config; Config config("/settings");
userdb::UserDb userdatabase("userdb.csv"); userdb::UserDb userdatabase("/userdb.csv");
webconsole::WebConsole web; webconsole::WebConsole web;
// Rfid // Rfid
Rfid rfid; Rfid rfid;
// i2C Bus // i2C Bus
#define PIN_WIRE_SDA D3 #define PIN_WIRE_SDA D3
#define PIN_WIRE_SCL D4 #define PIN_WIRE_SCL D4
Relais relay(D1);
Keyboard keyboard(200); Keyboard keyboard(200);
Interface iface; Interface iface;
void setup() void setup()
@ -38,6 +39,7 @@ void setup()
void loop() void loop()
{ {
relay.cylce();
rfid.scan(); rfid.scan();
web.serve(); web.serve();
keyboard.scanAsync(); keyboard.scanAsync();
@ -74,6 +76,7 @@ void loop()
{ {
iface.greetUser(login_user.first_name + " " + login_user.last_name); iface.greetUser(login_user.first_name + " " + login_user.last_name);
Serial.println("Logon from User " + login_user.toString()); Serial.println("Logon from User " + login_user.toString());
relay.activate(config.hold_time);
} }
iface.render(); iface.render();
} }