I2C Autodetection (#1072)
* Added beginning of webconfig-side I2C bus scanning. Added experimental wrapper class for ADS1219 to handle device auto-detection. * Added scanner to webconfig. * Case sensitivity fix * All current I2C addons except Display updated to do auto device detection rather than rely on I2C block options. Added address range to ADS1219 addon to allow scanning across full range. * Fixed I2C/USB peripheral configuration check to reject negative pin values. * Added autodetection of I2C displays. This currently does not disable the usage of other devices on the same block. * Deprecating I2C addon block and address fields. * Remove deprecated Block and Address fields from Display and several Addons. * Added exclusive mode for I2C peripherals to allow data-hungry devices like Display to take full control of the bus. * Revert deprecatedi2cBlock to i2cBlock * Reinstated deprecatedI2cBlock * Reinstated usage of deprecatedI2cBlock
This commit is contained in:
@@ -264,8 +264,10 @@ headers/configs
|
||||
headers/drivers
|
||||
headers/interfaces
|
||||
headers/interfaces/i2c
|
||||
headers/interfaces/i2c/ads1219
|
||||
headers/interfaces/i2c/pcf8575
|
||||
headers/interfaces/i2c/ssd1306
|
||||
headers/interfaces/i2c/wiiextension
|
||||
headers/gamepad
|
||||
headers/display
|
||||
headers/display/fonts
|
||||
|
||||
@@ -209,6 +209,8 @@ private:
|
||||
DisplayMode currDisplayMode;
|
||||
DisplayMode prevDisplayMode;
|
||||
bool turnOffWhenSuspended;
|
||||
|
||||
GPGFX_DisplayTypeOptions gpOptions;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#ifndef _I2CAnalog_H
|
||||
#define _I2CAnalog_H
|
||||
|
||||
#include <ADS1219.h>
|
||||
#include "ads1219_dev.h"
|
||||
|
||||
#include "gpaddon.h"
|
||||
|
||||
@@ -47,7 +47,7 @@ public:
|
||||
virtual void process(); // Analog Process
|
||||
virtual std::string name() { return I2CAnalog1219Name; }
|
||||
private:
|
||||
ADS1219 * ads;
|
||||
ADS1219Device * ads;
|
||||
ADS_PINS pins;
|
||||
int channelHop;
|
||||
uint32_t uIntervalMS; // ADS1219 Interval
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
#include "gamepad.h"
|
||||
#include "storagemanager.h"
|
||||
#include "peripheralmanager.h"
|
||||
#include "WiiExtension.h"
|
||||
#include "wiiextension_dev.h"
|
||||
|
||||
// WiiExtension Module Name
|
||||
#define WiiExtensionName "WiiExtension"
|
||||
@@ -22,10 +22,6 @@
|
||||
#define WII_EXTENSION_ENABLED 0
|
||||
#endif
|
||||
|
||||
#ifndef WII_EXTENSION_I2C_ADDR
|
||||
#define WII_EXTENSION_I2C_ADDR 0x52
|
||||
#endif
|
||||
|
||||
#ifndef WII_EXTENSION_I2C_SDA_PIN
|
||||
#define WII_EXTENSION_I2C_SDA_PIN -1
|
||||
#endif
|
||||
@@ -90,7 +86,7 @@ public:
|
||||
virtual void preprocess() {}
|
||||
virtual std::string name() { return WiiExtensionName; }
|
||||
private:
|
||||
WiiExtension * wii;
|
||||
WiiExtensionDevice * wii;
|
||||
uint32_t uIntervalMS;
|
||||
uint32_t nextTimer;
|
||||
|
||||
|
||||
@@ -12,6 +12,8 @@ class GPGFX {
|
||||
|
||||
void init(GPGFX_DisplayTypeOptions options);
|
||||
|
||||
GPGFX_DisplayTypeOptions getAvailableDisplay();
|
||||
|
||||
GPGFX_DisplayBase* getDriver() { return displayDriver; }
|
||||
|
||||
// drawing methods
|
||||
|
||||
@@ -17,8 +17,9 @@ typedef enum {
|
||||
} GPGFX_DisplaySize;
|
||||
|
||||
typedef enum {
|
||||
TYPE_NONE,
|
||||
TYPE_SSD1306
|
||||
DISPLAY_TYPE_NONE,
|
||||
DISPLAY_TYPE_SSD1306,
|
||||
DISPLAY_TYPE_COUNT
|
||||
} GPGFX_DisplayType;
|
||||
|
||||
typedef struct {
|
||||
|
||||
20
headers/interfaces/i2c/ads1219/ads1219_dev.h
Normal file
20
headers/interfaces/i2c/ads1219/ads1219_dev.h
Normal file
@@ -0,0 +1,20 @@
|
||||
#ifndef _ADS1219DEVICE_H_
|
||||
#define _ADS1219DEVICE_H_
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "i2cdevicebase.h"
|
||||
#include "ADS1219.h"
|
||||
|
||||
class ADS1219Device : public ADS1219, public I2CDeviceBase {
|
||||
public:
|
||||
// Constructor
|
||||
ADS1219Device() {}
|
||||
ADS1219Device(PeripheralI2C *i2cController, uint8_t addr = 0x40) : ADS1219(i2cController, addr) {}
|
||||
|
||||
std::vector<uint8_t> getDeviceAddresses() const override {
|
||||
return {0x40,0x41,0x42,0x43,0x44,0x45,0x46,0x47,0x48,0x49,0x4A,0x4B,0x4C,0x4D,0x4E,0x4F};
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -5,9 +5,13 @@
|
||||
#include <string.h>
|
||||
#include "pico/stdlib.h"
|
||||
#include "GPGFX_types.h"
|
||||
#include "i2cdevicebase.h"
|
||||
|
||||
class GPGFX_DisplayBase {
|
||||
class GPGFX_DisplayBase : public I2CDeviceBase {
|
||||
public:
|
||||
GPGFX_DisplayBase() {}
|
||||
~GPGFX_DisplayBase() {}
|
||||
|
||||
virtual void init(GPGFX_DisplayTypeOptions options) {}
|
||||
|
||||
virtual void setPower(bool isPowered) {}
|
||||
@@ -34,7 +38,14 @@ class GPGFX_DisplayBase {
|
||||
|
||||
void setMetrics(GPGFX_DisplayMetrics* metrics) { this->_metrics = metrics; }
|
||||
GPGFX_DisplayMetrics* getMetrics() { return this->_metrics; }
|
||||
protected:
|
||||
|
||||
std::vector<uint8_t> getDeviceAddresses() const override {
|
||||
return {};
|
||||
}
|
||||
|
||||
virtual bool isSPI() { return false; }
|
||||
virtual bool isI2C() { return false; }
|
||||
private:
|
||||
GPGFX_DisplayMetrics* _metrics;
|
||||
};
|
||||
|
||||
|
||||
@@ -12,10 +12,6 @@ class I2CDeviceBase : public DeviceBase {
|
||||
~I2CDeviceBase() {}
|
||||
|
||||
virtual std::vector<uint8_t> getDeviceAddresses() const = 0;
|
||||
|
||||
int8_t scanForDevice();
|
||||
protected:
|
||||
PeripheralI2C* i2c;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -14,6 +14,7 @@
|
||||
class PCF8575 : public I2CDeviceBase {
|
||||
public:
|
||||
// Constructor
|
||||
PCF8575() {}
|
||||
PCF8575(PeripheralI2C *i2cController, uint8_t addr = 0x20) {
|
||||
this->i2c = i2cController;
|
||||
this->address = addr;
|
||||
@@ -28,6 +29,9 @@ class PCF8575 : public I2CDeviceBase {
|
||||
void reset();
|
||||
//void start();
|
||||
|
||||
void setI2C(PeripheralI2C *i2cController) { this->i2c = i2cController; }
|
||||
void setAddress(uint8_t addr) { this->address = addr; }
|
||||
|
||||
void send(uint16_t value);
|
||||
uint16_t receive();
|
||||
|
||||
@@ -35,14 +39,15 @@ class PCF8575 : public I2CDeviceBase {
|
||||
|
||||
void setPin(uint8_t pinNumber, uint8_t value);
|
||||
bool getPin(uint8_t pinNumber);
|
||||
protected:
|
||||
uint8_t address;
|
||||
private:
|
||||
const uint16_t initialValue = 0xFFFF;
|
||||
uint8_t uc[128];
|
||||
|
||||
uint16_t dataSent;
|
||||
uint16_t dataReceived = initialValue;
|
||||
protected:
|
||||
PeripheralI2C* i2c = nullptr;
|
||||
uint8_t address = 0;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -8,6 +8,9 @@
|
||||
|
||||
class GPGFX_OBD_SSD1306 : public GPGFX_DisplayBase {
|
||||
public:
|
||||
GPGFX_OBD_SSD1306() {}
|
||||
~GPGFX_OBD_SSD1306() {}
|
||||
|
||||
void init(GPGFX_DisplayTypeOptions options);
|
||||
|
||||
void setPower(bool isPowered);
|
||||
@@ -27,6 +30,13 @@ class GPGFX_OBD_SSD1306 : public GPGFX_DisplayBase {
|
||||
void drawSprite(uint8_t* spriteData, uint16_t width, uint16_t height, uint16_t pitch, uint16_t x, uint16_t y, uint8_t priority);
|
||||
|
||||
void drawBuffer(uint8_t *pBuffer);
|
||||
|
||||
std::vector<uint8_t> getDeviceAddresses() const override {
|
||||
return {0x3C, 0x3D};
|
||||
}
|
||||
|
||||
bool isSPI() { return this->_isSPI; }
|
||||
bool isI2C() { return this->_isI2C; }
|
||||
private:
|
||||
OBDISP obd;
|
||||
GPGFX_DisplayTypeOptions _options;
|
||||
@@ -36,6 +46,9 @@ class GPGFX_OBD_SSD1306 : public GPGFX_DisplayBase {
|
||||
void clearScreen(int render);
|
||||
|
||||
uint8_t ucBackBuffer[1024];
|
||||
|
||||
bool _isSPI = false;
|
||||
bool _isI2C = true;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -7,6 +7,9 @@
|
||||
|
||||
class GPGFX_TinySSD1306 : public GPGFX_DisplayBase {
|
||||
public:
|
||||
GPGFX_TinySSD1306() {}
|
||||
~GPGFX_TinySSD1306() {}
|
||||
|
||||
void init(GPGFX_DisplayTypeOptions options);
|
||||
|
||||
void setPower(bool isPowered);
|
||||
@@ -32,6 +35,13 @@ class GPGFX_TinySSD1306 : public GPGFX_DisplayBase {
|
||||
void drawBuffer(uint8_t *pBuffer);
|
||||
|
||||
bool isSH1106(int detectedDisplay);
|
||||
|
||||
std::vector<uint8_t> getDeviceAddresses() const override {
|
||||
return {0x3C, 0x3D};
|
||||
}
|
||||
|
||||
bool isSPI() { return this->_isSPI; }
|
||||
bool isI2C() { return this->_isI2C; }
|
||||
private:
|
||||
typedef enum {
|
||||
SET_LOW_COLUMN = 0x00,
|
||||
@@ -84,6 +94,8 @@ class GPGFX_TinySSD1306 : public GPGFX_DisplayBase {
|
||||
uint8_t framePage = 0;
|
||||
|
||||
uint8_t screenType;
|
||||
bool _isSPI = false;
|
||||
bool _isI2C = true;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
20
headers/interfaces/i2c/wiiextension/wiiextension_dev.h
Normal file
20
headers/interfaces/i2c/wiiextension/wiiextension_dev.h
Normal file
@@ -0,0 +1,20 @@
|
||||
#ifndef _WIIEXTDEVICE_H_
|
||||
#define _WIIEXTDEVICE_H_
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "i2cdevicebase.h"
|
||||
#include <WiiExtension.h>
|
||||
|
||||
class WiiExtensionDevice : public WiiExtension, public I2CDeviceBase {
|
||||
public:
|
||||
// Constructor
|
||||
WiiExtensionDevice() {}
|
||||
WiiExtensionDevice(PeripheralI2C *i2cController, uint8_t addr = WII_EXTENSION_I2C_ADDR) : WiiExtension(i2cController, addr) {}
|
||||
|
||||
std::vector<uint8_t> getDeviceAddresses() const override {
|
||||
return {WII_EXTENSION_I2C_ADDR};
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -4,9 +4,15 @@
|
||||
#include "peripheral_i2c.h"
|
||||
#include "peripheral_spi.h"
|
||||
#include "peripheral_usb.h"
|
||||
#include "i2cdevicebase.h"
|
||||
|
||||
#define PMGR PeripheralManager::getInstance()
|
||||
|
||||
typedef struct {
|
||||
int8_t address;
|
||||
uint8_t block;
|
||||
} PeripheralI2CScanResult;
|
||||
|
||||
class PeripheralManager {
|
||||
public:
|
||||
PeripheralManager(PeripheralManager const&) = delete;
|
||||
@@ -28,6 +34,8 @@ public:
|
||||
bool isI2CEnabled(uint8_t block);
|
||||
bool isSPIEnabled(uint8_t block);
|
||||
bool isUSBEnabled(uint8_t block);
|
||||
|
||||
PeripheralI2CScanResult scanForI2CDevice(std::vector<uint8_t> addressList);
|
||||
private:
|
||||
PeripheralManager(){}
|
||||
|
||||
|
||||
@@ -77,8 +77,10 @@ typedef enum{
|
||||
class ADS1219 {
|
||||
protected:
|
||||
uint8_t address;
|
||||
PeripheralI2C* i2c;
|
||||
public:
|
||||
// Constructor
|
||||
ADS1219() {}
|
||||
ADS1219(PeripheralI2C *i2cController, uint8_t addr = 0x40);
|
||||
|
||||
// Methods
|
||||
@@ -97,14 +99,17 @@ class ADS1219 {
|
||||
void setChannel(int channel);
|
||||
void powerDown();
|
||||
uint8_t readRegister(adsRegister_t reg);
|
||||
void start();
|
||||
void start();
|
||||
uint32_t readConversionResult();
|
||||
|
||||
void setI2C(PeripheralI2C *i2cController) { this->i2c = i2cController; }
|
||||
void setAddress(uint8_t addr) { this->address = addr; }
|
||||
|
||||
private:
|
||||
void writeRegister(uint8_t data);
|
||||
|
||||
PeripheralI2C* i2c;
|
||||
uint8_t config;
|
||||
bool singleShot;
|
||||
uint8_t config = 0x00;
|
||||
bool singleShot = true;
|
||||
int data_ready;
|
||||
unsigned char uc[128];
|
||||
};
|
||||
|
||||
@@ -10,8 +10,8 @@ PeripheralI2C::PeripheralI2C() {
|
||||
#endif
|
||||
}
|
||||
|
||||
void PeripheralI2C::setConfig(uint8_t block, uint8_t sda, uint8_t scl, uint32_t speed) {
|
||||
if (block < NUM_I2CS) {
|
||||
void PeripheralI2C::setConfig(uint8_t block, int8_t sda, int8_t scl, uint32_t speed) {
|
||||
if ((block < NUM_I2CS) && (sda > -1) && (scl > -1)) {
|
||||
_I2C = _hardwareBlocks[block];
|
||||
_SDA = sda;
|
||||
_SCL = scl;
|
||||
@@ -39,6 +39,8 @@ void PeripheralI2C::setup() {
|
||||
}
|
||||
|
||||
int16_t PeripheralI2C::read(uint8_t address, uint8_t *data, uint16_t len, bool isBlock) {
|
||||
if ((_exclusiveAddress > -1) && (_exclusiveAddress != address)) return -1;
|
||||
|
||||
int16_t result = i2c_read_blocking(_I2C, address, data, len, isBlock);
|
||||
#ifdef DEBUG_PERIPHERALI2C
|
||||
printf("PeripheralI2C::write %d:%d (blocking? %d)\n", address, len, isBlock);
|
||||
@@ -52,6 +54,8 @@ int16_t PeripheralI2C::read(uint8_t address, uint8_t *data, uint16_t len, bool i
|
||||
}
|
||||
|
||||
int16_t PeripheralI2C::readRegister(uint8_t address, uint8_t reg, uint8_t *data, uint16_t len) {
|
||||
if ((_exclusiveAddress > -1) && (_exclusiveAddress != address)) return -1;
|
||||
|
||||
int16_t registerCheck;
|
||||
registerCheck = i2c_write_blocking(_I2C, address, ®, 1, true);
|
||||
if (registerCheck >= 0) {
|
||||
@@ -61,6 +65,8 @@ int16_t PeripheralI2C::readRegister(uint8_t address, uint8_t reg, uint8_t *data,
|
||||
}
|
||||
|
||||
int16_t PeripheralI2C::write(uint8_t address, uint8_t *data, uint16_t len, bool isBlock) {
|
||||
if ((_exclusiveAddress > -1) && (_exclusiveAddress != address)) return -1;
|
||||
|
||||
#ifdef DEBUG_PERIPHERALI2C
|
||||
printf("PeripheralI2C::write %d:%d (blocking? %d)\n", address, len, isBlock);
|
||||
for (int i = 0; i < len; i++) {
|
||||
@@ -84,4 +90,24 @@ uint8_t PeripheralI2C::test(uint8_t address) {
|
||||
void PeripheralI2C::clear() {
|
||||
// reset the bus
|
||||
test(0xFF);
|
||||
}
|
||||
|
||||
std::map<uint8_t,bool> PeripheralI2C::scan() {
|
||||
std::map<uint8_t,bool> result;
|
||||
|
||||
for (uint8_t addr = 0; addr < (1 << 7); ++addr) {
|
||||
int8_t ret;
|
||||
uint8_t rxdata;
|
||||
ret = i2c_read_blocking(_I2C, addr, &rxdata, 1, false);
|
||||
|
||||
if (ret >= 0) {
|
||||
result.insert({addr,(ret >= 0)});
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef DEBUG_PERIPHERALI2C
|
||||
printf("%d\n", result.size());
|
||||
#endif
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
#ifndef _PERIPHERAL_I2C_H_
|
||||
#define _PERIPHERAL_I2C_H_
|
||||
|
||||
#include <map>
|
||||
#include <hardware/gpio.h>
|
||||
#include <hardware/i2c.h>
|
||||
#include <hardware/platform_defs.h>
|
||||
@@ -48,7 +49,7 @@ public:
|
||||
|
||||
i2c_inst_t* getController() { return _I2C; }
|
||||
|
||||
void setConfig(uint8_t block, uint8_t sda, uint8_t scl, uint32_t speed);
|
||||
void setConfig(uint8_t block, int8_t sda, int8_t scl, uint32_t speed);
|
||||
|
||||
int16_t read(uint8_t address, uint8_t *data, uint16_t len, bool isBlock=false);
|
||||
int16_t readRegister(uint8_t address, uint8_t reg, uint8_t *data, uint16_t len);
|
||||
@@ -57,6 +58,11 @@ public:
|
||||
|
||||
uint8_t test(uint8_t address);
|
||||
void clear();
|
||||
|
||||
std::map<uint8_t,bool> scan();
|
||||
|
||||
// if this is set to anything other than -1, any r/w operations against the address other than test()/scan() will not be processed
|
||||
void setExclusiveUse(int8_t address = -1) { _exclusiveAddress = address; }
|
||||
private:
|
||||
const uint32_t DEFAULT_SPEED = 400000;
|
||||
|
||||
@@ -67,6 +73,8 @@ private:
|
||||
|
||||
i2c_inst_t* _hardwareBlocks[NUM_I2CS] = {i2c0,i2c1};
|
||||
|
||||
int8_t _exclusiveAddress = -1;
|
||||
|
||||
void setup();
|
||||
};
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ void PeripheralUSB::setConfig(uint8_t block, int8_t dp, int8_t enable5v, uint8_t
|
||||
}
|
||||
|
||||
void PeripheralUSB::setup() {
|
||||
if (_DP != -1) {
|
||||
if (_DP > -1) {
|
||||
if (_Enable5v != -1) { // Feather USB-A's require this
|
||||
gpio_init(_Enable5v);
|
||||
gpio_set_dir(_Enable5v, GPIO_IN);
|
||||
|
||||
@@ -76,6 +76,10 @@ typedef enum {
|
||||
#define WII_EXTENSION_CALIBRATION true
|
||||
#endif
|
||||
|
||||
#ifndef WII_EXTENSION_I2C_ADDR
|
||||
#define WII_EXTENSION_I2C_ADDR 0x52
|
||||
#endif
|
||||
|
||||
#define WII_ALARM_NUM 0
|
||||
#define WII_ALARM_IRQ TIMER_IRQ_0
|
||||
|
||||
@@ -102,6 +106,7 @@ static volatile bool WiiExtension_alarmFired;
|
||||
class WiiExtension {
|
||||
protected:
|
||||
uint8_t address;
|
||||
PeripheralI2C* i2c;
|
||||
public:
|
||||
int8_t extensionType = WII_EXTENSION_NONE;
|
||||
int8_t dataType = WII_DATA_TYPE_0;
|
||||
@@ -109,6 +114,7 @@ class WiiExtension {
|
||||
bool isReady = false;
|
||||
|
||||
// Constructor
|
||||
WiiExtension() {}
|
||||
WiiExtension(PeripheralI2C *i2cController, uint8_t addr);
|
||||
|
||||
// Methods
|
||||
@@ -117,12 +123,13 @@ class WiiExtension {
|
||||
void start();
|
||||
void poll();
|
||||
|
||||
void setI2C(PeripheralI2C *i2cController) { this->i2c = i2cController; }
|
||||
void setAddress(uint8_t addr) { this->address = addr; }
|
||||
|
||||
ExtensionBase* getController() { return extensionController; };
|
||||
private:
|
||||
ExtensionBase *extensionController = NULL;
|
||||
|
||||
PeripheralI2C* i2c;
|
||||
|
||||
#if WII_EXTENSION_DEBUG==true
|
||||
uint8_t _lastRead[16] = {0xFF};
|
||||
#endif
|
||||
|
||||
@@ -205,11 +205,11 @@ message ProfileOptions
|
||||
message DisplayOptions
|
||||
{
|
||||
optional bool enabled = 1;
|
||||
|
||||
optional int32 i2cBlock = 2;
|
||||
|
||||
optional int32 deprecatedI2cBlock = 2 [deprecated = true];
|
||||
optional int32 deprecatedI2cSDAPin = 3 [deprecated = true];
|
||||
optional int32 deprecatedI2cSCLPin = 4 [deprecated = true];
|
||||
optional int32 i2cAddress = 5;
|
||||
optional int32 deprecatedI2cAddress = 5 [deprecated = true];
|
||||
optional int32 deprecatedI2cSpeed = 6 [deprecated = true];
|
||||
|
||||
optional ButtonLayout buttonLayout = 7;
|
||||
@@ -417,11 +417,11 @@ message ReverseOptions
|
||||
message AnalogADS1219Options
|
||||
{
|
||||
optional bool enabled = 1;
|
||||
|
||||
optional int32 i2cBlock = 2;
|
||||
|
||||
optional int32 deprecatedI2cBlock = 2 [deprecated = true];
|
||||
optional int32 deprecatedI2cSDAPin = 3 [deprecated = true];
|
||||
optional int32 deprecatedI2cSCLPin = 4 [deprecated = true];
|
||||
optional int32 i2cAddress = 5;
|
||||
optional int32 deprecatedI2cAddress = 5 [deprecated = true];
|
||||
optional int32 deprecatedI2cSpeed = 6 [deprecated = true];
|
||||
}
|
||||
|
||||
@@ -640,7 +640,7 @@ message WiiOptions
|
||||
}
|
||||
|
||||
optional bool enabled = 1;
|
||||
optional int32 i2cBlock = 2;
|
||||
optional int32 deprecatedI2cBlock = 2 [deprecated = true];
|
||||
optional int32 deprecatedI2cSDAPin = 3 [deprecated = true];
|
||||
optional int32 deprecatedI2cSCLPin = 4 [deprecated = true];
|
||||
optional int32 deprecatedI2cSpeed = 5 [deprecated = true];
|
||||
@@ -734,7 +734,7 @@ message RotaryOptions
|
||||
message PCF8575Options
|
||||
{
|
||||
optional bool enabled = 1;
|
||||
optional int32 i2cBlock = 2;
|
||||
optional int32 deprecatedI2cBlock = 2 [deprecated = true];
|
||||
repeated GpioMappingInfo pins = 3 [(nanopb).max_count = 16];
|
||||
}
|
||||
|
||||
|
||||
@@ -18,31 +18,33 @@
|
||||
|
||||
bool DisplayAddon::available() {
|
||||
const DisplayOptions& options = Storage::getInstance().getDisplayOptions();
|
||||
return options.enabled && PeripheralManager::getInstance().isI2CEnabled(options.i2cBlock);
|
||||
bool result = false;
|
||||
if (options.enabled) {
|
||||
// create the gfx interface
|
||||
gpDisplay = new GPGFX();
|
||||
gpOptions = gpDisplay->getAvailableDisplay();
|
||||
result = (gpOptions.displayType != GPGFX_DisplayType::DISPLAY_TYPE_NONE);
|
||||
if (!result) delete gpDisplay;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void DisplayAddon::setup() {
|
||||
const DisplayOptions& options = Storage::getInstance().getDisplayOptions();
|
||||
PeripheralI2C* i2c = PeripheralManager::getInstance().getI2C(options.i2cBlock);
|
||||
|
||||
// Setup GPGFX Options
|
||||
GPGFX_DisplayTypeOptions gpOptions;
|
||||
if (PeripheralManager::getInstance().isI2CEnabled(options.i2cBlock)) {
|
||||
gpOptions.displayType = GPGFX_DisplayType::TYPE_SSD1306;
|
||||
gpOptions.i2c = i2c;
|
||||
if (gpOptions.displayType != GPGFX_DisplayType::DISPLAY_TYPE_NONE) {
|
||||
gpOptions.size = options.size;
|
||||
gpOptions.address = options.i2cAddress;
|
||||
gpOptions.orientation = options.flip;
|
||||
gpOptions.inverted = options.invert;
|
||||
gpOptions.font.fontData = GP_Font_Standard;
|
||||
gpOptions.font.width = 6;
|
||||
gpOptions.font.height = 8;
|
||||
} else {
|
||||
return; // Do not run our display
|
||||
return;
|
||||
}
|
||||
|
||||
// Setup GPGFX
|
||||
gpDisplay = new GPGFX();
|
||||
gpDisplay->init(gpOptions);
|
||||
|
||||
gamepad = Storage::getInstance().GetGamepad();
|
||||
|
||||
@@ -6,17 +6,18 @@
|
||||
bool PCF8575Addon::available() {
|
||||
const DisplayOptions& displayOptions = Storage::getInstance().getDisplayOptions();
|
||||
const PCF8575Options& options = Storage::getInstance().getAddonOptions().pcf8575Options;
|
||||
if (options.enabled && PeripheralManager::getInstance().isI2CEnabled(options.i2cBlock)) {
|
||||
if (displayOptions.enabled && (displayOptions.i2cBlock == options.i2cBlock)) {
|
||||
return false;
|
||||
if (options.enabled) {
|
||||
pcf = new PCF8575();
|
||||
PeripheralI2CScanResult result = PeripheralManager::getInstance().scanForI2CDevice(pcf->getDeviceAddresses());
|
||||
if (result.address > -1) {
|
||||
pcf->setAddress(result.address);
|
||||
pcf->setI2C(PeripheralManager::getInstance().getI2C(result.block));
|
||||
return true;
|
||||
} else {
|
||||
PeripheralI2C* i2c = PeripheralManager::getInstance().getI2C(options.i2cBlock);
|
||||
pcf = new PCF8575(i2c);
|
||||
return (pcf->scanForDevice() > -1);
|
||||
delete pcf;
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void PCF8575Addon::setup() {
|
||||
|
||||
@@ -8,12 +8,22 @@
|
||||
|
||||
bool I2CAnalog1219Input::available() {
|
||||
const AnalogADS1219Options& options = Storage::getInstance().getAddonOptions().analogADS1219Options;
|
||||
return (options.enabled && PeripheralManager::getInstance().isI2CEnabled(options.i2cBlock));
|
||||
if (options.enabled) {
|
||||
ads = new ADS1219Device();
|
||||
PeripheralI2CScanResult result = PeripheralManager::getInstance().scanForI2CDevice(ads->getDeviceAddresses());
|
||||
if (result.address > -1) {
|
||||
ads->setAddress(result.address);
|
||||
ads->setI2C(PeripheralManager::getInstance().getI2C(result.block));
|
||||
return true;
|
||||
} else {
|
||||
delete ads;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void I2CAnalog1219Input::setup() {
|
||||
const AnalogADS1219Options& options = Storage::getInstance().getAddonOptions().analogADS1219Options;
|
||||
PeripheralI2C* i2c = PeripheralManager::getInstance().getI2C(options.i2cBlock);
|
||||
|
||||
memset(&pins, 0, sizeof(ADS_PINS));
|
||||
channelHop = 0;
|
||||
@@ -22,7 +32,6 @@ void I2CAnalog1219Input::setup() {
|
||||
nextTimer = getMillis();
|
||||
|
||||
// Init our ADS1219 library
|
||||
ads = new ADS1219(i2c, options.i2cAddress);
|
||||
ads->begin(); // setup I2C and chip start
|
||||
ads->setChannel(0); // Start on Channel 0
|
||||
ads->setConversionMode(CONTINUOUS); // Read analog continuously
|
||||
|
||||
@@ -6,19 +6,24 @@
|
||||
#include "config.pb.h"
|
||||
|
||||
bool WiiExtensionInput::available() {
|
||||
const DisplayOptions& displayOptions = Storage::getInstance().getDisplayOptions();
|
||||
const WiiOptions& options = Storage::getInstance().getAddonOptions().wiiOptions;
|
||||
bool result = (options.enabled && PeripheralManager::getInstance().isI2CEnabled(options.i2cBlock));
|
||||
if (result && (displayOptions.enabled && (displayOptions.i2cBlock == options.i2cBlock))) {
|
||||
// display check
|
||||
result = false;
|
||||
if (options.enabled) {
|
||||
// addon is enabled. let's scan available blocks.
|
||||
wii = new WiiExtensionDevice();
|
||||
PeripheralI2CScanResult result = PeripheralManager::getInstance().scanForI2CDevice(wii->getDeviceAddresses());
|
||||
if (result.address > -1) {
|
||||
wii->setAddress(result.address);
|
||||
wii->setI2C(PeripheralManager::getInstance().getI2C(result.block));
|
||||
return true;
|
||||
} else {
|
||||
delete wii;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
return false;
|
||||
}
|
||||
|
||||
void WiiExtensionInput::setup() {
|
||||
const WiiOptions& options = Storage::getInstance().getAddonOptions().wiiOptions;
|
||||
PeripheralI2C* i2c = PeripheralManager::getInstance().getI2C(options.i2cBlock);
|
||||
nextTimer = getMillis();
|
||||
|
||||
#if WII_EXTENSION_DEBUG==true
|
||||
@@ -29,9 +34,9 @@ void WiiExtensionInput::setup() {
|
||||
|
||||
currentConfig = NULL;
|
||||
|
||||
wii = new WiiExtension(
|
||||
i2c,
|
||||
WII_EXTENSION_I2C_ADDR);
|
||||
//wii = new WiiExtensionDevice(
|
||||
// i2c,
|
||||
// WII_EXTENSION_I2C_ADDR);
|
||||
wii->begin();
|
||||
wii->start();
|
||||
|
||||
|
||||
@@ -804,10 +804,10 @@ bool ConfigUtils::fromLegacyStorage(Config& config)
|
||||
DisplayOptions& displayOptions = config.displayOptions;
|
||||
config.has_displayOptions = true;
|
||||
SET_PROPERTY(displayOptions, enabled, legacyBoardOptions.hasI2CDisplay);
|
||||
SET_PROPERTY(displayOptions, i2cBlock, legacyBoardOptions.i2cBlock);
|
||||
SET_PROPERTY(displayOptions, deprecatedI2cBlock, legacyBoardOptions.i2cBlock);
|
||||
SET_PROPERTY(displayOptions, deprecatedI2cSDAPin, legacyBoardOptions.i2cSDAPin);
|
||||
SET_PROPERTY(displayOptions, deprecatedI2cSCLPin, legacyBoardOptions.i2cSCLPin);
|
||||
SET_PROPERTY(displayOptions, i2cAddress, legacyBoardOptions.displayI2CAddress);
|
||||
SET_PROPERTY(displayOptions, deprecatedI2cAddress, legacyBoardOptions.displayI2CAddress);
|
||||
SET_PROPERTY(displayOptions, deprecatedI2cSpeed, legacyBoardOptions.i2cSpeed);
|
||||
if (isValidButtonLayout(legacyBoardOptions.buttonLayout))
|
||||
{
|
||||
@@ -1003,10 +1003,10 @@ bool ConfigUtils::fromLegacyStorage(Config& config)
|
||||
AnalogADS1219Options& analogADS1219Options = config.addonOptions.analogADS1219Options;
|
||||
config.addonOptions.has_analogADS1219Options = true;
|
||||
SET_PROPERTY(analogADS1219Options, enabled, legacyAddonOptions.I2CAnalog1219InputEnabled);
|
||||
SET_PROPERTY(analogADS1219Options, i2cBlock, legacyAddonOptions.i2cAnalog1219Block);
|
||||
SET_PROPERTY(analogADS1219Options, deprecatedI2cBlock, legacyAddonOptions.i2cAnalog1219Block);
|
||||
SET_PROPERTY(analogADS1219Options, deprecatedI2cSDAPin, bytePinToIntPin(legacyAddonOptions.i2cAnalog1219SDAPin));
|
||||
SET_PROPERTY(analogADS1219Options, deprecatedI2cSCLPin, bytePinToIntPin(legacyAddonOptions.i2cAnalog1219SCLPin));
|
||||
SET_PROPERTY(analogADS1219Options, i2cAddress, legacyAddonOptions.i2cAnalog1219Address);
|
||||
SET_PROPERTY(analogADS1219Options, deprecatedI2cAddress, legacyAddonOptions.i2cAnalog1219Address);
|
||||
SET_PROPERTY(analogADS1219Options, deprecatedI2cSpeed, legacyAddonOptions.i2cAnalog1219Speed);
|
||||
|
||||
SliderOptions& sliderOptions = config.addonOptions.sliderOptions;
|
||||
@@ -1084,7 +1084,7 @@ bool ConfigUtils::fromLegacyStorage(Config& config)
|
||||
WiiOptions& wiiOptions = config.addonOptions.wiiOptions;
|
||||
config.addonOptions.has_wiiOptions = true;
|
||||
SET_PROPERTY(wiiOptions, enabled, legacyAddonOptions.WiiExtensionAddonEnabled);
|
||||
SET_PROPERTY(wiiOptions, i2cBlock, legacyAddonOptions.wiiExtensionBlock);
|
||||
SET_PROPERTY(wiiOptions, deprecatedI2cBlock, legacyAddonOptions.wiiExtensionBlock);
|
||||
SET_PROPERTY(wiiOptions, deprecatedI2cSDAPin, bytePinToIntPin(legacyAddonOptions.wiiExtensionSDAPin));
|
||||
SET_PROPERTY(wiiOptions, deprecatedI2cSCLPin, bytePinToIntPin(legacyAddonOptions.wiiExtensionSCLPin));
|
||||
SET_PROPERTY(wiiOptions, deprecatedI2cSpeed, legacyAddonOptions.wiiExtensionSpeed);
|
||||
|
||||
@@ -364,10 +364,10 @@ void ConfigUtils::initUnsetPropertiesWithDefaults(Config& config)
|
||||
|
||||
// displayOptions
|
||||
INIT_UNSET_PROPERTY(config.displayOptions, enabled, !!HAS_I2C_DISPLAY);
|
||||
INIT_UNSET_PROPERTY(config.displayOptions, i2cBlock, (DISPLAY_I2C_BLOCK == i2c0) ? 0 : 1);
|
||||
INIT_UNSET_PROPERTY(config.displayOptions, deprecatedI2cBlock, (DISPLAY_I2C_BLOCK == i2c0) ? 0 : 1);
|
||||
INIT_UNSET_PROPERTY(config.displayOptions, deprecatedI2cSDAPin, -1);
|
||||
INIT_UNSET_PROPERTY(config.displayOptions, deprecatedI2cSCLPin, -1);
|
||||
INIT_UNSET_PROPERTY(config.displayOptions, i2cAddress, DISPLAY_I2C_ADDR);
|
||||
INIT_UNSET_PROPERTY(config.displayOptions, deprecatedI2cAddress, DISPLAY_I2C_ADDR);
|
||||
INIT_UNSET_PROPERTY(config.displayOptions, deprecatedI2cSpeed, I2C_SPEED);
|
||||
INIT_UNSET_PROPERTY(config.displayOptions, buttonLayout, BUTTON_LAYOUT);
|
||||
INIT_UNSET_PROPERTY(config.displayOptions, buttonLayoutRight, BUTTON_LAYOUT_RIGHT);
|
||||
@@ -584,10 +584,10 @@ void ConfigUtils::initUnsetPropertiesWithDefaults(Config& config)
|
||||
|
||||
// addonOptions.analogADS1219Options
|
||||
INIT_UNSET_PROPERTY(config.addonOptions.analogADS1219Options, enabled, !!I2C_ANALOG1219_ENABLED);
|
||||
INIT_UNSET_PROPERTY(config.addonOptions.analogADS1219Options, i2cBlock, (I2C_ANALOG1219_BLOCK == i2c0) ? 0 : 1)
|
||||
INIT_UNSET_PROPERTY(config.addonOptions.analogADS1219Options, deprecatedI2cBlock, (I2C_ANALOG1219_BLOCK == i2c0) ? 0 : 1)
|
||||
INIT_UNSET_PROPERTY(config.addonOptions.analogADS1219Options, deprecatedI2cSDAPin, -1);
|
||||
INIT_UNSET_PROPERTY(config.addonOptions.analogADS1219Options, deprecatedI2cSCLPin, -1);
|
||||
INIT_UNSET_PROPERTY(config.addonOptions.analogADS1219Options, i2cAddress, I2C_ANALOG1219_ADDRESS);
|
||||
INIT_UNSET_PROPERTY(config.addonOptions.analogADS1219Options, deprecatedI2cAddress, I2C_ANALOG1219_ADDRESS);
|
||||
INIT_UNSET_PROPERTY(config.addonOptions.analogADS1219Options, deprecatedI2cSpeed, I2C_ANALOG1219_SPEED);
|
||||
|
||||
// addonOptions.analogADS1256Options
|
||||
@@ -660,7 +660,7 @@ void ConfigUtils::initUnsetPropertiesWithDefaults(Config& config)
|
||||
|
||||
// addonOptions.wiiOptions
|
||||
INIT_UNSET_PROPERTY(config.addonOptions.wiiOptions, enabled, WII_EXTENSION_ENABLED);
|
||||
INIT_UNSET_PROPERTY(config.addonOptions.wiiOptions, i2cBlock, (WII_EXTENSION_I2C_BLOCK == i2c0) ? 0 : 1);
|
||||
INIT_UNSET_PROPERTY(config.addonOptions.wiiOptions, deprecatedI2cBlock, (WII_EXTENSION_I2C_BLOCK == i2c0) ? 0 : 1);
|
||||
INIT_UNSET_PROPERTY(config.addonOptions.wiiOptions, deprecatedI2cSDAPin, -1);
|
||||
INIT_UNSET_PROPERTY(config.addonOptions.wiiOptions, deprecatedI2cSCLPin, -1);
|
||||
INIT_UNSET_PROPERTY(config.addonOptions.wiiOptions, deprecatedI2cSpeed, WII_EXTENSION_I2C_SPEED);
|
||||
@@ -673,7 +673,7 @@ void ConfigUtils::initUnsetPropertiesWithDefaults(Config& config)
|
||||
|
||||
// addonOptions.pcf8575Options
|
||||
INIT_UNSET_PROPERTY(config.addonOptions.pcf8575Options, enabled, I2C_PCF8575_ENABLED);
|
||||
INIT_UNSET_PROPERTY(config.addonOptions.pcf8575Options, i2cBlock, (I2C_PCF8575_BLOCK == i2c0) ? 0 : 1);
|
||||
INIT_UNSET_PROPERTY(config.addonOptions.pcf8575Options, deprecatedI2cBlock, (I2C_PCF8575_BLOCK == i2c0) ? 0 : 1);
|
||||
|
||||
GpioAction pcf8575Actions[PCF8575_PIN_COUNT] = {
|
||||
PCF8575_PIN00_ACTION,PCF8575_PIN01_ACTION,PCF8575_PIN02_ACTION,PCF8575_PIN03_ACTION,
|
||||
@@ -1022,28 +1022,28 @@ void gpioMappingsMigrationCore(Config& config)
|
||||
|
||||
// migrate I2C addons to use peripheral manager
|
||||
if (!peripheralOptions.blockI2C0.enabled && (
|
||||
(config.displayOptions.enabled && (config.displayOptions.i2cBlock == 0)) ||
|
||||
(config.addonOptions.analogADS1219Options.enabled && (config.addonOptions.analogADS1219Options.i2cBlock == 0)) ||
|
||||
(config.addonOptions.wiiOptions.enabled && (config.addonOptions.wiiOptions.i2cBlock == 0))
|
||||
(config.displayOptions.enabled && (config.displayOptions.deprecatedI2cBlock == 0)) ||
|
||||
(config.addonOptions.analogADS1219Options.enabled && (config.addonOptions.analogADS1219Options.deprecatedI2cBlock == 0)) ||
|
||||
(config.addonOptions.wiiOptions.enabled && (config.addonOptions.wiiOptions.deprecatedI2cBlock == 0))
|
||||
)
|
||||
) {
|
||||
peripheralOptions.blockI2C0.enabled = (
|
||||
(config.displayOptions.enabled && (config.displayOptions.i2cBlock == 0)) |
|
||||
(config.addonOptions.analogADS1219Options.enabled && (config.addonOptions.analogADS1219Options.i2cBlock == 0)) |
|
||||
(config.addonOptions.wiiOptions.enabled && (config.addonOptions.wiiOptions.i2cBlock == 0)) |
|
||||
(config.displayOptions.enabled && (config.displayOptions.deprecatedI2cBlock == 0)) |
|
||||
(config.addonOptions.analogADS1219Options.enabled && (config.addonOptions.analogADS1219Options.deprecatedI2cBlock == 0)) |
|
||||
(config.addonOptions.wiiOptions.enabled && (config.addonOptions.wiiOptions.deprecatedI2cBlock == 0)) |
|
||||
(!!I2C0_ENABLED)
|
||||
);
|
||||
|
||||
// pin configuration
|
||||
peripheralOptions.blockI2C0.sda = (
|
||||
isValidPin(config.displayOptions.deprecatedI2cSDAPin) && (config.displayOptions.i2cBlock == 0) ?
|
||||
config.displayOptions.deprecatedI2cSDAPin :
|
||||
isValidPin(config.displayOptions.deprecatedI2cSDAPin) && (config.displayOptions.deprecatedI2cBlock == 0) ?
|
||||
config.displayOptions.deprecatedI2cSDAPin :
|
||||
(
|
||||
isValidPin(config.addonOptions.analogADS1219Options.deprecatedI2cSDAPin) && (config.addonOptions.analogADS1219Options.i2cBlock == 0) ?
|
||||
config.addonOptions.analogADS1219Options.deprecatedI2cSDAPin :
|
||||
isValidPin(config.addonOptions.analogADS1219Options.deprecatedI2cSDAPin) && (config.addonOptions.analogADS1219Options.deprecatedI2cBlock == 0) ?
|
||||
config.addonOptions.analogADS1219Options.deprecatedI2cSDAPin :
|
||||
(
|
||||
isValidPin(config.addonOptions.wiiOptions.deprecatedI2cSDAPin) && (config.addonOptions.wiiOptions.i2cBlock == 0) ?
|
||||
config.addonOptions.wiiOptions.deprecatedI2cSDAPin :
|
||||
isValidPin(config.addonOptions.wiiOptions.deprecatedI2cSDAPin) && (config.addonOptions.wiiOptions.deprecatedI2cBlock == 0) ?
|
||||
config.addonOptions.wiiOptions.deprecatedI2cSDAPin :
|
||||
I2C0_PIN_SDA
|
||||
)
|
||||
)
|
||||
@@ -1051,14 +1051,14 @@ void gpioMappingsMigrationCore(Config& config)
|
||||
markAddonPinIfUsed(peripheralOptions.blockI2C0.sda);
|
||||
|
||||
peripheralOptions.blockI2C0.scl = (
|
||||
isValidPin(config.displayOptions.deprecatedI2cSCLPin) && (config.displayOptions.i2cBlock == 0) ?
|
||||
config.displayOptions.deprecatedI2cSCLPin :
|
||||
isValidPin(config.displayOptions.deprecatedI2cSCLPin) && (config.displayOptions.deprecatedI2cBlock == 0) ?
|
||||
config.displayOptions.deprecatedI2cSCLPin :
|
||||
(
|
||||
isValidPin(config.addonOptions.analogADS1219Options.deprecatedI2cSCLPin) && (config.addonOptions.analogADS1219Options.i2cBlock == 0) ?
|
||||
config.addonOptions.analogADS1219Options.deprecatedI2cSCLPin :
|
||||
isValidPin(config.addonOptions.analogADS1219Options.deprecatedI2cSCLPin) && (config.addonOptions.analogADS1219Options.deprecatedI2cBlock == 0) ?
|
||||
config.addonOptions.analogADS1219Options.deprecatedI2cSCLPin :
|
||||
(
|
||||
isValidPin(config.addonOptions.wiiOptions.deprecatedI2cSCLPin) && (config.addonOptions.wiiOptions.i2cBlock == 0) ?
|
||||
config.addonOptions.wiiOptions.deprecatedI2cSCLPin :
|
||||
isValidPin(config.addonOptions.wiiOptions.deprecatedI2cSCLPin) && (config.addonOptions.wiiOptions.deprecatedI2cBlock == 0) ?
|
||||
config.addonOptions.wiiOptions.deprecatedI2cSCLPin :
|
||||
I2C0_PIN_SCL
|
||||
)
|
||||
)
|
||||
@@ -1067,14 +1067,14 @@ void gpioMappingsMigrationCore(Config& config)
|
||||
|
||||
// option configuration
|
||||
peripheralOptions.blockI2C0.speed = (
|
||||
isValidPin(config.displayOptions.deprecatedI2cSpeed) && (config.displayOptions.i2cBlock == 0) ?
|
||||
config.displayOptions.deprecatedI2cSpeed :
|
||||
isValidPin(config.displayOptions.deprecatedI2cSpeed) && (config.displayOptions.deprecatedI2cBlock == 0) ?
|
||||
config.displayOptions.deprecatedI2cSpeed :
|
||||
(
|
||||
isValidPin(config.addonOptions.analogADS1219Options.deprecatedI2cSpeed) && (config.addonOptions.analogADS1219Options.i2cBlock == 0) ?
|
||||
config.addonOptions.analogADS1219Options.deprecatedI2cSpeed :
|
||||
isValidPin(config.addonOptions.analogADS1219Options.deprecatedI2cSpeed) && (config.addonOptions.analogADS1219Options.deprecatedI2cBlock == 0) ?
|
||||
config.addonOptions.analogADS1219Options.deprecatedI2cSpeed :
|
||||
(
|
||||
isValidPin(config.addonOptions.wiiOptions.deprecatedI2cSpeed) && (config.addonOptions.wiiOptions.i2cBlock == 0) ?
|
||||
config.addonOptions.wiiOptions.deprecatedI2cSpeed :
|
||||
isValidPin(config.addonOptions.wiiOptions.deprecatedI2cSpeed) && (config.addonOptions.wiiOptions.deprecatedI2cBlock == 0) ?
|
||||
config.addonOptions.wiiOptions.deprecatedI2cSpeed :
|
||||
I2C0_SPEED
|
||||
)
|
||||
)
|
||||
@@ -1082,28 +1082,28 @@ void gpioMappingsMigrationCore(Config& config)
|
||||
}
|
||||
|
||||
if (!peripheralOptions.blockI2C1.enabled && (
|
||||
(config.displayOptions.enabled && (config.displayOptions.i2cBlock == 1)) ||
|
||||
(config.addonOptions.analogADS1219Options.enabled && (config.addonOptions.analogADS1219Options.i2cBlock == 1)) ||
|
||||
(config.addonOptions.wiiOptions.enabled && (config.addonOptions.wiiOptions.i2cBlock == 1))
|
||||
(config.displayOptions.enabled && (config.displayOptions.deprecatedI2cBlock == 1)) ||
|
||||
(config.addonOptions.analogADS1219Options.enabled && (config.addonOptions.analogADS1219Options.deprecatedI2cBlock == 1)) ||
|
||||
(config.addonOptions.wiiOptions.enabled && (config.addonOptions.wiiOptions.deprecatedI2cBlock == 1))
|
||||
)
|
||||
) {
|
||||
peripheralOptions.blockI2C1.enabled = (
|
||||
(config.displayOptions.enabled && (config.displayOptions.i2cBlock == 1)) |
|
||||
(config.addonOptions.analogADS1219Options.enabled && (config.addonOptions.analogADS1219Options.i2cBlock == 1)) |
|
||||
(config.addonOptions.wiiOptions.enabled && (config.addonOptions.wiiOptions.i2cBlock == 1)) |
|
||||
(config.displayOptions.enabled && (config.displayOptions.deprecatedI2cBlock == 1)) |
|
||||
(config.addonOptions.analogADS1219Options.enabled && (config.addonOptions.analogADS1219Options.deprecatedI2cBlock == 1)) |
|
||||
(config.addonOptions.wiiOptions.enabled && (config.addonOptions.wiiOptions.deprecatedI2cBlock == 1)) |
|
||||
(!!I2C1_ENABLED)
|
||||
);
|
||||
|
||||
// pin configuration
|
||||
peripheralOptions.blockI2C1.sda = (
|
||||
isValidPin(config.displayOptions.deprecatedI2cSDAPin) && (config.displayOptions.i2cBlock == 1) ?
|
||||
config.displayOptions.deprecatedI2cSDAPin :
|
||||
isValidPin(config.displayOptions.deprecatedI2cSDAPin) && (config.displayOptions.deprecatedI2cBlock == 1) ?
|
||||
config.displayOptions.deprecatedI2cSDAPin :
|
||||
(
|
||||
isValidPin(config.addonOptions.analogADS1219Options.deprecatedI2cSDAPin) && (config.addonOptions.analogADS1219Options.i2cBlock == 1) ?
|
||||
config.addonOptions.analogADS1219Options.deprecatedI2cSDAPin :
|
||||
isValidPin(config.addonOptions.analogADS1219Options.deprecatedI2cSDAPin) && (config.addonOptions.analogADS1219Options.deprecatedI2cBlock == 1) ?
|
||||
config.addonOptions.analogADS1219Options.deprecatedI2cSDAPin :
|
||||
(
|
||||
isValidPin(config.addonOptions.wiiOptions.deprecatedI2cSDAPin) && (config.addonOptions.wiiOptions.i2cBlock == 1) ?
|
||||
config.addonOptions.wiiOptions.deprecatedI2cSDAPin :
|
||||
isValidPin(config.addonOptions.wiiOptions.deprecatedI2cSDAPin) && (config.addonOptions.wiiOptions.deprecatedI2cBlock == 1) ?
|
||||
config.addonOptions.wiiOptions.deprecatedI2cSDAPin :
|
||||
I2C1_PIN_SDA
|
||||
)
|
||||
)
|
||||
@@ -1111,14 +1111,14 @@ void gpioMappingsMigrationCore(Config& config)
|
||||
markAddonPinIfUsed(peripheralOptions.blockI2C1.sda);
|
||||
|
||||
peripheralOptions.blockI2C1.scl = (
|
||||
isValidPin(config.displayOptions.deprecatedI2cSCLPin) && (config.displayOptions.i2cBlock == 1) ?
|
||||
config.displayOptions.deprecatedI2cSCLPin :
|
||||
isValidPin(config.displayOptions.deprecatedI2cSCLPin) && (config.displayOptions.deprecatedI2cBlock == 1) ?
|
||||
config.displayOptions.deprecatedI2cSCLPin :
|
||||
(
|
||||
isValidPin(config.addonOptions.analogADS1219Options.deprecatedI2cSCLPin) && (config.addonOptions.analogADS1219Options.i2cBlock == 1) ?
|
||||
config.addonOptions.analogADS1219Options.deprecatedI2cSCLPin :
|
||||
isValidPin(config.addonOptions.analogADS1219Options.deprecatedI2cSCLPin) && (config.addonOptions.analogADS1219Options.deprecatedI2cBlock == 1) ?
|
||||
config.addonOptions.analogADS1219Options.deprecatedI2cSCLPin :
|
||||
(
|
||||
isValidPin(config.addonOptions.wiiOptions.deprecatedI2cSCLPin) && (config.addonOptions.wiiOptions.i2cBlock == 1) ?
|
||||
config.addonOptions.wiiOptions.deprecatedI2cSCLPin :
|
||||
isValidPin(config.addonOptions.wiiOptions.deprecatedI2cSCLPin) && (config.addonOptions.wiiOptions.deprecatedI2cBlock == 1) ?
|
||||
config.addonOptions.wiiOptions.deprecatedI2cSCLPin :
|
||||
I2C1_PIN_SCL
|
||||
)
|
||||
)
|
||||
@@ -1127,14 +1127,14 @@ void gpioMappingsMigrationCore(Config& config)
|
||||
|
||||
// option configuration
|
||||
peripheralOptions.blockI2C1.speed = (
|
||||
isValidPin(config.displayOptions.deprecatedI2cSpeed) && (config.displayOptions.i2cBlock == 1) ?
|
||||
config.displayOptions.deprecatedI2cSpeed :
|
||||
isValidPin(config.displayOptions.deprecatedI2cSpeed) && (config.displayOptions.deprecatedI2cBlock == 1) ?
|
||||
config.displayOptions.deprecatedI2cSpeed :
|
||||
(
|
||||
isValidPin(config.addonOptions.analogADS1219Options.deprecatedI2cSpeed) && (config.addonOptions.analogADS1219Options.i2cBlock == 1) ?
|
||||
config.addonOptions.analogADS1219Options.deprecatedI2cSpeed :
|
||||
isValidPin(config.addonOptions.analogADS1219Options.deprecatedI2cSpeed) && (config.addonOptions.analogADS1219Options.deprecatedI2cBlock == 1) ?
|
||||
config.addonOptions.analogADS1219Options.deprecatedI2cSpeed :
|
||||
(
|
||||
isValidPin(config.addonOptions.wiiOptions.deprecatedI2cSpeed) && (config.addonOptions.wiiOptions.i2cBlock == 1) ?
|
||||
config.addonOptions.wiiOptions.deprecatedI2cSpeed :
|
||||
isValidPin(config.addonOptions.wiiOptions.deprecatedI2cSpeed) && (config.addonOptions.wiiOptions.deprecatedI2cBlock == 1) ?
|
||||
config.addonOptions.wiiOptions.deprecatedI2cSpeed :
|
||||
I2C1_SPEED
|
||||
)
|
||||
)
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include "storagemanager.h"
|
||||
#include "configmanager.h"
|
||||
#include "layoutmanager.h"
|
||||
#include "peripheralmanager.h"
|
||||
#include "AnimationStorage.hpp"
|
||||
#include "system.h"
|
||||
#include "config_utils.h"
|
||||
@@ -436,8 +437,6 @@ std::string setDisplayOptions(DisplayOptions& displayOptions)
|
||||
{
|
||||
DynamicJsonDocument doc = get_post_data();
|
||||
readDoc(displayOptions.enabled, doc, "enabled");
|
||||
readDoc(displayOptions.i2cAddress, doc, "i2cAddress");
|
||||
readDoc(displayOptions.i2cBlock, doc, "i2cBlock");
|
||||
readDoc(displayOptions.flip, doc, "flipDisplay");
|
||||
readDoc(displayOptions.invert, doc, "invertDisplay");
|
||||
readDoc(displayOptions.buttonLayout, doc, "buttonLayout");
|
||||
@@ -480,8 +479,6 @@ std::string getDisplayOptions() // Manually set Document Attributes for the disp
|
||||
DynamicJsonDocument doc(LWIP_HTTPD_POST_MAX_PAYLOAD_LEN);
|
||||
const DisplayOptions& displayOptions = Storage::getInstance().getDisplayOptions();
|
||||
writeDoc(doc, "enabled", displayOptions.enabled ? 1 : 0);
|
||||
writeDoc(doc, "i2cAddress", displayOptions.i2cAddress);
|
||||
writeDoc(doc, "i2cBlock", displayOptions.i2cBlock);
|
||||
writeDoc(doc, "flipDisplay", displayOptions.flip);
|
||||
writeDoc(doc, "invertDisplay", displayOptions.invert ? 1 : 0);
|
||||
writeDoc(doc, "buttonLayout", displayOptions.buttonLayout);
|
||||
@@ -1196,6 +1193,29 @@ std::string getPeripheralOptions()
|
||||
return serialize_json(doc);
|
||||
}
|
||||
|
||||
std::string getI2CPeripheralMap() {
|
||||
DynamicJsonDocument doc(LWIP_HTTPD_POST_MAX_PAYLOAD_LEN);
|
||||
|
||||
PeripheralOptions& peripheralOptions = Storage::getInstance().getPeripheralOptions();
|
||||
|
||||
|
||||
if (peripheralOptions.blockI2C0.enabled && PeripheralManager::getInstance().isI2CEnabled(0)) {
|
||||
std::map<uint8_t,bool> result = PeripheralManager::getInstance().getI2C(0)->scan();
|
||||
for (std::map<uint8_t,bool>::iterator it = result.begin(); it != result.end(); ++it) {
|
||||
writeDoc(doc, "i2c0", std::to_string(it->first), it->second);
|
||||
}
|
||||
}
|
||||
|
||||
if (peripheralOptions.blockI2C1.enabled && PeripheralManager::getInstance().isI2CEnabled(1)) {
|
||||
std::map<uint8_t,bool> result = PeripheralManager::getInstance().getI2C(1)->scan();
|
||||
for (std::map<uint8_t,bool>::iterator it = result.begin(); it != result.end(); ++it) {
|
||||
writeDoc(doc, "i2c1", std::to_string(it->first), it->second);
|
||||
}
|
||||
}
|
||||
|
||||
return serialize_json(doc);
|
||||
}
|
||||
|
||||
std::string setPeripheralOptions()
|
||||
{
|
||||
DynamicJsonDocument doc = get_post_data();
|
||||
@@ -1390,8 +1410,6 @@ std::string setAddonOptions()
|
||||
docToValue(focusModeOptions.enabled, doc, "FocusModeAddonEnabled");
|
||||
|
||||
AnalogADS1219Options& analogADS1219Options = Storage::getInstance().getAddonOptions().analogADS1219Options;
|
||||
docToValue(analogADS1219Options.i2cBlock, doc, "i2cAnalog1219Block");
|
||||
docToValue(analogADS1219Options.i2cAddress, doc, "i2cAnalog1219Address");
|
||||
docToValue(analogADS1219Options.enabled, doc, "I2CAnalog1219InputEnabled");
|
||||
|
||||
SliderOptions& sliderOptions = Storage::getInstance().getAddonOptions().sliderOptions;
|
||||
@@ -1440,7 +1458,6 @@ std::string setAddonOptions()
|
||||
docToValue(turboOptions.enabled, doc, "TurboInputEnabled");
|
||||
|
||||
WiiOptions& wiiOptions = Storage::getInstance().getAddonOptions().wiiOptions;
|
||||
docToValue(wiiOptions.i2cBlock, doc, "wiiExtensionBlock");
|
||||
docToValue(wiiOptions.enabled, doc, "WiiExtensionAddonEnabled");
|
||||
|
||||
SNESOptions& snesOptions = Storage::getInstance().getAddonOptions().snesOptions;
|
||||
@@ -1496,7 +1513,6 @@ std::string setAddonOptions()
|
||||
docToValue(rotaryOptions.encoderTwo.multiplier, doc, "encoderTwoMultiplier");
|
||||
|
||||
PCF8575Options& pcf8575Options = Storage::getInstance().getAddonOptions().pcf8575Options;
|
||||
docToValue(pcf8575Options.i2cBlock, doc, "pcf8575Block");
|
||||
docToValue(pcf8575Options.enabled, doc, "PCF8575AddonEnabled");
|
||||
|
||||
DRV8833RumbleOptions& drv8833RumbleOptions = Storage::getInstance().getAddonOptions().drv8833RumbleOptions;
|
||||
@@ -1808,8 +1824,6 @@ std::string getAddonOptions()
|
||||
writeDoc(doc, "TiltInputEnabled", tiltOptions.enabled);
|
||||
|
||||
const AnalogADS1219Options& analogADS1219Options = Storage::getInstance().getAddonOptions().analogADS1219Options;
|
||||
writeDoc(doc, "i2cAnalog1219Block", analogADS1219Options.i2cBlock);
|
||||
writeDoc(doc, "i2cAnalog1219Address", analogADS1219Options.i2cAddress);
|
||||
writeDoc(doc, "I2CAnalog1219InputEnabled", analogADS1219Options.enabled);
|
||||
|
||||
const SliderOptions& sliderOptions = Storage::getInstance().getAddonOptions().sliderOptions;
|
||||
@@ -1858,7 +1872,6 @@ std::string getAddonOptions()
|
||||
writeDoc(doc, "TurboInputEnabled", turboOptions.enabled);
|
||||
|
||||
const WiiOptions& wiiOptions = Storage::getInstance().getAddonOptions().wiiOptions;
|
||||
writeDoc(doc, "wiiExtensionBlock", wiiOptions.i2cBlock);
|
||||
writeDoc(doc, "WiiExtensionAddonEnabled", wiiOptions.enabled);
|
||||
|
||||
const SNESOptions& snesOptions = Storage::getInstance().getAddonOptions().snesOptions;
|
||||
@@ -1929,7 +1942,6 @@ std::string getAddonOptions()
|
||||
writeDoc(doc, "encoderTwoMultiplier", rotaryOptions.encoderTwo.multiplier);
|
||||
|
||||
PCF8575Options& pcf8575Options = Storage::getInstance().getAddonOptions().pcf8575Options;
|
||||
writeDoc(doc, "pcf8575Block", pcf8575Options.i2cBlock);
|
||||
writeDoc(doc, "PCF8575AddonEnabled", pcf8575Options.enabled);
|
||||
|
||||
const DRV8833RumbleOptions& drv8833RumbleOptions = Storage::getInstance().getAddonOptions().drv8833RumbleOptions;
|
||||
@@ -2198,6 +2210,7 @@ static const std::pair<const char*, HandlerFuncPtr> handlerFuncs[] =
|
||||
{ "/api/setProfileOptions", setProfileOptions },
|
||||
{ "/api/setPeripheralOptions", setPeripheralOptions },
|
||||
{ "/api/getPeripheralOptions", getPeripheralOptions },
|
||||
{ "/api/getI2CPeripheralMap", getI2CPeripheralMap },
|
||||
{ "/api/setExpansionPins", setExpansionPins },
|
||||
{ "/api/getExpansionPins", getExpansionPins },
|
||||
{ "/api/setKeyMappings", setKeyMappings },
|
||||
|
||||
@@ -1,13 +1,15 @@
|
||||
#include "GPGFX.h"
|
||||
|
||||
#include <cstring>
|
||||
#include <vector>
|
||||
|
||||
#include "peripheralmanager.h"
|
||||
#include "obd_ssd1306.h"
|
||||
#include "tiny_ssd1306.h"
|
||||
|
||||
std::map<GPGFX_DisplayType, std::map<GPGFX_DisplaySize, GPGFX_DisplayMetrics>> GPGFX_DisplayModes = {
|
||||
{
|
||||
{TYPE_SSD1306},
|
||||
{DISPLAY_TYPE_SSD1306},
|
||||
{
|
||||
{SIZE_128x32,{128,32,1}},
|
||||
{SIZE_128x64,{128,64,1}},
|
||||
@@ -21,20 +23,52 @@ GPGFX::GPGFX() {
|
||||
|
||||
void GPGFX::init(GPGFX_DisplayTypeOptions options) {
|
||||
switch (options.displayType) {
|
||||
case GPGFX_DisplayType::TYPE_SSD1306:
|
||||
case GPGFX_DisplayType::DISPLAY_TYPE_SSD1306:
|
||||
//this->displayDriver = new GPGFX_OBD_SSD1306();
|
||||
this->displayDriver = new GPGFX_TinySSD1306();
|
||||
break;
|
||||
default:
|
||||
options.displayType = GPGFX_DisplayType::TYPE_NONE;
|
||||
options.displayType = GPGFX_DisplayType::DISPLAY_TYPE_NONE;
|
||||
}
|
||||
|
||||
if (options.displayType != GPGFX_DisplayType::TYPE_NONE) {
|
||||
if (options.displayType != GPGFX_DisplayType::DISPLAY_TYPE_NONE) {
|
||||
this->displayDriver->setMetrics(&GPGFX_DisplayModes[options.displayType][(GPGFX_DisplaySize)options.size]);
|
||||
this->displayDriver->init(options);
|
||||
}
|
||||
}
|
||||
|
||||
GPGFX_DisplayTypeOptions GPGFX::getAvailableDisplay() {
|
||||
GPGFX_DisplayBase* driver = nullptr;
|
||||
GPGFX_DisplayTypeOptions display;
|
||||
|
||||
display.displayType = GPGFX_DisplayType::DISPLAY_TYPE_NONE;
|
||||
|
||||
for (uint16_t i = GPGFX_DisplayType::DISPLAY_TYPE_NONE; i < GPGFX_DisplayType::DISPLAY_TYPE_COUNT; i++) {
|
||||
if (i == GPGFX_DisplayType::DISPLAY_TYPE_SSD1306) {
|
||||
driver = new GPGFX_TinySSD1306();
|
||||
} else {
|
||||
driver = nullptr;
|
||||
}
|
||||
if ((driver != nullptr) && (display.displayType == GPGFX_DisplayType::DISPLAY_TYPE_NONE)) {
|
||||
if (driver->isI2C()) {
|
||||
PeripheralI2CScanResult result = PeripheralManager::getInstance().scanForI2CDevice(driver->getDeviceAddresses());
|
||||
if (result.address > -1) {
|
||||
display.displayType = (GPGFX_DisplayType)i;
|
||||
display.address = result.address;
|
||||
display.i2c = PeripheralManager::getInstance().getI2C(result.block);
|
||||
display.i2c->setExclusiveUse(result.address);
|
||||
return display;
|
||||
}
|
||||
}
|
||||
if (driver->isSPI()) {
|
||||
// NYI: check if SPI display exists
|
||||
}
|
||||
delete driver;
|
||||
}
|
||||
}
|
||||
return display;
|
||||
}
|
||||
|
||||
void GPGFX::clearScreen() {
|
||||
this->displayDriver->clear();
|
||||
}
|
||||
|
||||
@@ -1,14 +1,2 @@
|
||||
#include <vector>
|
||||
#include "i2cdevicebase.h"
|
||||
|
||||
int8_t I2CDeviceBase::scanForDevice() {
|
||||
if (i2c != nullptr) {
|
||||
std::vector<uint8_t> addressList = getDeviceAddresses();
|
||||
for (uint8_t i = 0; i < addressList.size(); i++) {
|
||||
uint8_t result = i2c->test(addressList[i]);
|
||||
|
||||
if (result) return addressList[i];
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
@@ -59,3 +59,29 @@ bool PeripheralManager::isUSBEnabled(uint8_t block) {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
PeripheralI2CScanResult PeripheralManager::scanForI2CDevice(std::vector<uint8_t> addressList) {
|
||||
PeripheralI2CScanResult scanResult = {
|
||||
.address = -1,
|
||||
.block = 0
|
||||
};
|
||||
|
||||
for (uint8_t block = 0; block < NUM_I2CS; block++) {
|
||||
if (isI2CEnabled(block)) {
|
||||
PeripheralI2C* i2c = getI2C(block);
|
||||
|
||||
for (uint8_t i = 0; i < addressList.size(); i++) {
|
||||
if (!((addressList[i] & 0x78) == 0 || (addressList[i] & 0x78) == 0x78)) {
|
||||
uint8_t result = i2c->test(addressList[i]);
|
||||
|
||||
if (result) {
|
||||
scanResult.address = addressList[i];
|
||||
scanResult.block = block;
|
||||
return scanResult;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return scanResult;
|
||||
}
|
||||
@@ -45,8 +45,6 @@ app.get('/api/resetSettings', (req, res) => {
|
||||
app.get('/api/getDisplayOptions', (req, res) => {
|
||||
const data = {
|
||||
enabled: 1,
|
||||
i2cAddress: 61,
|
||||
i2cBlock: 0,
|
||||
flipDisplay: 0,
|
||||
invertDisplay: 1,
|
||||
buttonLayout: 0,
|
||||
@@ -396,8 +394,6 @@ app.get('/api/getAddonsOptions', (req, res) => {
|
||||
reverseActionDown: 1,
|
||||
reverseActionLeft: 1,
|
||||
reverseActionRight: 1,
|
||||
i2cAnalog1219Block: 0,
|
||||
i2cAnalog1219Address: 0x40,
|
||||
onBoardLedMode: 0,
|
||||
dualDirDpadMode: 0,
|
||||
dualDirCombineMode: 0,
|
||||
@@ -463,7 +459,6 @@ app.get('/api/getAddonsOptions', (req, res) => {
|
||||
shmupBtnMask4: 0,
|
||||
pinShmupDial: -1,
|
||||
sliderSOCDModeDefault: 1,
|
||||
wiiExtensionBlock: 0,
|
||||
snesPadClockPin: -1,
|
||||
snesPadLatchPin: -1,
|
||||
snesPadDataPin: -1,
|
||||
@@ -512,7 +507,6 @@ app.get('/api/getAddonsOptions', (req, res) => {
|
||||
encoderTwoAllowWrapAround: false,
|
||||
encoderTwoMultiplier: 1,
|
||||
RotaryAddonEnabled: 1,
|
||||
pcf8575Block: 0,
|
||||
PCF8575AddonEnabled: 1,
|
||||
DRV8833RumbleAddonEnabled: 1,
|
||||
usedPins: Object.values(picoController),
|
||||
|
||||
@@ -13,20 +13,10 @@ import { I2C_BLOCKS } from '../Data/Peripherals';
|
||||
|
||||
export const i2cAnalogScheme = {
|
||||
I2CAnalog1219InputEnabled: yup.number().label('I2C Analog1219 Input Enabled'),
|
||||
i2cAnalog1219Block: yup
|
||||
.number()
|
||||
.label('I2C Analog1219 Block')
|
||||
.validateSelectionWhenValue('I2CAnalog1219InputEnabled', I2C_BLOCKS),
|
||||
i2cAnalog1219Address: yup
|
||||
.number()
|
||||
.label('I2C Analog1219 Address')
|
||||
.validateNumberWhenValue('I2CAnalog1219InputEnabled'),
|
||||
};
|
||||
|
||||
export const i2cAnalogState = {
|
||||
I2CAnalog1219InputEnabled: 0,
|
||||
i2cAnalog1219Block: 0,
|
||||
i2cAnalog1219Address: 0x40,
|
||||
};
|
||||
|
||||
const I2CAnalog1219 = ({ values, errors, handleChange, handleCheckbox }) => {
|
||||
@@ -47,39 +37,6 @@ const I2CAnalog1219 = ({ values, errors, handleChange, handleCheckbox }) => {
|
||||
!(values.I2CAnalog1219InputEnabled && getAvailablePeripherals('i2c'))
|
||||
}
|
||||
>
|
||||
<Row className="mb-3">
|
||||
{getAvailablePeripherals('i2c') ? (
|
||||
<FormSelect
|
||||
label={t('AddonsConfig:i2c-analog-ads1219-block-label')}
|
||||
name="i2cAnalog1219Block"
|
||||
className="form-select-sm"
|
||||
groupClassName="col-sm-3 mb-3"
|
||||
value={values.i2cAnalog1219Block}
|
||||
error={errors.i2cAnalog1219Block}
|
||||
isInvalid={errors.i2cAnalog1219Block}
|
||||
onChange={handlePeripheralChange}
|
||||
>
|
||||
{getAvailablePeripherals('i2c').map((o, i) => (
|
||||
<option key={`i2cBlock-option-${i}`} value={o.value}>
|
||||
{o.label}
|
||||
</option>
|
||||
))}
|
||||
</FormSelect>
|
||||
) : (
|
||||
''
|
||||
)}
|
||||
<FormControl
|
||||
label={t('AddonsConfig:i2c-analog-ads1219-address-label')}
|
||||
name="i2cAnalog1219Address"
|
||||
className="form-control-sm"
|
||||
groupClassName="col-sm-3 mb-3"
|
||||
value={values.i2cAnalog1219Address}
|
||||
error={errors.i2cAnalog1219Address}
|
||||
isInvalid={errors.i2cAnalog1219Address}
|
||||
onChange={handleChange}
|
||||
maxLength={4}
|
||||
/>
|
||||
</Row>
|
||||
</div>
|
||||
{getAvailablePeripherals('i2c') ? (
|
||||
<FormCheck
|
||||
|
||||
@@ -51,16 +51,10 @@ export const pcf8575Scheme = {
|
||||
.number()
|
||||
.required()
|
||||
.label('PCF8575 IO Add-On Enabled'),
|
||||
pcf8575Block: yup
|
||||
.number()
|
||||
.required()
|
||||
.label('PCF8575 I2C Block')
|
||||
.validateSelectionWhenValue('PCF8575AddonEnabled', I2C_BLOCKS),
|
||||
};
|
||||
|
||||
export const pcf8575State = {
|
||||
PCF8575AddonEnabled: 0,
|
||||
pcf8575Block: 0,
|
||||
};
|
||||
|
||||
const getOption = (foo, actionId) => {
|
||||
@@ -265,28 +259,6 @@ const PCF8575 = ({ values, errors, handleChange, handleCheckbox }) => {
|
||||
id="PCF8575AddonOptions"
|
||||
hidden={!(values.PCF8575AddonEnabled && getAvailablePeripherals('i2c'))}
|
||||
>
|
||||
<Row className="mb-3">
|
||||
{getAvailablePeripherals('i2c') ? (
|
||||
<FormSelect
|
||||
label={t('PCF8575:block-label')}
|
||||
name="pcf8575Block"
|
||||
className="form-select-sm"
|
||||
groupClassName="col-sm-2 col-md-2 mb-3"
|
||||
value={values.pcf8575Block}
|
||||
error={errors.pcf8575Block}
|
||||
isInvalid={errors.pcf8575Block}
|
||||
onChange={handlePeripheralChange}
|
||||
>
|
||||
{getAvailablePeripherals('i2c').map((o, i) => (
|
||||
<option key={`pcf8575Block-option-${i}`} value={o.value}>
|
||||
{o.label}
|
||||
</option>
|
||||
))}
|
||||
</FormSelect>
|
||||
) : (
|
||||
''
|
||||
)}
|
||||
</Row>
|
||||
<Row className="mb-2">
|
||||
<ExpansionPinsForm
|
||||
pins={pins}
|
||||
|
||||
@@ -18,16 +18,10 @@ export const wiiScheme = {
|
||||
.number()
|
||||
.required()
|
||||
.label('Wii Extensions Enabled'),
|
||||
wiiExtensionBlock: yup
|
||||
.number()
|
||||
.required()
|
||||
.label('WiiExtension I2C Block')
|
||||
.validateSelectionWhenValue('WiiExtensionAddonEnabled', I2C_BLOCKS),
|
||||
};
|
||||
|
||||
export const wiiState = {
|
||||
WiiExtensionAddonEnabled: 0,
|
||||
wiiExtensionBlock: 0,
|
||||
};
|
||||
|
||||
const WII_EXTENSION_CONTROLS = [
|
||||
@@ -364,31 +358,6 @@ const Wii = ({
|
||||
</p>
|
||||
</Trans>
|
||||
</Row>
|
||||
<Row className="mb-3">
|
||||
{getAvailablePeripherals('i2c') ? (
|
||||
<FormSelect
|
||||
label={t('WiiAddon:block-label')}
|
||||
name="wiiExtensionBlock"
|
||||
className="form-select-sm"
|
||||
groupClassName="col-sm-2 col-md-2 mb-3"
|
||||
value={values.wiiExtensionBlock}
|
||||
error={errors.wiiExtensionBlock}
|
||||
isInvalid={errors.wiiExtensionBlock}
|
||||
onChange={handlePeripheralChange}
|
||||
>
|
||||
{getAvailablePeripherals('i2c').map((o, i) => (
|
||||
<option
|
||||
key={`wiiExtensionI2cBlock-option-${i}`}
|
||||
value={o.value}
|
||||
>
|
||||
{o.label}
|
||||
</option>
|
||||
))}
|
||||
</FormSelect>
|
||||
) : (
|
||||
''
|
||||
)}
|
||||
</Row>
|
||||
<Row className="mb-3">
|
||||
<Tabs
|
||||
defaultActiveKey={`wii${WII_EXTENSION_CONTROLS[0].id}Config`}
|
||||
|
||||
@@ -12,8 +12,6 @@ import FormSelect from '../Components/FormSelect';
|
||||
import Section from '../Components/Section';
|
||||
import WebApi from '../Services/WebApi';
|
||||
|
||||
import { I2C_BLOCKS } from '../Data/Peripherals';
|
||||
|
||||
const ON_OFF_OPTIONS = [
|
||||
{ label: 'Disabled', value: 0 },
|
||||
{ label: 'Enabled', value: 1 },
|
||||
@@ -35,8 +33,6 @@ const DISPLAY_FLIP_MODES = [
|
||||
|
||||
const defaultValues = {
|
||||
enabled: false,
|
||||
i2cAddress: '0x3C',
|
||||
i2cBlock: 0,
|
||||
flipDisplay: false,
|
||||
invertDisplay: false,
|
||||
buttonLayout: 0,
|
||||
@@ -75,12 +71,6 @@ let buttonLayoutRightSchema = buttonLayoutSchemaBase.label(
|
||||
|
||||
const schema = yup.object().shape({
|
||||
enabled: yup.number().label('Enabled?'),
|
||||
i2cAddress: yup.string().required().label('I2C Address'),
|
||||
i2cBlock: yup
|
||||
.number()
|
||||
.required()
|
||||
.oneOf(I2C_BLOCKS.map((o) => o.value))
|
||||
.label('I2C Block'),
|
||||
flipDisplay: yup
|
||||
.number()
|
||||
.oneOf(DISPLAY_FLIP_MODES.map((o) => o.value))
|
||||
@@ -157,7 +147,6 @@ const FormContext = () => {
|
||||
useEffect(() => {
|
||||
async function setDisplayOptions() {
|
||||
if (!!values.enabled) values.enabled = parseInt(values.enabled);
|
||||
if (!!values.i2cBlock) values.i2cBlock = parseInt(values.i2cBlock);
|
||||
if (!!values.flipDisplay)
|
||||
values.flipDisplay = parseInt(values.flipDisplay);
|
||||
if (!!values.invertDisplay)
|
||||
@@ -183,7 +172,6 @@ const FormContext = () => {
|
||||
useEffect(() => {
|
||||
async function setSplashImage() {
|
||||
if (!!values.enabled) values.enabled = parseInt(values.enabled);
|
||||
if (!!values.i2cBlock) values.i2cBlock = parseInt(values.i2cBlock);
|
||||
if (!!values.flipDisplay)
|
||||
values.flipDisplay = parseInt(values.flipDisplay);
|
||||
if (!!values.invertDisplay)
|
||||
@@ -300,34 +288,6 @@ export default function DisplayConfigPage() {
|
||||
</option>
|
||||
))}
|
||||
</FormSelect>
|
||||
<FormSelect
|
||||
label={t('DisplayConfig:form.i2c-block-label')}
|
||||
name="i2cBlock"
|
||||
className="form-select-sm"
|
||||
groupClassName="col-sm-3 mb-3"
|
||||
value={values.i2cBlock}
|
||||
error={errors.i2cBlock}
|
||||
isInvalid={errors.i2cBlock}
|
||||
onChange={handlePeripheralChange}
|
||||
>
|
||||
{getAvailablePeripherals('i2c').map((o, i) => (
|
||||
<option key={`i2cBlock-option-${i}`} value={o.value}>
|
||||
{o.label}
|
||||
</option>
|
||||
))}
|
||||
</FormSelect>
|
||||
<FormControl
|
||||
type="text"
|
||||
label={t('DisplayConfig:form.i2c-address-label')}
|
||||
name="i2cAddress"
|
||||
className="form-control-sm"
|
||||
groupClassName="col-sm-3 mb-3"
|
||||
value={values.i2cAddress}
|
||||
error={errors.i2cAddress}
|
||||
isInvalid={errors.i2cAddress}
|
||||
onChange={handleChange}
|
||||
maxLength={4}
|
||||
/>
|
||||
</Row>
|
||||
<h1>{t('DisplayConfig:section.screen-header')}</h1>
|
||||
<Row className="mb-4">
|
||||
|
||||
@@ -205,9 +205,6 @@ async function getDisplayOptions() {
|
||||
try {
|
||||
const response = await Http.get(`${baseUrl}/api/getDisplayOptions`);
|
||||
|
||||
if (response.data.i2cAddress) {
|
||||
response.data.i2cAddress = '0x' + response.data.i2cAddress.toString(16);
|
||||
}
|
||||
response.data.splashDuration = response.data.splashDuration / 1000; // milliseconds to seconds
|
||||
response.data.displaySaverTimeout =
|
||||
response.data.displaySaverTimeout / 60000; // milliseconds to minutes
|
||||
@@ -220,7 +217,6 @@ async function getDisplayOptions() {
|
||||
|
||||
async function setDisplayOptions(options, isPreview) {
|
||||
let newOptions = sanitizeRequest(options);
|
||||
newOptions.i2cAddress = parseInt(options.i2cAddress);
|
||||
newOptions.buttonLayout = parseInt(options.buttonLayout);
|
||||
newOptions.buttonLayoutRight = parseInt(options.buttonLayoutRight);
|
||||
newOptions.splashMode = parseInt(options.splashMode);
|
||||
|
||||
Reference in New Issue
Block a user