mirror of
https://github.com/arendst/Tasmota.git
synced 2025-07-24 11:16:34 +00:00
Change pin handling part 4/4
This commit is contained in:
parent
c939077514
commit
86f801c349
@ -1582,7 +1582,7 @@ chknext:
|
||||
if (!strncmp(vname,"pd[",3)) {
|
||||
GetNumericResult(vname+3,OPER_EQU,&fvar,0);
|
||||
uint8_t gpiopin=fvar;
|
||||
for (uint8_t i=0;i<GPIO_SENSOR_END;i++) {
|
||||
for (uint8_t i=0;i<GPIO_SENSOR_END;i++) { // Theo/Gemu: This needs to change when pin[] becomes real pin array
|
||||
// if (pin[i]==gpiopin) {
|
||||
if (Pin(i)==gpiopin) {
|
||||
fvar=i;
|
||||
|
@ -249,8 +249,6 @@ void HlwDrvInit(void)
|
||||
{
|
||||
Hlw.model_type = 0; // HLW8012
|
||||
if (PinUsed(GPIO_HJL_CF)) {
|
||||
// pin[GPIO_HLW_CF] = pin[GPIO_HJL_CF];
|
||||
// pin[GPIO_HJL_CF] = 99;
|
||||
SetPin(Pin(GPIO_HJL_CF), GPIO_HLW_CF);
|
||||
SetPin(99, GPIO_HJL_CF);
|
||||
Hlw.model_type = 1; // HJL-01/BL0937
|
||||
@ -260,8 +258,6 @@ void HlwDrvInit(void)
|
||||
|
||||
Hlw.ui_flag = true; // Voltage on high
|
||||
if (PinUsed(GPIO_NRG_SEL_INV)) {
|
||||
// pin[GPIO_NRG_SEL] = pin[GPIO_NRG_SEL_INV];
|
||||
// pin[GPIO_NRG_SEL_INV] = 99;
|
||||
SetPin(Pin(GPIO_NRG_SEL_INV), GPIO_NRG_SEL);
|
||||
SetPin(99, GPIO_NRG_SEL_INV);
|
||||
Hlw.ui_flag = false; // Voltage on low
|
||||
|
@ -282,9 +282,9 @@ long HxWeight(void)
|
||||
void HxInit(void)
|
||||
{
|
||||
Hx.type = 0;
|
||||
if ((pin[GPIO_HX711_DAT] < 99) && (pin[GPIO_HX711_SCK] < 99)) {
|
||||
Hx.pin_sck = pin[GPIO_HX711_SCK];
|
||||
Hx.pin_dout = pin[GPIO_HX711_DAT];
|
||||
if (PinUsed(GPIO_HX711_DAT) && PinUsed(GPIO_HX711_SCK)) {
|
||||
Hx.pin_sck = Pin(GPIO_HX711_SCK);
|
||||
Hx.pin_dout = Pin(GPIO_HX711_DAT);
|
||||
|
||||
pinMode(Hx.pin_sck, OUTPUT);
|
||||
pinMode(Hx.pin_dout, INPUT);
|
||||
|
@ -206,7 +206,7 @@ void TX2xStartRead(void)
|
||||
delayMicroseconds(TX2X_BIT_TIME / 2);
|
||||
|
||||
for (int32_t bitcount = 41; bitcount > 0; bitcount--) {
|
||||
uint32_t dpin = (digitalRead(pin[GPIO_TX2X_TXD_BLACK]));
|
||||
uint32_t dpin = (digitalRead(Pin(GPIO_TX2X_TXD_BLACK)));
|
||||
#ifdef USE_TX23_WIND_SENSOR
|
||||
dpin ^= 1;
|
||||
#endif // USE_TX23_WIND_SENSOR
|
||||
@ -263,7 +263,7 @@ void TX2xStartRead(void)
|
||||
|
||||
// Must clear this bit in the interrupt register,
|
||||
// it gets set even when interrupts are disabled
|
||||
GPIO_REG_WRITE(GPIO_STATUS_W1TC_ADDRESS, 1 << pin[GPIO_TX2X_TXD_BLACK]);
|
||||
GPIO_REG_WRITE(GPIO_STATUS_W1TC_ADDRESS, 1 << Pin(GPIO_TX2X_TXD_BLACK));
|
||||
}
|
||||
|
||||
bool Tx2xAvailable(void)
|
||||
@ -338,13 +338,13 @@ void Tx2xRead(void)
|
||||
// TX23 start transmission by pulling down TxD line for at minimum 500ms
|
||||
// so we pull TxD signal to low every 3 seconds
|
||||
tx23_stage = 0;
|
||||
pinMode(pin[GPIO_TX2X_TXD_BLACK], OUTPUT);
|
||||
digitalWrite(pin[GPIO_TX2X_TXD_BLACK], LOW);
|
||||
pinMode(Pin(GPIO_TX2X_TXD_BLACK), OUTPUT);
|
||||
digitalWrite(Pin(GPIO_TX2X_TXD_BLACK), LOW);
|
||||
} else if ((uptime % TX23_READ_INTERVAL)==1) {
|
||||
// after pulling down TxD: pull-up TxD every x+1 seconds
|
||||
// to trigger TX23 start transmission
|
||||
tx23_stage = 1; // first rising signal is invalid
|
||||
pinMode(pin[GPIO_TX2X_TXD_BLACK], INPUT_PULLUP);
|
||||
pinMode(Pin(GPIO_TX2X_TXD_BLACK), INPUT_PULLUP);
|
||||
}
|
||||
#endif // USE_TX23_WIND_SENSOR
|
||||
if (Tx2xAvailable()) {
|
||||
@ -465,12 +465,12 @@ void Tx2xInit(void)
|
||||
#endif // USE_TX2X_WIND_SENSOR_NOSTATISTICS
|
||||
#ifdef USE_TX23_WIND_SENSOR
|
||||
tx23_stage = 0;
|
||||
pinMode(pin[GPIO_TX2X_TXD_BLACK], OUTPUT);
|
||||
digitalWrite(pin[GPIO_TX2X_TXD_BLACK], LOW);
|
||||
pinMode(Pin(GPIO_TX2X_TXD_BLACK), OUTPUT);
|
||||
digitalWrite(Pin(GPIO_TX2X_TXD_BLACK), LOW);
|
||||
#else // USE_TX23_WIND_SENSOR
|
||||
pinMode(pin[GPIO_TX2X_TXD_BLACK], INPUT);
|
||||
pinMode(Pin(GPIO_TX2X_TXD_BLACK), INPUT);
|
||||
#endif // USE_TX23_WIND_SENSOR
|
||||
attachInterrupt(pin[GPIO_TX2X_TXD_BLACK], TX2xStartRead, RISING);
|
||||
attachInterrupt(Pin(GPIO_TX2X_TXD_BLACK), TX2xStartRead, RISING);
|
||||
}
|
||||
|
||||
int32_t Tx2xNormalize(int32_t value)
|
||||
@ -582,7 +582,7 @@ bool Xsns35(uint8_t function)
|
||||
{
|
||||
bool result = false;
|
||||
|
||||
if (pin[GPIO_TX2X_TXD_BLACK] < 99) {
|
||||
if (PinUsed(GPIO_TX2X_TXD_BLACK)) {
|
||||
switch (function) {
|
||||
case FUNC_INIT:
|
||||
Tx2xInit();
|
||||
|
@ -39,14 +39,11 @@
|
||||
|
||||
#define MGC3130_I2C_ADDR 0x42
|
||||
|
||||
#define MGC3130_xfer pin[GPIO_MGC3130_XFER]
|
||||
#define MGC3130_reset pin[GPIO_MGC3130_RESET]
|
||||
|
||||
|
||||
uint8_t MGC3130_xfer = 0;
|
||||
uint8_t MGC3130_reset = 0;
|
||||
bool MGC3130_type = false;
|
||||
char MGC3130stype[] = "MGC3130";
|
||||
|
||||
|
||||
#define MGC3130_SYSTEM_STATUS 0x15
|
||||
#define MGC3130_REQUEST_MSG 0x06
|
||||
#define MGC3130_FW_VERSION 0x83
|
||||
@ -478,6 +475,9 @@ void MGC3130_detect(void)
|
||||
{
|
||||
if (MGC3130_type || I2cActive(MGC3130_I2C_ADDR)) { return; }
|
||||
|
||||
MGC3130_xfer = Pin(GPIO_MGC3130_XFER);
|
||||
MGC3130_reset = Pin(GPIO_MGC3130_RESET);
|
||||
|
||||
pinMode(MGC3130_xfer, INPUT_PULLUP);
|
||||
pinMode(MGC3130_reset, OUTPUT);
|
||||
digitalWrite(MGC3130_reset, LOW);
|
||||
@ -588,7 +588,7 @@ bool Xsns36(uint8_t function)
|
||||
|
||||
bool result = false;
|
||||
|
||||
if ((FUNC_INIT == function) && (pin[GPIO_MGC3130_XFER] < 99) && (pin[GPIO_MGC3130_RESET] < 99)) {
|
||||
if ((FUNC_INIT == function) && PinUsed(GPIO_MGC3130_XFER) && PinUsed(GPIO_MGC3130_RESET)) {
|
||||
MGC3130_detect();
|
||||
}
|
||||
else if (MGC3130_type) {
|
||||
|
@ -607,9 +607,9 @@ void RfSnsInit(void)
|
||||
RfSnsInitAlectoV2();
|
||||
#endif
|
||||
if (rfsns_any_sensor) {
|
||||
rfsns_rf_bit = digitalPinToBitMask(pin[GPIO_RF_SENSOR]);
|
||||
rfsns_rf_port = digitalPinToPort(pin[GPIO_RF_SENSOR]);
|
||||
pinMode(pin[GPIO_RF_SENSOR], INPUT);
|
||||
rfsns_rf_bit = digitalPinToBitMask(Pin(GPIO_RF_SENSOR));
|
||||
rfsns_rf_port = digitalPinToPort(Pin(GPIO_RF_SENSOR));
|
||||
pinMode(Pin(GPIO_RF_SENSOR), INPUT);
|
||||
} else {
|
||||
free(rfsns_raw_signal);
|
||||
rfsns_raw_signal = nullptr;
|
||||
@ -654,14 +654,14 @@ bool Xsns37(uint8_t function)
|
||||
{
|
||||
bool result = false;
|
||||
|
||||
if ((pin[GPIO_RF_SENSOR] < 99) && (FUNC_INIT == function)) {
|
||||
if (PinUsed(GPIO_RF_SENSOR) && (FUNC_INIT == function)) {
|
||||
RfSnsInit();
|
||||
}
|
||||
else if (rfsns_raw_signal) {
|
||||
switch (function) {
|
||||
case FUNC_LOOP:
|
||||
if ((*portInputRegister(rfsns_rf_port) &rfsns_rf_bit) == rfsns_rf_bit) {
|
||||
if (RfSnsFetchSignal(pin[GPIO_RF_SENSOR], HIGH)) {
|
||||
if (RfSnsFetchSignal(Pin(GPIO_RF_SENSOR), HIGH)) {
|
||||
RfSnsAnalyzeRawSignal();
|
||||
}
|
||||
}
|
||||
|
@ -267,8 +267,8 @@ void AzEverySecond(void)
|
||||
void AzInit(void)
|
||||
{
|
||||
az_type = 0;
|
||||
if ((pin[GPIO_AZ_RXD] < 99) && (pin[GPIO_AZ_TXD] < 99)) {
|
||||
AzSerial = new TasmotaSerial(pin[GPIO_AZ_RXD], pin[GPIO_AZ_TXD], 1);
|
||||
if (PinUsed(GPIO_AZ_RXD) && PinUsed(GPIO_AZ_TXD)) {
|
||||
AzSerial = new TasmotaSerial(Pin(GPIO_AZ_RXD), Pin(GPIO_AZ_TXD), 1);
|
||||
if (AzSerial->begin(9600)) {
|
||||
if (AzSerial->hardwareSerial()) { ClaimSerial(); }
|
||||
az_type = 1;
|
||||
|
@ -34,13 +34,13 @@ void MAX31855_Init(void){
|
||||
return;
|
||||
|
||||
// Set GPIO modes for SW-SPI
|
||||
pinMode(pin[GPIO_MAX31855CS], OUTPUT);
|
||||
pinMode(pin[GPIO_MAX31855CLK], OUTPUT);
|
||||
pinMode(pin[GPIO_MAX31855DO], INPUT);
|
||||
pinMode(Pin(GPIO_MAX31855CS), OUTPUT);
|
||||
pinMode(Pin(GPIO_MAX31855CLK), OUTPUT);
|
||||
pinMode(Pin(GPIO_MAX31855DO), INPUT);
|
||||
|
||||
// Chip not selected / Clock low
|
||||
digitalWrite(pin[GPIO_MAX31855CS], HIGH);
|
||||
digitalWrite(pin[GPIO_MAX31855CLK], LOW);
|
||||
digitalWrite(Pin(GPIO_MAX31855CS), HIGH);
|
||||
digitalWrite(Pin(GPIO_MAX31855CLK), LOW);
|
||||
|
||||
initialized = true;
|
||||
}
|
||||
@ -99,22 +99,22 @@ float MAX31855_GetReferenceTemperature(int32_t RawData){
|
||||
int32_t MAX31855_ShiftIn(uint8_t Length){
|
||||
int32_t dataIn = 0;
|
||||
|
||||
digitalWrite(pin[GPIO_MAX31855CS], LOW); // CS = LOW -> Start SPI communication
|
||||
digitalWrite(Pin(GPIO_MAX31855CS), LOW); // CS = LOW -> Start SPI communication
|
||||
delayMicroseconds(1); // CS fall to output enable = max. 100ns
|
||||
|
||||
for (uint32_t i = 0; i < Length; i++)
|
||||
{
|
||||
digitalWrite(pin[GPIO_MAX31855CLK], LOW);
|
||||
digitalWrite(Pin(GPIO_MAX31855CLK), LOW);
|
||||
delayMicroseconds(1); // CLK pulse width low = min. 100ns / CLK fall to output valid = max. 40ns
|
||||
dataIn <<= 1;
|
||||
if(digitalRead(pin[GPIO_MAX31855DO]))
|
||||
if(digitalRead(Pin(GPIO_MAX31855DO)))
|
||||
dataIn |= 1;
|
||||
digitalWrite(pin[GPIO_MAX31855CLK], HIGH);
|
||||
digitalWrite(Pin(GPIO_MAX31855CLK), HIGH);
|
||||
delayMicroseconds(1); // CLK pulse width high = min. 100ns
|
||||
}
|
||||
|
||||
digitalWrite(pin[GPIO_MAX31855CS], HIGH); // CS = HIGH -> End SPI communication
|
||||
digitalWrite(pin[GPIO_MAX31855CLK], LOW);
|
||||
digitalWrite(Pin(GPIO_MAX31855CS), HIGH); // CS = HIGH -> End SPI communication
|
||||
digitalWrite(Pin(GPIO_MAX31855CLK), LOW);
|
||||
return dataIn;
|
||||
}
|
||||
|
||||
@ -151,7 +151,7 @@ void MAX31855_Show(bool Json){
|
||||
bool Xsns39(uint8_t function)
|
||||
{
|
||||
bool result = false;
|
||||
if((pin[GPIO_MAX31855CS] < 99) && (pin[GPIO_MAX31855CLK] < 99) && (pin[GPIO_MAX31855DO] < 99)){
|
||||
if(PinUsed(GPIO_MAX31855CS) && PinUsed(GPIO_MAX31855CLK) && PinUsed(GPIO_MAX31855DO)){
|
||||
|
||||
switch (function) {
|
||||
case FUNC_INIT:
|
||||
|
@ -66,8 +66,8 @@ uint8_t pn532_newdata_len = 0;
|
||||
|
||||
void PN532_Init(void)
|
||||
{
|
||||
if ((pin[GPIO_PN532_RXD] < 99) && (pin[GPIO_PN532_TXD] < 99)) {
|
||||
PN532_Serial = new TasmotaSerial(pin[GPIO_PN532_RXD], pin[GPIO_PN532_TXD], 1);
|
||||
if (PinUsed(GPIO_PN532_RXD9) && PinUsed(GPIO_PN532_TXD)) {
|
||||
PN532_Serial = new TasmotaSerial(Pin(GPIO_PN532_RXD), Pin(GPIO_PN532_TXD), 1);
|
||||
if (PN532_Serial->begin(115200)) {
|
||||
if (PN532_Serial->hardwareSerial()) { ClaimSerial(); }
|
||||
PN532_wakeup();
|
||||
|
@ -71,10 +71,10 @@ bool hre_good = false;
|
||||
// The settling times here were determined using a single unit hooked to a scope
|
||||
int hreReadBit()
|
||||
{
|
||||
digitalWrite(pin[GPIO_HRE_CLOCK], HIGH);
|
||||
digitalWrite(Pin(GPIO_HRE_CLOCK), HIGH);
|
||||
delay(1);
|
||||
int bit = digitalRead(pin[GPIO_HRE_DATA]);
|
||||
digitalWrite(pin[GPIO_HRE_CLOCK], LOW);
|
||||
int bit = digitalRead(Pin(GPIO_HRE_DATA));
|
||||
digitalWrite(Pin(GPIO_HRE_CLOCK), LOW);
|
||||
delay(1);
|
||||
return bit;
|
||||
}
|
||||
@ -110,12 +110,12 @@ void hreInit(void)
|
||||
hre_read_errors = 0;
|
||||
hre_good = false;
|
||||
|
||||
pinMode(pin[GPIO_HRE_CLOCK], OUTPUT);
|
||||
pinMode(pin[GPIO_HRE_DATA], INPUT);
|
||||
pinMode(Pin(GPIO_HRE_CLOCK), OUTPUT);
|
||||
pinMode(Pin(GPIO_HRE_DATA), INPUT);
|
||||
|
||||
// Note that the level shifter inverts this line and we want to leave it
|
||||
// high when not being read.
|
||||
digitalWrite(pin[GPIO_HRE_CLOCK], LOW);
|
||||
digitalWrite(Pin(GPIO_HRE_CLOCK), LOW);
|
||||
|
||||
hre_state = hre_sync;
|
||||
}
|
||||
@ -260,8 +260,7 @@ void hreShow(boolean json)
|
||||
bool Xsns43(byte function)
|
||||
{
|
||||
// If we don't have pins assigned give up quickly.
|
||||
if (pin[GPIO_HRE_CLOCK] >= 99 || pin[GPIO_HRE_DATA] >= 99)
|
||||
return false;
|
||||
if (!PinUsed(GPIO_HRE_CLOCK) || !PinUsed(GPIO_HRE_DATA)) { return false; }
|
||||
|
||||
switch (function)
|
||||
{
|
||||
|
@ -51,10 +51,10 @@ void MAX31865_Init(void){
|
||||
return;
|
||||
|
||||
max31865.setPins(
|
||||
pin[GPIO_SSPI_CS],
|
||||
pin[GPIO_SSPI_MOSI],
|
||||
pin[GPIO_SSPI_MISO],
|
||||
pin[GPIO_SSPI_SCLK]
|
||||
Pin(GPIO_SSPI_CS),
|
||||
Pin(GPIO_SSPI_MOSI),
|
||||
Pin(GPIO_SSPI_MISO),
|
||||
Pin(GPIO_SSPI_SCLK)
|
||||
);
|
||||
|
||||
if(max31865.begin(PTD_WIRES))
|
||||
@ -110,8 +110,8 @@ void MAX31865_Show(bool Json){
|
||||
bool Xsns47(uint8_t function)
|
||||
{
|
||||
bool result = false;
|
||||
if((pin[GPIO_SSPI_MISO] < 99) && (pin[GPIO_SSPI_MOSI] < 99) &&
|
||||
(pin[GPIO_SSPI_SCLK] < 99) && (pin[GPIO_SSPI_CS] < 99)) {
|
||||
if (PinUsed(GPIO_SSPI_MISO) && PinUsed(GPIO_SSPI_MOSI) &&
|
||||
PinUsed(GPIO_SSPI_SCLK) && PinUsed(GPIO_SSPI_CS)) {
|
||||
|
||||
switch (function) {
|
||||
case FUNC_INIT:
|
||||
|
@ -36,8 +36,8 @@ uint8_t rdm_blcnt;
|
||||
TasmotaSerial *RDM6300_Serial = nullptr;
|
||||
|
||||
void RDM6300_Init() {
|
||||
if (pin[GPIO_RDM6300_RX] < 99) {
|
||||
RDM6300_Serial = new TasmotaSerial(pin[GPIO_RDM6300_RX],-1,1);
|
||||
if (PinUsed(GPIO_RDM6300_RX)) {
|
||||
RDM6300_Serial = new TasmotaSerial(Pin(GPIO_RDM6300_RX),-1,1);
|
||||
if (RDM6300_Serial->begin(RDM6300_BAUDRATE)) {
|
||||
if (RDM6300_Serial->hardwareSerial()) {
|
||||
ClaimSerial();
|
||||
|
@ -95,8 +95,8 @@ void IBEACON_Init() {
|
||||
hm17_found=0;
|
||||
|
||||
// actually doesnt work reliably with software serial
|
||||
if ((pin[GPIO_IBEACON_RX] < 99) && (pin[GPIO_IBEACON_TX] < 99)) {
|
||||
IBEACON_Serial = new TasmotaSerial(pin[GPIO_IBEACON_RX], pin[GPIO_IBEACON_TX],1);
|
||||
if (PinUsed(GPIO_IBEACON_RX) && PinUsed(GPIO_IBEACON_TX)) {
|
||||
IBEACON_Serial = new TasmotaSerial(Pin(GPIO_IBEACON_RX), Pin(GPIO_IBEACON_TX),1);
|
||||
if (IBEACON_Serial->begin(HM17_BAUDRATE)) {
|
||||
if (IBEACON_Serial->hardwareSerial()) {
|
||||
ClaimSerial();
|
||||
|
@ -1831,8 +1831,9 @@ uint8_t *script_meter;
|
||||
#endif
|
||||
|
||||
bool Gpio_used(uint8_t gpiopin) {
|
||||
for (uint16_t i=0;i<GPIO_SENSOR_END;i++) {
|
||||
if (pin[i]==gpiopin) {
|
||||
for (uint16_t i=0;i<GPIO_SENSOR_END;i++) { // Theo/Gemu: This needs to change when pin[] has becomes real pin array
|
||||
// if (pin[i]==gpiopin) {
|
||||
if (Pin(i)==gpiopin) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -64,8 +64,8 @@ void HpmaSecond(void) // Every second
|
||||
void HpmaInit(void)
|
||||
{
|
||||
hpma_type = 0;
|
||||
if (pin[GPIO_HPMA_RX] < 99 && pin[GPIO_HPMA_TX] < 99) {
|
||||
HpmaSerial = new TasmotaSerial(pin[GPIO_HPMA_RX], pin[GPIO_HPMA_TX], 1);
|
||||
if (PinUsed(GPIO_HPMA_RX) && PinUsed(GPIO_HPMA_TX)) {
|
||||
HpmaSerial = new TasmotaSerial(Pin(GPIO_HPMA_RX), Pin(GPIO_HPMA_TX), 1);
|
||||
hpma115S0 = new HPMA115S0(*HpmaSerial);
|
||||
|
||||
if (HpmaSerial->begin(9600)) {
|
||||
|
@ -354,8 +354,8 @@ void UBXTriggerTele(void)
|
||||
void UBXDetect(void)
|
||||
{
|
||||
UBX.mode.init = 0;
|
||||
if ((pin[GPIO_GPS_RX] < 99) && (pin[GPIO_GPS_TX] < 99)) {
|
||||
UBXSerial = new TasmotaSerial(pin[GPIO_GPS_RX], pin[GPIO_GPS_TX], 1, 0, UBX_SERIAL_BUFFER_SIZE); // 64 byte buffer is NOT enough
|
||||
if (PinUsed(GPIO_GPS_RX) && PinUsed(GPIO_GPS_TX)) {
|
||||
UBXSerial = new TasmotaSerial(Pin(GPIO_GPS_RX), Pin(GPIO_GPS_TX), 1, 0, UBX_SERIAL_BUFFER_SIZE); // 64 byte buffer is NOT enough
|
||||
if (UBXSerial->begin(9600)) {
|
||||
DEBUG_SENSOR_LOG(PSTR("UBX: started serial"));
|
||||
if (UBXSerial->hardwareSerial()) {
|
||||
|
@ -27,10 +27,10 @@
|
||||
0.9.4.0 20200304 integrate - sensor types can be ignored (default for LYWSD03),
|
||||
add CGD1 (Alarm clock), correct PDU-types for LYWSD02
|
||||
---
|
||||
0.9.3.0 20200222 integrate - use now the correct id-word instead of MAC-OUI,
|
||||
0.9.3.0 20200222 integrate - use now the correct id-word instead of MAC-OUI,
|
||||
add CGG1
|
||||
---
|
||||
0.9.2.0 20200212 integrate - "backports" from MI-HM10, change reading pattern,
|
||||
0.9.2.0 20200212 integrate - "backports" from MI-HM10, change reading pattern,
|
||||
add missing PDU-types, renaming driver
|
||||
---
|
||||
0.9.1.0 20200117 integrate - Added support for the LYWSD02
|
||||
@ -176,7 +176,7 @@ struct {
|
||||
uint8_t packetMode; // 0 - normal BLE-advertisements, 1 - 6 "special" sensor packets
|
||||
uint8_t perPage = 4;
|
||||
uint8_t firstUsedPacketMode = 1;
|
||||
|
||||
|
||||
FIFO_t buffer;
|
||||
|
||||
struct {
|
||||
@ -232,16 +232,16 @@ static union{
|
||||
/********************************************************************************************/
|
||||
|
||||
/**
|
||||
* @brief
|
||||
*
|
||||
* @brief
|
||||
*
|
||||
* @param _mode Packet mode 0-6
|
||||
* @return true If no error occured
|
||||
* @return false If NRF24L01 is not connected
|
||||
* @return false If NRF24L01 is not connected
|
||||
*/
|
||||
bool MINRFinitBLE(uint8_t _mode)
|
||||
{
|
||||
if (MINRF.timer%1000 == 0){ // only re-init every 20 seconds
|
||||
NRF24radio.begin(pin[GPIO_SPI_CS],pin[GPIO_SPI_DC]);
|
||||
NRF24radio.begin(Pin(GPIO_SPI_CS),Pin(GPIO_SPI_DC));
|
||||
NRF24radio.setAutoAck(false);
|
||||
NRF24radio.setDataRate(RF24_1MBPS);
|
||||
NRF24radio.disableCRC();
|
||||
@ -264,7 +264,7 @@ bool MINRFinitBLE(uint8_t _mode)
|
||||
|
||||
/**
|
||||
* @brief cycle through the channels 37-39, skip ignored channel
|
||||
*
|
||||
*
|
||||
*/
|
||||
void MINRFhopChannel()
|
||||
{
|
||||
@ -405,19 +405,19 @@ bool MINRFhandleBeacon(scan_entry_t * entry, uint32_t offset);
|
||||
|
||||
/**
|
||||
* @brief handle a generic BLE-packet in the scan process
|
||||
*
|
||||
*
|
||||
*/
|
||||
void MINRFhandleScan(void){
|
||||
if(MINRFscanResult.size()>20 || MINRF.stopScan) {
|
||||
MINRF.activeScan=false;
|
||||
MINRFcomputefirstUsedPacketMode();
|
||||
uint32_t i = 0; // pass counter as reference to lambda
|
||||
MINRFscanResult.erase(std::remove_if(MINRFscanResult.begin(),
|
||||
MINRFscanResult.erase(std::remove_if(MINRFscanResult.begin(),
|
||||
MINRFscanResult.end(),
|
||||
[&i](scan_entry_t e) {
|
||||
if(e.showedUp>2) AddLog_P2(LOG_LEVEL_INFO,PSTR("MINRF: Beacon %02u: %02X%02X%02X%02X%02X%02X Cid: %04X Svc: %04X UUID: %04X"),i,e.mac[0],e.mac[1],e.mac[2],e.mac[3],e.mac[4],e.mac[5],e.cid,e.svc,e.uuid);
|
||||
i++;
|
||||
return ((e.showedUp < 3));
|
||||
return ((e.showedUp < 3));
|
||||
}),
|
||||
MINRFscanResult.end());
|
||||
MINRF.stopScan=false;
|
||||
@ -447,7 +447,7 @@ void MINRFhandleScan(void){
|
||||
|
||||
/**
|
||||
* @brief start beacon mode, can co-exist with Mijia-sniffing
|
||||
*
|
||||
*
|
||||
* @param entry number of entry in scan list
|
||||
*/
|
||||
void MINRFstartBeacon(uint16_t entry){
|
||||
@ -459,7 +459,7 @@ void MINRFstartBeacon(uint16_t entry){
|
||||
|
||||
/**
|
||||
* @brief semi-generic BLE-ADV-parser
|
||||
*
|
||||
*
|
||||
* @param entry Entry of scan list
|
||||
* @param offset Depends on the reading mode: 0->regular BLE-ADV, 6->"cutted" BLE-ADV with MAC as PDU
|
||||
* @return true - when name, cid, uuid or svc is found with any value
|
||||
@ -536,7 +536,7 @@ bool MINRFhandleBeacon(scan_entry_t * entry, uint32_t offset){
|
||||
|
||||
/**
|
||||
* @brief increase beacon timer every second and process the result
|
||||
*
|
||||
*
|
||||
*/
|
||||
void MINRFbeaconCounter(void){
|
||||
if(MINRF.beacon.active) {
|
||||
@ -550,7 +550,7 @@ void MINRFbeaconCounter(void){
|
||||
|
||||
/**
|
||||
* @brief compute "PDU" from MAC for each possible channel and store it globally
|
||||
*
|
||||
*
|
||||
*/
|
||||
void MINRFcomputeBeaconPDU(void){
|
||||
for (uint32_t i = 0; i<3; i++){
|
||||
@ -570,7 +570,7 @@ void MINRFcomputeBeaconPDU(void){
|
||||
|
||||
/**
|
||||
* @brief reverse 6-byte-array, hard-coded size of 6
|
||||
*
|
||||
*
|
||||
* @param _mac pass an uint_t[6]
|
||||
*/
|
||||
void MINRFreverseMAC(uint8_t _mac[]){
|
||||
@ -582,8 +582,8 @@ void MINRFreverseMAC(uint8_t _mac[]){
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief
|
||||
*
|
||||
* @brief
|
||||
*
|
||||
* @param _string input string in format: AABBCCDDEEFF (upper case!)
|
||||
* @param _mac target byte array with fixed size of 6
|
||||
*/
|
||||
@ -594,7 +594,7 @@ void MINRFMACStringToBytes(char* _string, uint8_t _mac[]) { //uppercase
|
||||
uint8_t value = 0;
|
||||
if(c >= '0' && c <= '9')
|
||||
value = (c - '0');
|
||||
else if (c >= 'A' && c <= 'F')
|
||||
else if (c >= 'A' && c <= 'F')
|
||||
value = (10 + (c - 'A'));
|
||||
_mac[(index/2)] += value << (((index + 1) % 2) * 4);
|
||||
index++;
|
||||
@ -604,7 +604,7 @@ void MINRFMACStringToBytes(char* _string, uint8_t _mac[]) { //uppercase
|
||||
|
||||
/**
|
||||
* @brief helper function, to avoid to start with an ignored sensor type
|
||||
*
|
||||
*
|
||||
*/
|
||||
void MINRFcomputefirstUsedPacketMode(void){
|
||||
for (uint32_t i = 0; i<CGD1; i++){
|
||||
@ -675,7 +675,7 @@ uint32_t MINRFgetSensorSlot(uint8_t (&_serial)[6], uint16_t _type){
|
||||
}
|
||||
}
|
||||
if(!_success) return 0xff;
|
||||
|
||||
|
||||
DEBUG_SENSOR_LOG(PSTR("MINRF: vector size %u"), MIBLEsensors.size());
|
||||
for(uint32_t i=0; i<MIBLEsensors.size(); i++){
|
||||
if(memcmp(_serial,MIBLEsensors[i].serial,sizeof(_serial))==0){
|
||||
@ -724,7 +724,7 @@ uint32_t MINRFgetSensorSlot(uint8_t (&_serial)[6], uint16_t _type){
|
||||
void MINRFpurgeFakeSensors(void){
|
||||
for(uint32_t i=0; i<MIBLEsensors.size(); i++){
|
||||
DEBUG_SENSOR_LOG(PSTR("MINRF: remove FAKE %s at slot: %u"),kMINRFSlaveType[MIBLEsensors[i].type-1], i);
|
||||
MIBLEsensors.erase(std::remove_if(MIBLEsensors.begin(),
|
||||
MIBLEsensors.erase(std::remove_if(MIBLEsensors.begin(),
|
||||
MIBLEsensors.end(),
|
||||
[](mi_sensor_t i) { return ((i.showedUp < 3 || bitRead(MINRF.ignore,i.type))); }),
|
||||
MIBLEsensors.end());
|
||||
@ -747,7 +747,7 @@ void MINRFconfirmSensors(void){
|
||||
|
||||
/**
|
||||
* @brief generic MiBeacon parser
|
||||
*
|
||||
*
|
||||
*/
|
||||
void MINRFhandleMiBeaconPacket(void){
|
||||
MINRFreverseMAC(MINRF.buffer.miBeacon.Mac);
|
||||
@ -784,7 +784,7 @@ void MINRFhandleMiBeaconPacket(void){
|
||||
case 0x07:
|
||||
_sensorVec->lux=MINRF.buffer.miBeacon.lux & 0x00ffffff;
|
||||
DEBUG_SENSOR_LOG(PSTR("Mode 7: U24: %u Lux"), MINRF.buffer.miBeacon.lux & 0x00ffffff);
|
||||
break;
|
||||
break;
|
||||
case 0x08:
|
||||
_tempFloat =(float)MINRF.buffer.miBeacon.moist;
|
||||
if(_tempFloat<100){
|
||||
@ -881,7 +881,7 @@ void MINRFhandleCGD1Packet(void){ // no MiBeacon
|
||||
\*********************************************************************************************/
|
||||
|
||||
void MINRF_EVERY_50_MSECOND() { // Every 50mseconds
|
||||
|
||||
|
||||
if(MINRF.timer>6000){ // happens every 6000/20 = 300 seconds
|
||||
DEBUG_SENSOR_LOG(PSTR("MINRF: check for FAKE sensors"));
|
||||
MINRFpurgeFakeSensors();
|
||||
@ -890,7 +890,7 @@ void MINRF_EVERY_50_MSECOND() { // Every 50mseconds
|
||||
MINRF.timer++;
|
||||
|
||||
if (!MINRFreceivePacket()){
|
||||
// DEBUG_SENSOR_LOG(PSTR("MINRF: nothing received"));
|
||||
// DEBUG_SENSOR_LOG(PSTR("MINRF: nothing received"));
|
||||
}
|
||||
|
||||
else {
|
||||
@ -1057,7 +1057,7 @@ void MINRFShow(bool json)
|
||||
}
|
||||
ResponseAppend_P(PSTR(",\"%s-%02x%02x%02x\":{"),kMINRFSlaveType[MIBLEsensors[i].type-1],MIBLEsensors[i].serial[3],MIBLEsensors[i].serial[4],MIBLEsensors[i].serial[5]);
|
||||
if (MIBLEsensors[i].type==FLORA && !isnan(MIBLEsensors[i].temp)){
|
||||
char stemp[FLOATSZ];
|
||||
char stemp[FLOATSZ];
|
||||
dtostrfd(MIBLEsensors[i].temp, Settings.flag2.temperature_resolution, stemp);
|
||||
ResponseAppend_P(PSTR("\"" D_JSON_TEMPERATURE "\":%s"), stemp);
|
||||
|
||||
@ -1074,7 +1074,7 @@ void MINRFShow(bool json)
|
||||
}
|
||||
ResponseJsonEnd();
|
||||
}
|
||||
if (MIBLEsensors[i].type>FLORA){
|
||||
if (MIBLEsensors[i].type>FLORA){
|
||||
if(!isnan(MIBLEsensors[i].temp) && !isnan(MIBLEsensors[i].hum)){
|
||||
ResponseAppendTHD(MIBLEsensors[i].temp,MIBLEsensors[i].hum);
|
||||
}
|
||||
@ -1112,7 +1112,7 @@ void MINRFShow(bool json)
|
||||
continue;
|
||||
}
|
||||
WSContentSend_PD(HTTP_MINRF_HL);
|
||||
WSContentSend_PD(HTTP_MINRF_MAC, kMINRFSlaveType[MIBLEsensors[i].type-1], D_MAC_ADDRESS, MIBLEsensors[i].serial[0], MIBLEsensors[i].serial[1],MIBLEsensors[i].serial[2],MIBLEsensors[i].serial[3],MIBLEsensors[i].serial[4],MIBLEsensors[i].serial[5]);
|
||||
WSContentSend_PD(HTTP_MINRF_MAC, kMINRFSlaveType[MIBLEsensors[i].type-1], D_MAC_ADDRESS, MIBLEsensors[i].serial[0], MIBLEsensors[i].serial[1],MIBLEsensors[i].serial[2],MIBLEsensors[i].serial[3],MIBLEsensors[i].serial[4],MIBLEsensors[i].serial[5]);
|
||||
if (MIBLEsensors[i].type==FLORA){
|
||||
if(!isnan(MIBLEsensors[i].temp)){
|
||||
char temperature[FLOATSZ];
|
||||
@ -1139,7 +1139,7 @@ void MINRFShow(bool json)
|
||||
if(MINRF.beacon.active){
|
||||
WSContentSend_PD(HTTP_MINRF_HL);
|
||||
WSContentSend_PD(HTTP_MINRF_HL);
|
||||
WSContentSend_PD(HTTP_MINRF_MAC, F("Beacon"), D_MAC_ADDRESS, MINRF.beacon.mac[0], MINRF.beacon.mac[1],MINRF.beacon.mac[2],MINRF.beacon.mac[3],MINRF.beacon.mac[4],MINRF.beacon.mac[5]);
|
||||
WSContentSend_PD(HTTP_MINRF_MAC, F("Beacon"), D_MAC_ADDRESS, MINRF.beacon.mac[0], MINRF.beacon.mac[1],MINRF.beacon.mac[2],MINRF.beacon.mac[3],MINRF.beacon.mac[4],MINRF.beacon.mac[5]);
|
||||
WSContentSend_PD(PSTR("{s}Beacon Time{m}%u seconds{e}"),MINRF.beacon.time);
|
||||
}
|
||||
if(counter>3) {
|
||||
|
@ -403,7 +403,7 @@ uint32_t MIBLEgetSensorSlot(uint8_t (&_serial)[6], uint16_t _type){
|
||||
void HM10SerialInit(void) {
|
||||
HM10.mode.init = false;
|
||||
HM10.serialSpeed = HM10_BAUDRATE;
|
||||
HM10Serial = new TasmotaSerial(pin[GPIO_HM10_RX], pin[GPIO_HM10_TX], 1, 0, HM10_MAX_RX_BUF);
|
||||
HM10Serial = new TasmotaSerial(Pin(GPIO_HM10_RX), Pin(GPIO_HM10_TX), 1, 0, HM10_MAX_RX_BUF);
|
||||
if (HM10Serial->begin(HM10.serialSpeed)) {
|
||||
AddLog_P2(LOG_LEVEL_DEBUG, PSTR("%s start serial communication fixed to 115200 baud"),D_CMND_HM10);
|
||||
if (HM10Serial->hardwareSerial()) {
|
||||
@ -1257,7 +1257,7 @@ bool Xsns62(uint8_t function)
|
||||
{
|
||||
bool result = false;
|
||||
|
||||
if ((pin[GPIO_HM10_RX] < 99) && (pin[GPIO_HM10_TX] < 99)) {
|
||||
if (PinUsed(GPIO_HM10_RX) && PinUsed(GPIO_HM10_TX)) {
|
||||
switch (function) {
|
||||
case FUNC_INIT:
|
||||
HM10SerialInit(); // init and start communication
|
||||
|
@ -41,9 +41,9 @@ bool hrxl_found = false;
|
||||
void HRXLInit(void)
|
||||
{
|
||||
hrxl_found = false;
|
||||
if ((pin[GPIO_HRXL_RX] < 99))
|
||||
if (PinUsed(GPIO_HRXL_RX))
|
||||
{
|
||||
HRXLSerial = new TasmotaSerial(pin[GPIO_HRXL_RX], -1, 1);
|
||||
HRXLSerial = new TasmotaSerial(Pin(GPIO_HRXL_RX), -1, 1);
|
||||
if (HRXLSerial->begin(9600))
|
||||
{
|
||||
if (HRXLSerial->hardwareSerial())
|
||||
@ -100,8 +100,7 @@ void HRXLShow(bool json)
|
||||
|
||||
bool Xsns64(uint8_t function)
|
||||
{
|
||||
if (pin[GPIO_HRXL_RX] >= 99)
|
||||
return false;
|
||||
if (!PinUsed(GPIO_HRXL_RX)) { return false; }
|
||||
|
||||
switch (function)
|
||||
{
|
||||
|
@ -401,9 +401,9 @@ void AS3935SetWdth(uint8_t wdth) {
|
||||
}
|
||||
|
||||
bool AS3935AutoTune(){
|
||||
detachInterrupt(pin[GPIO_AS3935]);
|
||||
bool result = AS3935AutoTuneCaps(pin[GPIO_AS3935]);
|
||||
attachInterrupt(digitalPinToInterrupt(pin[GPIO_AS3935]), AS3935Isr, RISING);
|
||||
detachInterrupt(Pin(GPIO_AS3935));
|
||||
bool result = AS3935AutoTuneCaps(Pin(GPIO_AS3935));
|
||||
attachInterrupt(digitalPinToInterrupt(Pin(GPIO_AS3935)), AS3935Isr, RISING);
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -497,8 +497,8 @@ void AS3935Detect(void) {
|
||||
if (AS3935init())
|
||||
{
|
||||
I2cSetActiveFound(AS3935_ADDR, D_NAME_AS3935);
|
||||
pinMode(pin[GPIO_AS3935], INPUT);
|
||||
attachInterrupt(digitalPinToInterrupt(pin[GPIO_AS3935]), AS3935Isr, RISING);
|
||||
pinMode(Pin(GPIO_AS3935), INPUT);
|
||||
attachInterrupt(digitalPinToInterrupt(Pin(GPIO_AS3935)), AS3935Isr, RISING);
|
||||
AS3935Setup();
|
||||
as3935_active = 1;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user