Commits

Alessio Caiazza committed 3b0a123

switched to ion build system. http://inotool.org

Comments (0)

Files changed (11)

 syntax: glob
-termostato_rx/build
-termostato_tx/build
-termostato_rx/build.sh
-termostato_rx/makefile
-termostato_tx/build.sh
-termostato_tx/makefile
+ino.ini
+syntax: regexp
+^termostato_(r|t)x/\.build/

termostato_rx/lib/SoftEasyTransfer

+../../termostato_tx/lib/SoftEasyTransfer

termostato_rx/lib/termostato

+../../termostato

termostato_rx/src/termostato_rx.ino

+#include <SoftEasyTransfer.h>
+#include <SoftwareSerial.h>
+#include "../lib/termostato/protocol.h"
+
+
+#define STATUS_LED 13
+#define RELE 12
+#define RADIO_IN 2
+
+#define LOST_SIGNAL_TRASHOLD 30 * 1000
+#define LOOP_DELAY 250
+
+SoftwareSerial mySerial(RADIO_IN, 3);
+
+
+//create object
+SoftEasyTransfer ET; 
+
+
+//give a name to the group of data
+HOTSPOT_MSG mydata;
+
+unsigned long time;
+bool connectionLost;
+bool status;
+
+void setup(){
+  mySerial.begin(9600);
+  ET.begin(details(mydata), &mySerial);
+  
+  pinMode(STATUS_LED, OUTPUT);
+  pinMode(RELE, OUTPUT);
+
+  time = millis();
+  connectionLost = true;
+  status = false;
+  Serial.begin(9600);
+}
+
+void loop(){
+  //check and see if a data packet has come in. 
+  if(ET.receiveData()){
+    connectionLost = false;
+    time = millis();
+    switch(mydata.cmd) {
+      case PING:
+        status = mydata.args;
+        Serial.print("PING: status "); Serial.println(status);
+        break;
+      case SWITCH_ON:
+        status = true;
+        Serial.println("SWITCH_ON");
+        break;
+      case SWITCH_OFF:
+        status = false;
+        Serial.println("SWITCH_OFF");
+        break;
+    } 
+    digitalWrite(RELE, status);
+    digitalWrite(STATUS_LED, status);
+  } else {
+    unsigned long now = millis();
+    if(now - time > LOST_SIGNAL_TRASHOLD)
+      connectionLost = true;
+
+    if(connectionLost) {
+      status = !status;
+      digitalWrite(STATUS_LED, status);
+    }
+  }
+  
+  delay(LOOP_DELAY);
+}

termostato_rx/termostato_rx.ino

-#include <SoftEasyTransfer.h>
-#include <SoftwareSerial.h>
-#include "../termostato/protocol.h"
-
-
-#define STATUS_LED 13
-#define RELE 12
-#define RADIO_IN 2
-
-#define LOST_SIGNAL_TRASHOLD 30 * 1000
-#define LOOP_DELAY 250
-
-SoftwareSerial mySerial(RADIO_IN, 3);
-
-
-//create object
-SoftEasyTransfer ET; 
-
-
-//give a name to the group of data
-HOTSPOT_MSG mydata;
-
-unsigned long time;
-bool connectionLost;
-bool status;
-
-void setup(){
-  mySerial.begin(9600);
-  ET.begin(details(mydata), &mySerial);
-  
-  pinMode(STATUS_LED, OUTPUT);
-  pinMode(RELE, OUTPUT);
-
-  time = millis();
-  connectionLost = true;
-  status = false;
-  Serial.begin(9600);
-}
-
-void loop(){
-  //check and see if a data packet has come in. 
-  if(ET.receiveData()){
-    connectionLost = false;
-    time = millis();
-    switch(mydata.cmd) {
-      case PING:
-        status = mydata.args;
-        Serial.print("PING: status "); Serial.println(status);
-        break;
-      case SWITCH_ON:
-        status = true;
-        Serial.println("SWITCH_ON");
-        break;
-      case SWITCH_OFF:
-        status = false;
-        Serial.println("SWITCH_OFF");
-        break;
-    } 
-    digitalWrite(RELE, status);
-    digitalWrite(STATUS_LED, status);
-  } else {
-    unsigned long now = millis();
-    if(now - time > LOST_SIGNAL_TRASHOLD)
-      connectionLost = true;
-
-    if(connectionLost) {
-      status = !status;
-      digitalWrite(STATUS_LED, status);
-    }
-  }
-  
-  delay(LOOP_DELAY);
-}

termostato_tx/lib/SoftEasyTransfer/SoftEasyTransfer.cpp

