Software push v0.1
This commit is contained in:
parent
aee0c2cf6c
commit
e7b1092530
224
Software/RT26301.ino
Normal file
224
Software/RT26301.ino
Normal file
@ -0,0 +1,224 @@
|
||||
#include <OneWire.h>
|
||||
#include <DallasTemperature.h>
|
||||
#include <Wire.h>
|
||||
|
||||
OneWire ow0(8); // GP0
|
||||
OneWire ow1(9); // GP1
|
||||
|
||||
#define UART_TX 0
|
||||
#define UART_RX 1
|
||||
#define FRAM_ADDR 0x50
|
||||
#define FRAM_SIZE 32768
|
||||
|
||||
DallasTemperature ds0(&ow0);
|
||||
DallasTemperature ds1(&ow1);
|
||||
|
||||
volatile int resolution = 12;
|
||||
volatile int cuton0 = 30;
|
||||
volatile int cutoff0 = 33;
|
||||
volatile int cuton1 = 30;
|
||||
volatile int cutoff1 = 33;
|
||||
int res = 12;
|
||||
|
||||
void fram_init()
|
||||
{
|
||||
Wire.setSDA(12);
|
||||
Wire.setSCL(13);
|
||||
Wire.begin();
|
||||
}
|
||||
|
||||
void fram_write(uint16_t addr, uint8_t data)
|
||||
{
|
||||
if (addr >= FRAM_SIZE) return;
|
||||
|
||||
Wire.beginTransmission(FRAM_ADDR);
|
||||
Wire.write(addr >> 8); // High byte Adresse
|
||||
Wire.write(addr & 0xFF); // Low byte Adresse
|
||||
Wire.write(data);
|
||||
Wire.endTransmission();
|
||||
}
|
||||
|
||||
uint8_t fram_read(uint16_t addr)
|
||||
{
|
||||
if (addr >= FRAM_SIZE) return 0;
|
||||
|
||||
Wire.beginTransmission(FRAM_ADDR);
|
||||
Wire.write(addr >> 8);
|
||||
Wire.write(addr & 0xFF);
|
||||
Wire.endTransmission(false);
|
||||
|
||||
Wire.requestFrom(FRAM_ADDR, 1);
|
||||
|
||||
if (Wire.available())
|
||||
return Wire.read();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void setup() {
|
||||
Serial1.setTX(0); // GP0
|
||||
Serial1.setRX(1); // GP1
|
||||
Serial1.begin(115200);
|
||||
pinMode(10, OUTPUT);
|
||||
digitalWrite(10, HIGH);
|
||||
pinMode(11, OUTPUT);
|
||||
digitalWrite(11, HIGH);
|
||||
|
||||
fram_init();
|
||||
cuton0 = fram_read(1);
|
||||
cutoff0 = fram_read(2);
|
||||
cuton1 = fram_read(3);
|
||||
cutoff1 = fram_read(4);
|
||||
resolution = fram_read(5);
|
||||
|
||||
ds0.begin();
|
||||
ds1.begin();
|
||||
|
||||
ds0.setWaitForConversion(false);
|
||||
ds1.setWaitForConversion(false);
|
||||
|
||||
ds0.setResolution(resolution);
|
||||
ds1.setResolution(resolution);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
ds0.requestTemperatures();
|
||||
ds1.requestTemperatures();
|
||||
switch(resolution){
|
||||
case 9:
|
||||
delay(100);
|
||||
break;
|
||||
case 10:
|
||||
delay(190);
|
||||
break;
|
||||
case 11:
|
||||
delay(375);
|
||||
break;
|
||||
case 12:
|
||||
delay(750);
|
||||
break;
|
||||
}
|
||||
float t0 = ds0.getTempCByIndex(0);
|
||||
float t1 = ds1.getTempCByIndex(0);
|
||||
if(t1 <= cuton0){
|
||||
digitalWrite(10, HIGH);
|
||||
}
|
||||
if(t0 <= cuton1){
|
||||
digitalWrite(11, HIGH);
|
||||
}
|
||||
if(t1 >= cutoff0){
|
||||
digitalWrite(10, LOW);
|
||||
}
|
||||
if(t0 >= cutoff1){
|
||||
digitalWrite(11, LOW);
|
||||
}
|
||||
if(t0 != -127 || t1 != -127){
|
||||
Serial1.print(t0, 4);
|
||||
Serial1.print(";");
|
||||
Serial1.println(t1, 4);
|
||||
Serial1.flush();
|
||||
if(res != resolution){
|
||||
ds0.setResolution(resolution);
|
||||
ds1.setResolution(resolution);
|
||||
res = resolution;
|
||||
}
|
||||
}
|
||||
|
||||
static String cmd;
|
||||
|
||||
while (Serial1.available()) {
|
||||
char c = Serial1.read();
|
||||
|
||||
if (c == '\n' || c == '\r') {
|
||||
|
||||
if (cmd.startsWith("res:")) {
|
||||
|
||||
int newRes = cmd.substring(4).toInt();
|
||||
|
||||
if (newRes >= 9 && newRes <= 12) {
|
||||
|
||||
resolution = newRes;
|
||||
Serial1.print("OK RES=");
|
||||
Serial1.println(resolution);
|
||||
Serial1.flush();
|
||||
fram_write(5,resolution);
|
||||
} else {
|
||||
Serial1.println("ERR");
|
||||
Serial1.flush();
|
||||
}
|
||||
}
|
||||
|
||||
if (cmd.startsWith("cuton0:")) {
|
||||
|
||||
int newcuton0 = cmd.substring(7).toInt();
|
||||
|
||||
if (newcuton0 >= -55 && newcuton0 <= 125) {
|
||||
|
||||
cuton0 = newcuton0;
|
||||
Serial1.print("OK cuton0=");
|
||||
Serial1.println(cuton0);
|
||||
Serial1.flush();
|
||||
fram_write(1,cuton0);
|
||||
} else {
|
||||
Serial1.println("ERR");
|
||||
Serial1.flush();
|
||||
}
|
||||
}
|
||||
|
||||
if (cmd.startsWith("cutoff0:")) {
|
||||
|
||||
int newcutoff0 = cmd.substring(8).toInt();
|
||||
|
||||
if (newcutoff0 >= -55 && newcutoff0 <= 125) {
|
||||
|
||||
cutoff0 = newcutoff0;
|
||||
Serial1.print("OK cutoff0=");
|
||||
Serial1.println(cutoff0);
|
||||
Serial1.flush();
|
||||
fram_write(2,cutoff0);
|
||||
} else {
|
||||
Serial1.println("ERR");
|
||||
Serial1.flush();
|
||||
}
|
||||
}
|
||||
|
||||
if (cmd.startsWith("cuton1:")) {
|
||||
|
||||
int newcuton1 = cmd.substring(7).toInt();
|
||||
|
||||
if (newcuton1 >= -55 && newcuton1 <= 125) {
|
||||
|
||||
cuton1 = newcuton1;
|
||||
Serial1.print("OK cuton1=");
|
||||
Serial1.println(cuton1);
|
||||
Serial1.flush();
|
||||
fram_write(3,cuton1);
|
||||
} else {
|
||||
Serial1.println("ERR");
|
||||
Serial1.flush();
|
||||
}
|
||||
}
|
||||
|
||||
if (cmd.startsWith("cutoff1:")) {
|
||||
|
||||
int newcutoff1 = cmd.substring(8).toInt();
|
||||
|
||||
if (newcutoff1 >= -55 && newcutoff1 <= 125) {
|
||||
|
||||
cutoff1 = newcutoff1;
|
||||
Serial1.print("OK cutoff1=");
|
||||
Serial1.println(cutoff1);
|
||||
Serial1.flush();
|
||||
fram_write(4,cutoff1);
|
||||
} else {
|
||||
Serial1.println("ERR");
|
||||
Serial1.flush();
|
||||
}
|
||||
}
|
||||
|
||||
cmd = "";
|
||||
} else {
|
||||
cmd += c;
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user