This commit is contained in:
mvdbro
2017-08-26 21:40:06 +02:00
parent 493f4b6323
commit 6a779ec75a
4 changed files with 82 additions and 52 deletions

View File

@@ -76,7 +76,7 @@
#define socketdebug false
#define ARDUINO_PROJECT_PID 2016110201L
#define VERSION 2
#define BUILD 153
#define BUILD 154
#define BUILD_NOTES ""
#define NODE_TYPE_ID_ESP_EASY_STD 1

View File

@@ -656,7 +656,6 @@ void handle_hardware(EthernetClient client, String &post) {
{
Settings.PinBootStates[2] = WebServer.arg(F("p2")).toInt();
Settings.PinBootStates[3] = WebServer.arg(F("p3")).toInt();
Settings.PinBootStates[4] = WebServer.arg(F("p4")).toInt();
Settings.PinBootStates[5] = WebServer.arg(F("p5")).toInt();
Settings.PinBootStates[6] = WebServer.arg(F("p6")).toInt();
Settings.PinBootStates[7] = WebServer.arg(F("p7")).toInt();
@@ -677,14 +676,12 @@ void handle_hardware(EthernetClient client, String &post) {
addPinStateSelect(reply, "p2", Settings.PinBootStates[2]);
reply += F("<TR><TD>D3:<TD>");
addPinStateSelect(reply, "p3", Settings.PinBootStates[3]);
reply += F("<TR><TD>D4:<TD>");
addPinStateSelect(reply, "p4", Settings.PinBootStates[4]);
reply += F("<TR><TD>D5:<TD>");
addPinStateSelect(reply, "p5", Settings.PinBootStates[5]);
client.print(reply);
reply = "";
addPinStateSelect(reply, "p5", Settings.PinBootStates[5]);
reply += F("<TR><TD>D6:<TD>");
addPinStateSelect(reply, "p6", Settings.PinBootStates[6]);
reply += F("<TR><TD>D7:<TD>");
@@ -1368,34 +1365,32 @@ void sortDeviceArray()
//********************************************************************************
void addPinSelect(boolean forI2C, String& str, String name, int choice)
{
String options[11];
String options[10];
options[0] = F(" ");
options[1] = F("D2");
options[2] = F("D3");
options[3] = F("D4");
options[4] = F("D5");
options[5] = F("D6");
options[6] = F("D7");
options[7] = F("D8");
options[8] = F("D9");
options[9] = F("D11");
options[10] = F("D12");
int optionValues[11];
options[3] = F("D5");
options[4] = F("D6");
options[5] = F("D7");
options[6] = F("D8");
options[7] = F("D9");
options[8] = F("D11");
options[9] = F("D12");
int optionValues[10];
optionValues[0] = -1;
optionValues[1] = 2;
optionValues[2] = 3;
optionValues[3] = 4;
optionValues[4] = 5;
optionValues[5] = 6;
optionValues[6] = 7;
optionValues[7] = 8;
optionValues[8] = 9;
optionValues[9] = 11;
optionValues[10] = 12;
optionValues[3] = 5;
optionValues[4] = 6;
optionValues[5] = 7;
optionValues[6] = 8;
optionValues[7] = 9;
optionValues[8] = 11;
optionValues[9] = 12;
str += F("<select name='");
str += name;
str += "'>";
for (byte x = 0; x < 11; x++)
for (byte x = 0; x < 10; x++)
{
str += F("<option value='");
str += optionValues[x];

View File

@@ -7,6 +7,18 @@
#define PLUGIN_NAME_004 "Temperature - DS18b20"
#define PLUGIN_VALUENAME1_004 "Temperature"
#define PIN_TO_BASEREG(pin) (portInputRegister(digitalPinToPort(pin)))
#define PIN_TO_BITMASK(pin) (digitalPinToBitMask(pin))
#define IO_REG_TYPE uint8_t
#define IO_REG_ASM asm("r30")
#define DIRECT_READ(base, mask) (((*(base)) & (mask)) ? 1 : 0)
#define DIRECT_MODE_INPUT(base, mask) ((*((base)+1)) &= ~(mask))
#define DIRECT_MODE_OUTPUT(base, mask) ((*((base)+1)) |= (mask))
#define DIRECT_WRITE_LOW(base, mask) ((*((base)+2)) &= ~(mask))
#define DIRECT_WRITE_HIGH(base, mask) ((*((base)+2)) |= (mask))
IO_REG_TYPE bitmask;
volatile IO_REG_TYPE *baseReg;
uint8_t Plugin_004_DallasPin;
boolean Plugin_004(byte function, struct EventStruct *event, String& string)
@@ -51,6 +63,9 @@ boolean Plugin_004(byte function, struct EventStruct *event, String& string)
// Scan the onewire bus and fill dropdown list with devicecount on this GPIO.
Plugin_004_DallasPin = Settings.TaskDevicePin1[event->TaskIndex];
bitmask = PIN_TO_BITMASK(Plugin_004_DallasPin );
baseReg = PIN_TO_BASEREG(Plugin_004_DallasPin );
byte choice = Settings.TaskDevicePluginConfig[event->TaskIndex][0];
byte devCount = Plugin_004_DS_scan(choice, addr);
string += F("<TR><TD>Device Nr:<TD><select name='plugin_004_dev'>");
@@ -107,6 +122,8 @@ boolean Plugin_004(byte function, struct EventStruct *event, String& string)
case PLUGIN_READ:
{
bitmask = PIN_TO_BITMASK(Plugin_004_DallasPin );
baseReg = PIN_TO_BASEREG(Plugin_004_DallasPin );
uint8_t addr[8];
// Load ROM address from tasksettings
LoadTaskSettings(event->TaskIndex);
@@ -220,22 +237,31 @@ boolean Plugin_004_DS_readTemp(uint8_t ROM[8], float *value)
\*********************************************************************************************/
uint8_t Plugin_004_DS_reset()
{
IO_REG_TYPE mask = bitmask;
volatile IO_REG_TYPE *reg IO_REG_ASM = baseReg;
uint8_t r;
uint8_t retries = 125;
//noInterrupts();
pinMode(Plugin_004_DallasPin, INPUT);
do { // wait until the wire is high... just in case
noInterrupts();
DIRECT_MODE_INPUT(reg, mask);
interrupts();
// wait until the wire is high... just in case
do {
if (--retries == 0) return 0;
delayMicroseconds(2);
} while ( !digitalRead(Plugin_004_DallasPin));
} while ( !DIRECT_READ(reg, mask));
pinMode(Plugin_004_DallasPin, OUTPUT); digitalWrite(Plugin_004_DallasPin, LOW);
delayMicroseconds(492); // Dallas spec. = Min. 480uSec. Arduino 500uSec.
pinMode(Plugin_004_DallasPin, INPUT); //Float
delayMicroseconds(40);
r = !digitalRead(Plugin_004_DallasPin);
delayMicroseconds(420);
//interrupts();
noInterrupts();
DIRECT_WRITE_LOW(reg, mask);
DIRECT_MODE_OUTPUT(reg, mask); // drive output low
interrupts();
delayMicroseconds(480);
noInterrupts();
DIRECT_MODE_INPUT(reg, mask); // allow it to float
delayMicroseconds(70);
r = !DIRECT_READ(reg, mask);
interrupts();
delayMicroseconds(410);
return r;
}
@@ -415,16 +441,18 @@ void Plugin_004_DS_write(uint8_t ByteToWrite)
\*********************************************************************************************/
uint8_t Plugin_004_DS_read_bit(void)
{
IO_REG_TYPE mask=bitmask;
volatile IO_REG_TYPE *reg IO_REG_ASM = baseReg;
uint8_t r;
//noInterrupts();
pinMode(Plugin_004_DallasPin, OUTPUT);
digitalWrite(Plugin_004_DallasPin, LOW);
noInterrupts();
DIRECT_MODE_OUTPUT(reg, mask);
DIRECT_WRITE_LOW(reg, mask);
delayMicroseconds(3);
pinMode(Plugin_004_DallasPin, INPUT); // let pin float, pull up will raise
DIRECT_MODE_INPUT(reg, mask); // let pin float, pull up will raise
delayMicroseconds(10);
r = digitalRead(Plugin_004_DallasPin);
//interrupts();
r = DIRECT_READ(reg, mask);
interrupts();
delayMicroseconds(53);
return r;
}
@@ -435,21 +463,24 @@ uint8_t Plugin_004_DS_read_bit(void)
\*********************************************************************************************/
void Plugin_004_DS_write_bit(uint8_t v)
{
IO_REG_TYPE mask=bitmask;
volatile IO_REG_TYPE *reg IO_REG_ASM = baseReg;
if (v & 1) {
//noInterrupts();
digitalWrite(Plugin_004_DallasPin, LOW);
pinMode(Plugin_004_DallasPin, OUTPUT);
noInterrupts();
DIRECT_WRITE_LOW(reg, mask);
DIRECT_MODE_OUTPUT(reg, mask); // drive output low
delayMicroseconds(10);
digitalWrite(Plugin_004_DallasPin, HIGH);
//interrupts();
DIRECT_WRITE_HIGH(reg, mask); // drive output high
interrupts();
delayMicroseconds(55);
} else {
//noInterrupts();
digitalWrite(Plugin_004_DallasPin, LOW);
pinMode(Plugin_004_DallasPin, OUTPUT);
noInterrupts();
DIRECT_WRITE_LOW(reg, mask);
DIRECT_MODE_OUTPUT(reg, mask); // drive output low
delayMicroseconds(65);
digitalWrite(Plugin_004_DallasPin, HIGH);
//interrupts();
DIRECT_WRITE_HIGH(reg, mask); // drive output high
interrupts();
delayMicroseconds(5);
}
}

View File

@@ -1,4 +1,8 @@
// R153
// R154 26-08-2017
// Removed pin select D4 from the list as it is used for SD Card
// Fixed Dallas plugin for AVR
// R153 25-08-2017
// Added nodetype to self.
// Minor cosmetic GUI fixes