Skip to content

Commit

Permalink
Improved vending machine boot window
Browse files Browse the repository at this point in the history
  • Loading branch information
Jnesselr committed Mar 4, 2023
1 parent 81e687b commit 5dcfd2e
Show file tree
Hide file tree
Showing 9 changed files with 91 additions and 101 deletions.
45 changes: 0 additions & 45 deletions snack-machine-firmware/src/denhac/DenhacBindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

#include "denhac/DenhacBindings.h"
#include "denhac/data/BridgeStatus.h"
#include "denhac/ui/DenhacUI.h"
#include "denhac/Session.h"
#include "denhac/ProductManager.h"

Expand All @@ -13,16 +12,10 @@
void DenhacBindings::setup() {
RFID::onCardScanned = DenhacBindings::onCardScanned;

Motors::onSystemStateChanged = DenhacBindings::onMotorSystemStateChanged;

BillValidator::onStateChanged = DenhacBindings::onBillValidatorStateCallback;
BillValidator::onBillRouted = DenhacBindings::onBillRoutedCallback;

CoinChanger::onStateChanged = DenhacBindings::onCoinChangerStateCallback;
CoinChanger::onCoinDeposited = DenhacBindings::onCoinDepositedCallback;

SiteLink::onStateChanged = DenhacBindings::onSiteLinkStateCallback;
SiteLink::statusCallback = DenhacBindings::onSiteLinkStatusCallback;
SiteLink::productUpdatedCallback = ProductManager::productUpdated;
SiteLink::productRemovedCallback = ProductManager::productRemoved;

Expand All @@ -33,22 +26,6 @@ void DenhacBindings::onCardScanned(unsigned long cardCode) {
Session::cardScanned((uint32_t) cardCode);
}

void DenhacBindings::onMotorSystemStateChanged(
MotorSystemState oldState,
MotorSystemState newState) {
if(newState == MotorSystemState::IDLE) {
DenhacUI::bootWindow.setMotorsIdle(true);
}
}

void DenhacBindings::onBillValidatorStateCallback(
BillValidatorState oldState,
BillValidatorState newState) {
if(newState == BillValidatorState::IDLE) {
DenhacUI::bootWindow.setBillValidatorIdle(true);
}
}

void DenhacBindings::onBillRoutedCallback(BillRouting routing, uint8_t billType) {
switch(routing) {
case BillRouting::ESCROW_POSITION:
Expand All @@ -61,14 +38,6 @@ void DenhacBindings::onBillRoutedCallback(BillRouting routing, uint8_t billType)
}
}

void DenhacBindings::onCoinChangerStateCallback(
CoinChangerState oldState,
CoinChangerState newState) {
if(newState == CoinChangerState::IDLE) {
DenhacUI::bootWindow.setCoinChangerIdle(true);
}
}

void DenhacBindings::onCoinDepositedCallback(
CoinRouting routing,
uint8_t coinType) {
Expand All @@ -79,18 +48,4 @@ void DenhacBindings::onCoinDepositedCallback(
Session::moneyInserted(CoinChanger::getValue(coinType));
}

void DenhacBindings::onSiteLinkStateCallback(
SiteLinkState oldState,
SiteLinkState newState) {
if(newState == SiteLinkState::IDLE) {
DenhacUI::bootWindow.setSiteLinkIdle(true);
}
}

void DenhacBindings::onSiteLinkStatusCallback(uint8_t statusCode) {
if(statusCode == BridgeStatus::WIFI_CONNECTED) {
DenhacUI::bootWindow.setWifiOnline(true);
}
}

#endif
9 changes: 0 additions & 9 deletions snack-machine-firmware/src/denhac/DenhacBindings.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,9 @@ class DenhacBindings {
// RFID
static void onCardScanned(unsigned long cardCode);

// Motors
static void onMotorSystemStateChanged(MotorSystemState oldState, MotorSystemState newState);

// Bill Validator
static void onBillValidatorStateCallback(BillValidatorState oldState, BillValidatorState newState);
static void onBillRoutedCallback(BillRouting, uint8_t billType);

// Coin Changer
static void onCoinChangerStateCallback(CoinChangerState oldState, CoinChangerState newState);
static void onCoinDepositedCallback(CoinRouting routing, uint8_t coinType);

// SiteLink
static void onSiteLinkStateCallback(SiteLinkState oldState, SiteLinkState newState);
static void onSiteLinkStatusCallback(uint8_t statusCode);
};
2 changes: 1 addition & 1 deletion snack-machine-firmware/src/denhac/DenhacBoard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@

#include "ui/WindowManager.hpp"
#include "ui/Screen.h"
#include "denhac/ui/DenhacUI.h"
#include "denhac/DenhacBindings.h"
#include "denhac/ui/BootWindow.h"

Task DenhacBoard::billValidatorLoop(200, []{
BillValidator::loop();
Expand Down
93 changes: 69 additions & 24 deletions snack-machine-firmware/src/denhac/ui/BootWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,19 @@ uint16_t BootWindow::siteLinkY;
uint16_t BootWindow::wifiY;
uint16_t BootWindow::motorsY;

uint8_t BootWindow::numStepsCompleted = 0;
uint8_t BootWindow::numStepsTotal = 64 + 5;

void BootWindow::setup() {
display = &Screen::display;

Motors::onSystemStateChanged = BootWindow::onMotorSystemStateChanged;
Motors::onMotorAvailability = BootWindow::onMotorAvailability;
BillValidator::onStateChanged = BootWindow::onBillValidatorStateCallback;
CoinChanger::onStateChanged = BootWindow::onCoinChangerStateCallback;
SiteLink::onStateChanged = BootWindow::onSiteLinkStateCallback;
SiteLink::statusCallback = BootWindow::onSiteLinkStatusCallback;

display->gfx_BGcolour(WHITESMOKE);
display->gfx_Cls();

Expand Down Expand Up @@ -89,7 +99,7 @@ void BootWindow::setup() {

void BootWindow::loop() {
// If it's a minute and we're not done with this, hard reset
uint32_t timeout = 15 * 1000;
uint32_t timeout = 60000;
if(current_loop_millis > timeout) {
while(true); // Force a reset with watchdog
}
Expand Down Expand Up @@ -152,6 +162,14 @@ void BootWindow::loop() {
}
}

// display->gfx_Rectangle(39, motorsY + 80, Screen::getWidth() - 39, motorsY + 85, LIGHTGREY);
display->gfx_Rectangle(38, motorsY + 79, Screen::getWidth() - 38, motorsY + 86, LIGHTGREY);

uint16_t totalWidth = Screen::getWidth() - 80;
uint16_t widthUsed = (numStepsCompleted * totalWidth) / numStepsTotal;

display->gfx_RectangleFilled(40, motorsY + 81, 40 + widthUsed, motorsY + 84, GREEN);

if(billValidatorIdle &&
coinChangerIdle &&
siteLinkIdle &&
Expand All @@ -162,44 +180,71 @@ void BootWindow::loop() {
}
}

void BootWindow::setBillValidatorIdle(bool isIdle) {
if(isIdle != billValidatorIdle) {
void BootWindow::onMotorSystemStateChanged(
MotorSystemState oldState,
MotorSystemState newState) {
if(newState != MotorSystemState::IDLE || redrawMotors) {
return;
}

motorsIdle = true;
redrawMotors = true;
lastChangeMillis = current_loop_millis;
numStepsCompleted++;
}

void BootWindow::onBillValidatorStateCallback(
BillValidatorState oldState,
BillValidatorState newState) {
if(newState != BillValidatorState::IDLE || redrawBillValidator) {
return;
}

redrawBillValidator = true;
lastChangeMillis = current_loop_millis;
}
billValidatorIdle = isIdle;
billValidatorIdle = true;
numStepsCompleted++;
}

void BootWindow::setCoinChangerIdle(bool isIdle) {
if(isIdle != coinChangerIdle) {
void BootWindow::onCoinChangerStateCallback(
CoinChangerState oldState,
CoinChangerState newState) {
if(newState == CoinChangerState::IDLE || coinChangerIdle) {
return;
}

redrawCoinChanger = true;
coinChangerIdle = true;
lastChangeMillis = current_loop_millis;
}
coinChangerIdle = isIdle;
numStepsCompleted++;
}

void BootWindow::setSiteLinkIdle(bool isIdle) {
if(isIdle != siteLinkIdle) {
void BootWindow::onSiteLinkStateCallback(
SiteLinkState oldState,
SiteLinkState newState) {
if(newState == SiteLinkState::IDLE || siteLinkIdle) {
return;
}

redrawSiteLink = true;
siteLinkIdle = true;
lastChangeMillis = current_loop_millis;
}
siteLinkIdle = isIdle;
numStepsCompleted++;
}

void BootWindow::setWifiOnline(bool online) {
if(online != wifiOnline) {
redrawWifi = true;
lastChangeMillis = current_loop_millis;
void BootWindow::onSiteLinkStatusCallback(uint8_t statusCode) {
if(statusCode != BridgeStatus::WIFI_CONNECTED || wifiOnline) {
return;
}
wifiOnline = online;

redrawWifi = true;
wifiOnline = true;
lastChangeMillis = current_loop_millis;
numStepsCompleted++;
}

void BootWindow::setMotorsIdle(bool isIdle) {
if(isIdle != motorsIdle) {
redrawMotors = true;
lastChangeMillis = current_loop_millis;
}
motorsIdle = isIdle;
void BootWindow::onMotorAvailability(uint8_t row, uint8_t col, bool available) {
numStepsCompleted++;
}

void BootWindow::drawXAt(uint16_t x, uint16_t y) {
Expand Down
20 changes: 15 additions & 5 deletions snack-machine-firmware/src/denhac/ui/BootWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
#include <Diablo_Serial_4DLib.h>

#include "stdint.h"
#include "motors.h"
#include "mdb/devices/BillValidator.h"
#include "mdb/devices/CoinChanger.h"
#include "denhac/SiteLink.h"
#include "denhac/data/BridgeStatus.h"

class BootWindow {
public:
Expand All @@ -11,11 +16,13 @@ class BootWindow {
static void teardown() {};
static void touch(uint8_t touchMode, uint16_t x, uint16_t y) {};

static void setBillValidatorIdle(bool);
static void setCoinChangerIdle(bool);
static void setSiteLinkIdle(bool);
static void setWifiOnline(bool);
static void setMotorsIdle(bool);

static void onCoinChangerStateCallback(CoinChangerState oldState, CoinChangerState newState);
static void onBillValidatorStateCallback(BillValidatorState oldState, BillValidatorState newState);
static void onMotorSystemStateChanged(MotorSystemState oldState, MotorSystemState newState);
static void onSiteLinkStateCallback(SiteLinkState oldState, SiteLinkState newState);
static void onSiteLinkStatusCallback(uint8_t statusCode);
static void onMotorAvailability(uint8_t row, uint8_t col, bool available);
private:
static void drawXAt(uint16_t x, uint16_t y);
static void drawCheckAt(uint16_t x, uint16_t y);
Expand All @@ -40,4 +47,7 @@ class BootWindow {
static uint16_t siteLinkY;
static uint16_t wifiY;
static uint16_t motorsY;

static uint8_t numStepsCompleted;
static uint8_t numStepsTotal;
};
8 changes: 0 additions & 8 deletions snack-machine-firmware/src/denhac/ui/DenhacUI.cpp

This file was deleted.

9 changes: 0 additions & 9 deletions snack-machine-firmware/src/denhac/ui/DenhacUI.h

This file was deleted.

4 changes: 4 additions & 0 deletions snack-machine-firmware/src/motors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ MotorState Motors::motorState = MotorState::NONE_SELECTED;
MotorSystemStateCallback Motors::onSystemStateChanged = nullptr;
MotorStateCallback Motors::onMotorStateChanged = nullptr;
ItemVendedCallback Motors::onItemVended = nullptr;
MotorAvailableCallback Motors::onMotorAvailability = nullptr;

unsigned long Motors::lastStateChangeTime = 0;
uint8_t Motors::motorsScanResult[8] = {0, 0, 0, 0, 0, 0, 0, 0};
Expand Down Expand Up @@ -112,16 +113,19 @@ void Motors::handleInitialScan() {
// Serial.print(") ");

int value = analogRead(MOTORS_SENSE);
bool motorAvailable = false;
if(value < 100) {
uint64_t mask = 1 << selectedCol;
motorsScanResult[selectedRow] |= mask;
motorAvailable = true;
// Serial.println("EXISTS");
} else {
// Serial.println("does NOT exist");
}
Serial.flush();

off();
CALLBACK(onMotorAvailability, selectedRow, selectedCol, motorAvailable);

selectedCol++;
if(selectedCol == 8) {
Expand Down
2 changes: 2 additions & 0 deletions snack-machine-firmware/src/motors.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ enum class MotorState {
typedef void (*MotorSystemStateCallback)(MotorSystemState oldState, MotorSystemState newState);
typedef void (*MotorStateCallback)(MotorState oldState, MotorState newState);
typedef void (*ItemVendedCallback)(uint8_t row, uint8_t col);
typedef void (*MotorAvailableCallback)(uint8_t row, uint8_t col, bool available);

class Motors {
public:
Expand All @@ -31,6 +32,7 @@ class Motors {
static MotorSystemStateCallback onSystemStateChanged;
static MotorStateCallback onMotorStateChanged;
static ItemVendedCallback onItemVended;
static MotorAvailableCallback onMotorAvailability;
private:
static bool valid(int row, int col);

Expand Down

0 comments on commit 5dcfd2e

Please sign in to comment.