+#include "SoftEasyTransfer.h"
+
+
+
+
+#if ARDUINO > 22
+//Captures address and size of struct
+void SoftEasyTransfer::begin(uint8_t * ptr, uint8_t length, SoftwareSerial *theSerial){
+	address = ptr;
+	size = length;
+	_serial = theSerial;
+
+	//dynamic creation of rx parsing buffer in RAM
+	rx_buffer = (uint8_t*) malloc(size);
+}
+
+#else
+//Captures address and size of struct
+void SoftEasyTransfer::begin(uint8_t * ptr, uint8_t length, NewSoftSerial *theSerial){
+	address = ptr;
+	size = length;
+	_serial = theSerial;
+	
+	//dynamic creation of rx parsing buffer in RAM
+	rx_buffer = (uint8_t*) malloc(size);
+}
+
+#endif
+
+#if ARDUINO > 22
+//Sends out struct in binary, with header, length info and checksum
+void SoftEasyTransfer::sendData(){
+  uint8_t CS = size;
+  _serial->write(0x06);
+  _serial->write(0x85);
+  _serial->write(size);
+  for(int i = 0; i<size; i++){
+    CS^=*(address+i);
+    _serial->write(*(address+i));
+  }
+  _serial->write(CS);
+
+}
+#else
+//Sends out struct in binary, with header, length info and checksum
+void SoftEasyTransfer::sendData(){
+  uint8_t CS = size;
+  _serial->print(0x06, BYTE);
+  _serial->print(0x85, BYTE);
+  _serial->print(size, BYTE);
+  for(int i = 0; i<size; i++){
+    CS^=*(address+i);
+    _serial->print(*(address+i), BYTE);
+  }
+  _serial->print(CS, BYTE);
+
+}
+#endif
+
+boolean SoftEasyTransfer::receiveData(){
+  
+  //start off by looking for the header bytes. If they were already found in a previous call, skip it.
+  if(rx_len == 0){
+  //this size check may be redundant due to the size check below, but for now I'll leave it the way it is.
+    if(_serial->available() >= 3){
+	//this will block until a 0x06 is found or buffer size becomes less then 3.
+      while(_serial->read() != 0x06) {
+		//This will trash any preamble junk in the serial buffer
+		//but we need to make sure there is enough in the buffer to process while we trash the rest
+		//if the buffer becomes too empty, we will escape and try again on the next call
+		if(_serial->available() < 3)
+			return false;
+		}
+      if (_serial->read() == 0x85){
+        rx_len = _serial->read();
+		//make sure the binary structs on both Arduinos are the same size.
+        if(rx_len != size){
+          rx_len = 0;
+          return false;
+        }
+      }
+    }
+  }
+  
+  
+  
+  if(rx_len != 0){
+    while(_serial->available() && rx_array_inx <= rx_len){
+      rx_buffer[rx_array_inx++] = _serial->read();
+    }
+    
+    if(rx_len == (rx_array_inx-1)){
+      //seem to have got whole message
+      //last uint8_t is CS
+      calc_CS = rx_len;
+      for (int i = 0; i<rx_len; i++){
+        calc_CS^=rx_buffer[i];
+      } 
+      
+      if(calc_CS == rx_buffer[rx_array_inx-1]){//CS good
+        memcpy(address,rx_buffer,size);
+		rx_len = 0;
+		rx_array_inx = 0;
+		return true;
+		}
+        
+	  else{
+	  //failed checksum, need to clear this out anyway
+		rx_len = 0;
+		rx_array_inx = 0;
+		return false;
+	  }	
+		
+    }
+  }
+  
+  return false;
+}

termostato_tx/lib/SoftEasyTransfer/SoftEasyTransfer.h

+/******************************************************************
+*  EasyTransfer Arduino Library 
+*		details and example sketch: 
+*			http://www.billporter.info/easytransfer-arduino-library/
+*
+*		Brought to you by:
+*              Bill Porter
+*              www.billporter.info
+*
+*		See Readme for other info and version history
+*	
+*  
+*This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or(at your option) any later version.
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+<http://www.gnu.org/licenses/>
+*
+*This work is licensed under the Creative Commons Attribution-ShareAlike 3.0 Unported License. 
+*To view a copy of this license, visit http://creativecommons.org/licenses/by-sa/3.0/ or
+*send a letter to Creative Commons, 444 Castro Street, Suite 900, Mountain View, California, 94041, USA.
+******************************************************************/
+#ifndef SoftEasyTransfer_h
+#define SoftEasyTransfer_h
+
+
+//make it a little prettier on the front end. 
+#define details(name) (byte*)&name,sizeof(name)
+
+//Not neccessary, but just in case. 
+#if ARDUINO > 22
+#include "Arduino.h"
+#include <SoftwareSerial.h>
+#else
+#include "WProgram.h"
+#include <NewSoftSerial.h>
+#endif
+//#include "HardwareSerial.h"
+
+
+#include <math.h>
+#include <stdio.h>
+#include <stdint.h>
+#include <avr/io.h>
+
+class SoftEasyTransfer {
+public:
+//void begin(uint8_t *, uint8_t, HardwareSerial *theSerial);
+#if ARDUINO > 22
+void begin(uint8_t *, uint8_t, SoftwareSerial *theSerial);
+#else
+void begin(uint8_t *, uint8_t, NewSoftSerial *theSerial);
+#endif
+void sendData();
+boolean receiveData();
+private:
+//HardwareSerial *_serial;
+
+#if ARDUINO > 22
+SoftwareSerial *_serial;
+#else
+NewSoftSerial *_serial;
+#endif
+
+
+uint8_t * address;  //address of struct
+uint8_t size;       //size of struct
+uint8_t * rx_buffer; //address for temporary storage and parsing buffer
+uint8_t rx_array_inx;  //index for RX parsing buffer
+uint8_t rx_len;		//RX packet length according to the packet
+uint8_t calc_CS;	   //calculated Chacksum
+};
+
+
+
+#endif

