Changed from MCP23S17 to MCP23017. Lots of changes.
Doesn't really work because of timing stuff.
This commit is contained in:
@ -5,17 +5,19 @@
|
||||
#include "player.h"
|
||||
#include "mqtt_client.h"
|
||||
#include <MFRC522.h>
|
||||
#include <MCP23S17/MCP23S17.h>
|
||||
#include <Adafruit_MCP23017.h>
|
||||
|
||||
class Controller {
|
||||
private:
|
||||
MFRC522* _rfid;
|
||||
MCP* _mcp;
|
||||
Adafruit_MCP23017* _mcp;
|
||||
SPIMaster* _spi;
|
||||
MQTTClient* _mqtt_client;
|
||||
bool _rfid_enabled = true;
|
||||
void _check_rfid();
|
||||
void _check_serial();
|
||||
void _check_buttons();
|
||||
bool _debounce_button(uint8_t index);
|
||||
uint32_t _get_rfid_card_uid();
|
||||
uint32_t _last_rfid_card_uid = 0;
|
||||
uint8_t _no_rfid_card_count = 0;
|
||||
@ -30,7 +32,7 @@ private:
|
||||
unsigned long _last_mqtt_report_at = 0;
|
||||
void _send_mqtt_report();
|
||||
public:
|
||||
Controller(Player* p, MCP* m);
|
||||
Controller(Player* p, Adafruit_MCP23017* m, SPIMaster* s);
|
||||
void set_mqtt_client(MQTTClient* m);
|
||||
String get_status_json();
|
||||
void loop();
|
||||
|
@ -1,6 +1,5 @@
|
||||
#pragma once
|
||||
#include <ESP8266WebServer.h>
|
||||
#include "spi_master.h"
|
||||
#include "player.h"
|
||||
#include "controller.h"
|
||||
#include <SD.h>
|
||||
|
@ -4,7 +4,8 @@
|
||||
#include <SD.h>
|
||||
#include <list>
|
||||
#include <map>
|
||||
#include <MCP23S17/MCP23S17.h>
|
||||
#include <Adafruit_MCP23017.h>
|
||||
#include "spi_master.h"
|
||||
|
||||
#define SCI_MODE 0x00
|
||||
#define SCI_STATUS 0x01
|
||||
@ -23,11 +24,6 @@
|
||||
#define SM_CANCEL 0x0008
|
||||
#define SS_DO_NOT_JUMP 0x8000
|
||||
|
||||
#define XRESET PIN_VS1053_XRESET
|
||||
#define DREQ PIN_VS1053_DREQ
|
||||
#define XCS PIN_VS1053_XCS
|
||||
#define XDCS PIN_VS1053_XDCS
|
||||
|
||||
class Player {
|
||||
private:
|
||||
enum state { uninitialized, idle, playing, stopping,
|
||||
@ -81,10 +77,11 @@ private:
|
||||
uint8_t _volume;
|
||||
uint16_t _stop_delay;
|
||||
uint32_t _skip_to;
|
||||
MCP* _mcp;
|
||||
Adafruit_MCP23017* _mcp;
|
||||
SPIMaster* _spi;
|
||||
unsigned long _stopped_at;
|
||||
public:
|
||||
Player(MCP* m);
|
||||
Player(Adafruit_MCP23017* m, SPIMaster* s);
|
||||
void vol_up();
|
||||
void vol_down();
|
||||
void track_next();
|
||||
|
@ -5,31 +5,42 @@
|
||||
#include "config.h"
|
||||
|
||||
class SPIMaster {
|
||||
private:
|
||||
Adafruit_MCP23017* _mcp;
|
||||
public:
|
||||
static void init() {
|
||||
SPI.setHwCs(false);
|
||||
pinMode(PIN_SD_CS, OUTPUT);
|
||||
pinMode(PIN_VS1053_XCS, OUTPUT);
|
||||
pinMode(PIN_VS1053_XDCS, OUTPUT);
|
||||
pinMode(PIN_MCP, OUTPUT);
|
||||
}
|
||||
static void enable(uint8_t pin) {
|
||||
digitalWrite(PIN_SD_CS, pin==PIN_SD_CS ? LOW : HIGH);
|
||||
digitalWrite(PIN_VS1053_XCS, pin==PIN_VS1053_XCS ? LOW : HIGH);
|
||||
digitalWrite(PIN_VS1053_XDCS, pin==PIN_VS1053_XDCS ? LOW : HIGH);
|
||||
digitalWrite(PIN_MCP, pin==PIN_MCP ? LOW : HIGH);
|
||||
|
||||
SPIMaster(Adafruit_MCP23017* m) {
|
||||
_mcp = m;
|
||||
PIN_SD_CS_SETUP();
|
||||
PIN_VS1053_XCS_SETUP();
|
||||
PIN_VS1053_XDCS_SETUP();
|
||||
PIN_RC522_CS_SETUP();
|
||||
disable();
|
||||
}
|
||||
|
||||
static void printStatus() {
|
||||
Serial.printf("CS state: SD:%d, VS1053_XCS:%d, VS1053_XDCS:%d, MCP:%d\n",
|
||||
digitalRead(PIN_SD_CS),
|
||||
digitalRead(PIN_VS1053_XCS),
|
||||
digitalRead(PIN_VS1053_XDCS),
|
||||
digitalRead(PIN_MCP));
|
||||
void select_sd(bool enabled=true) {
|
||||
PIN_SD_CS(enabled ? LOW : HIGH);
|
||||
delayMicroseconds(MCP_SPI_SETTING_DELAY);
|
||||
}
|
||||
|
||||
static void disable() {
|
||||
enable(142);
|
||||
void select_vs1053_xcs(bool enabled=true) {
|
||||
PIN_VS1053_XCS(enabled ? LOW : HIGH);
|
||||
delayMicroseconds(MCP_SPI_SETTING_DELAY);
|
||||
}
|
||||
|
||||
void select_vs1053_xdcs(bool enabled=true) {
|
||||
PIN_VS1053_XDCS(enabled ? LOW : HIGH);
|
||||
delayMicroseconds(MCP_SPI_SETTING_DELAY);
|
||||
}
|
||||
|
||||
void select_rc522(bool enabled=true) {
|
||||
PIN_RC522_CS(enabled ? LOW : HIGH);
|
||||
delayMicroseconds(MCP_SPI_SETTING_DELAY);
|
||||
}
|
||||
|
||||
void disable() {
|
||||
PIN_SD_CS(HIGH);
|
||||
PIN_VS1053_XCS(HIGH);
|
||||
PIN_VS1053_XDCS(HIGH);
|
||||
PIN_RC522_CS(HIGH);
|
||||
}
|
||||
};
|
||||
|
8
include/tools.h
Normal file
8
include/tools.h
Normal file
@ -0,0 +1,8 @@
|
||||
#include <Adafruit_MCP23017.h>
|
||||
#include "config.h"
|
||||
|
||||
void print_mcp_status(Adafruit_MCP23017* mcp) {
|
||||
DEBUG(" AAAAAAAA BBBBBBBB\n");
|
||||
DEBUG(" 76543210 76543210\n");
|
||||
DEBUG("State of MCP pins: %08s %08s\n", String(mcp->readGPIO(0), 2).c_str(), String(mcp->readGPIO(1), 2).c_str());
|
||||
}
|
Reference in New Issue
Block a user