Added more details to the state machine and updating the inserted value

This commit is contained in:
Jens Noack 2025-03-01 00:19:00 +01:00
parent 90b894a307
commit 5b69468a88
12 changed files with 295 additions and 109 deletions

View file

@ -12,6 +12,7 @@ private:
volatile unsigned long last_pressed_ms = 0;
volatile unsigned long pressed_at_ms = 0;
volatile unsigned long pressed_after_ms = 0;
volatile unsigned long pressed_count = 0;
bool activeWaiting = false;
unsigned long startWaitTime = 0;
@ -26,6 +27,8 @@ public:
AtmButton(uint8_t, uint8_t );
void begin();
void reset();
void softPress();
bool wasPressed();
void ledOn();
void ledOff();

View file

@ -2,6 +2,8 @@
#define COINACCEPTOR_H
#include "Arduino.h"
#include <cstring>
#include <string>
class CoinAcceptor {
private:
@ -9,26 +11,38 @@ private:
uint8_t accState = ACC_DISABLED;
volatile uint16_t coinPulses = 0;
volatile uint16_t allPulses = 0;
uint16_t coinValue = 0;
uint16_t sumValue = 0;
std::string sumValueStr = "";
volatile bool coinDetected = false;
volatile unsigned long currentMs = 0;
volatile unsigned long lastPulseAtMs = 0;
static void IRAM_ATTR pulseIsrHandler(void* arg);
void IRAM_ATTR pulseIsrHandler();
public:
const uint8_t ACC_DISABLED = LOW;
const uint8_t ACC_ENABLED = HIGH;
const unsigned int* pulseValues;
unsigned int* coinNumbers;
const size_t maxPulses = 0;
const uint8_t pulseWidthMs = 0;
const uint16_t maxAllowedCentToInsert = 0;
uint8_t detectionError = 0;
CoinAcceptor(uint8_t pulsePin, uint8_t enablePin, const unsigned int* pulseValues, const size_t maxPulses, const uint8_t pulseWidthMs );
CoinAcceptor(uint8_t pulsePin, uint8_t enablePin, const unsigned int* pulseValues, const size_t maxPulses, const uint8_t pulseWidthMs, const uint16_t maxAllowedCentToInsert);
~CoinAcceptor();
void begin();
void disable();
void enable();
uint8_t state();
bool detectCoin();
uint16_t getCoinValue();
uint16_t getSumValue();
void resetSumValue();
std::string getSumValueStr();
std::string getCoinsNumStr() const;
std::string getCoinsValStr() const;
};

View file

@ -38,7 +38,7 @@ class EpaperDisplay
void sleep();
void initScreen();
void homeScreen();
void showInsertedAmount(const char*);
void showInsertedAmount(const char* amount_in_euro, const char* coin_values, const char* coin_numbers, const char* max_ammount_in_euro, bool update);
void updateInsertedAmount(const char*);
void cleanScreen();

View file

@ -1,13 +1,4 @@
#ifndef MAIN_H
#define MAIN_H
typedef enum {
INIT,
WAIT_FOR_COIN,
PROCESS_COIN,
GENERATE_QR,
PAYMENT_CONFIRMED,
ERROR_STATE
} State;
#endif

36
firmware/include/state.h Normal file
View file

@ -0,0 +1,36 @@
#ifndef ATM_STATE_H
#define ATM_STATE_H
#include <Arduino.h>
#include <lnurl.h>
#include <cstring>
#include <string>
#include "button.h"
#include "coinacceptor.h"
#include "epaperdisplay.h"
extern EpaperDisplay epDisp;
extern AtmButton ok_button;
extern AtmButton cancel_button;
extern CoinAcceptor cacc;
namespace atm {
typedef enum {
INIT,
WAIT_FOR_COIN,
WAIT_FOR_BUTTON,
PROCESS_COIN,
GENERATE_QR,
CANCEL_PAYMENT,
PAYMENT_CONFIRMED,
ERROR_STATE
} State;
void stateMachine(void);
void reset(void);
}
#endif