termostato_tx/lib/SoftEasyTransfer/keywords.txt

+#######################################
+# Syntax Coloring Map EasyTransfer
+#######################################
+
+#######################################
+# Datatypes (KEYWORD1)
+#######################################
+
+SoftEasyTransfer	KEYWORD1
+
+#######################################
+# Methods and Functions (KEYWORD2)
+#######################################
+sendData	KEYWORD2
+receiveData	KEYWORD2
+begin	KEYWORD2
+
+
+#######################################
+# Constants (LITERAL1)
+#######################################
+details	LITERAL1

termostato_tx/lib/termostato

+../../termostato

termostato_tx/src/termostato_tx.ino

+#include <SoftEasyTransfer.h>
+#include <SoftwareSerial.h>
+#include "../lib/termostato/protocol.h"
+
+#define GENERAl_SWITCH 7
+#define POT A5
+#define TEMP A2
+#define RADIO_OUT 2
+#define STATUS_LED 13
+
+// we tie 3.3V to ARef and measure it with a multimeter!
+#define aref_voltage 5.0    
+#define TEMP_MIN 12
+#define TEMP_MAX 33
+
+#define LOOP_DELAY 5000
+#define PING_FREQ 15000
+#define NUMSAMPLES 5
+
+SoftEasyTransfer ET; 
+SoftwareSerial mySerial(3, RADIO_OUT);
+
+
+
+//give a name to the group of data
+HOTSPOT_MSG mydata;
+
+
+long lastPing;
+bool status;
+
+void setup(){  
+  mySerial.begin(9600);
+  ET.begin(details(mydata), &mySerial);
+
+  
+  pinMode(STATUS_LED, OUTPUT);
+  pinMode(GENERAl_SWITCH, INPUT);
+  pinMode(POT, INPUT);
+  pinMode(TEMP, INPUT);
+   
+  Serial.begin(9600);
+  lastPing = 0;
+  status = false;
+  digitalWrite(STATUS_LED, status);
+}
+
+int getTemp() {
+	int samples[NUMSAMPLES]; 
+	uint8_t i; 
+ 	float average;
+  // take N samples in a row, with a slight delay
+  for (i=0; i< NUMSAMPLES; i++) {
+    samples[i] = analogRead(TEMP);
+    delay(10);
+  }
+  // average all the samples out
+  average = 0;
+  for (i=0; i< NUMSAMPLES; i++) {
+    average += samples[i];
+  }
+  average /= NUMSAMPLES;
+
+  Serial.print("Temp:\t");
+  //Serial.print(tempReading);     // the raw analog reading
+ 
+  // converting that reading to voltage, which is based off the reference voltage
+  float voltage = average * aref_voltage;
+  voltage /= 1024.0; 
+ 
+  // print out the voltage
+  //Serial.print(" - ");
+  Serial.print(average); Serial.print(" raw ");
+ 
+  // now print out the temperature
+  float temperatureC = (voltage - 0.5) * 100 ;  //converting from 10 mv per degree wit 500 mV offset
+                                               //to degrees ((volatge - 500mV) times 100)
+  Serial.print(temperatureC); Serial.println(" degrees C");
+
+  return (int)temperatureC;
+}
+
+int getPot() {
+	int potValue = analogRead(POT);
+	int temp =  map(potValue, 0, 1023, TEMP_MIN, TEMP_MAX);
+	Serial.print("Pot:\t"); Serial.print(potValue); Serial.print(" raw ");
+	Serial.print(temp); Serial.println(" degrees C");
+	return temp;
+}
+
+void loop(){
+	long now = millis();
+	if(now - lastPing > PING_FREQ) {
+    lastPing = now;
+		mydata.cmd = PING;
+		mydata.args = (int)status;
+    Serial.println("PING");
+		ET.sendData();
+	}
+
+	int temp = getTemp();
+	int trashold = getPot();
+	bool mustSend = false;
+	if(status && temp > trashold) {
+		mydata.cmd = SWITCH_OFF;
+		mydata.args = 0;
+    status = false;
+		mustSend = true;
+    Serial.println("SWITCH_OFF");
+	} else if (!status && temp < trashold) {
+		mydata.cmd = SWITCH_ON;
+		mydata.args = 0;
+    status = true;
+		mustSend = true;
+    Serial.println("SWITCH_ON");
+	}
+
+	if(mustSend)
+		ET.sendData();
+
+	digitalWrite(STATUS_LED, status);
+  
+  delay(LOOP_DELAY);
+}

termostato_tx/termostato_tx.ino

-#include <SoftEasyTransfer.h>
-#include <SoftwareSerial.h>
-#include "../termostato/protocol.h"
-
-#define GENERAl_SWITCH 7
-#define POT A5
-#define TEMP A2
-#define RADIO_OUT 2
-#define STATUS_LED 13
-
-// we tie 3.3V to ARef and measure it with a multimeter!
-#define aref_voltage 5.0    
-#define TEMP_MIN 12
-#define TEMP_MAX 33
-
-#define LOOP_DELAY 5000
-#define PING_FREQ 15000
-#define NUMSAMPLES 5
-
-SoftEasyTransfer ET; 
-SoftwareSerial mySerial(3, RADIO_OUT);
-
-
-
-//give a name to the group of data
-HOTSPOT_MSG mydata;
-
-
-long lastPing;
-bool status;
-
-void setup(){  
-  mySerial.begin(9600);
-  ET.begin(details(mydata), &mySerial);
-
-  
-  pinMode(STATUS_LED, OUTPUT);
-  pinMode(GENERAl_SWITCH, INPUT);
-  pinMode(POT, INPUT);
-  pinMode(TEMP, INPUT);
-   
-  Serial.begin(9600);
-  lastPing = 0;
-  status = false;
-  digitalWrite(STATUS_LED, status);
-}
-
-int getTemp() {
-	int samples[NUMSAMPLES]; 
-	uint8_t i; 
- 	float average;
-  // take N samples in a row, with a slight delay
-  for (i=0; i< NUMSAMPLES; i++) {
-    samples[i] = analogRead(TEMP);
-    delay(10);
-  }
-  // average all the samples out
-  average = 0;
-  for (i=0; i< NUMSAMPLES; i++) {
-    average += samples[i];
-  }
-  average /= NUMSAMPLES;
-
-  Serial.print("Temp:\t");
-  //Serial.print(tempReading);     // the raw analog reading
- 
-  // converting that reading to voltage, which is based off the reference voltage
-  float voltage = average * aref_voltage;
-  voltage /= 1024.0; 
- 
-  // print out the voltage
-  //Serial.print(" - ");
-  Serial.print(average); Serial.print(" raw ");
- 
-  // now print out the temperature
-  float temperatureC = (voltage - 0.5) * 100 ;  //converting from 10 mv per degree wit 500 mV offset
-                                               //to degrees ((volatge - 500mV) times 100)
-  Serial.print(temperatureC); Serial.println(" degrees C");
-
-  return (int)temperatureC;
-}
-
-int getPot() {
-	int potValue = analogRead(POT);
-	int temp =  map(potValue, 0, 1023, TEMP_MIN, TEMP_MAX);
-	Serial.print("Pot:\t"); Serial.print(potValue); Serial.print(" raw ");
-	Serial.print(temp); Serial.println(" degrees C");
-	return temp;
-}
-
-void loop(){
-	long now = millis();
-	if(now - lastPing > PING_FREQ) {
-    lastPing = now;
-		mydata.cmd = PING;
-		mydata.args = (int)status;
-    Serial.println("PING");
-		ET.sendData();
-	}
-
-	int temp = getTemp();
-	int trashold = getPot();
-	bool mustSend = false;
-	if(status && temp > trashold) {
-		mydata.cmd = SWITCH_OFF;
-		mydata.args = 0;
-    status = false;
-		mustSend = true;
-    Serial.println("SWITCH_OFF");
-	} else if (!status && temp < trashold) {
-		mydata.cmd = SWITCH_ON;
-		mydata.args = 0;
-    status = true;
-		mustSend = true;
-    Serial.println("SWITCH_ON");
-	}
-
-	if(mustSend)
-		ET.sendData();
-
-	digitalWrite(STATUS_LED, status);
-  
-  delay(LOOP_DELAY);
-}