Permalink
Browse files

Update Readme.txt

  • Loading branch information...
1 parent 39e8489 commit cd455dedbdbc722ad97e8f4723789c125807c9de @rayshobby committed May 17, 2012
@@ -5,9 +5,6 @@
Mar 2012 @ Rayshobby.net
*/
-#include <WProgram.h>
-#include <avr/eeprom.h>
-
#include "OpenSprinkler.h"
// define class data members
@@ -72,7 +69,7 @@ prog_uchar OpenSprinkler::options_max[NUM_OPTIONS] PROGMEM = {
// Display string of each option
prog_char _str_fwv [] PROGMEM = "FW";
prog_char _str_tz [] PROGMEM = "Time zone:";
-prog_char _str_dhcp[] PROGMEM = "Enable DHCP: ";
+prog_char _str_dhcp[] PROGMEM = "Use DHCP: ";
prog_char _str_ip1 [] PROGMEM = "Static.ip1: ";
prog_char _str_ip2 [] PROGMEM = "Static.ip2: ";
prog_char _str_ip3 [] PROGMEM = "Static.ip3: ";
@@ -88,7 +85,7 @@ prog_char _str_ms [] PROGMEM = "Multi station:";
prog_char _str_ext [] PROGMEM = "Ext. Boards: ";
prog_char _str_rn [] PROGMEM = "Require net: ";
prog_char _str_ma [] PROGMEM = "Master stn:";
-prog_char _str_rs [] PROGMEM = "Use rainsensor:";
+prog_char _str_rs [] PROGMEM = "Rain sensor:";
prog_char _str_reset[] PROGMEM = "Reset all? ";
char* OpenSprinkler::options_str[NUM_OPTIONS] = {
@@ -166,9 +163,14 @@ void(* resetFunc) (void) = 0;
// Reset ethernet controller
void OpenSprinkler::reset_ethernet() {
+#if SVC_HW_VERSION == 12
+
+#else
+ pinMode(PIN_ETHER_RESET, OUTPUT);
digitalWrite(PIN_ETHER_RESET, LOW);
delay(50);
digitalWrite(PIN_ETHER_RESET, HIGH);
+#endif
}
// Reboot controller
@@ -184,7 +186,6 @@ void OpenSprinkler::begin() {
digitalWrite(PIN_SR_LATCH, HIGH);
pinMode(PIN_SR_CLOCK, OUTPUT);
pinMode(PIN_SR_DATA, OUTPUT);
- pinMode(PIN_ETHER_RESET, OUTPUT);
// Reset all stations
station_reset();
@@ -405,7 +406,7 @@ boolean OpenSprinkler::multistation_check() {
void OpenSprinkler::lcd_print_pgm(PGM_P PROGMEM str) {
uint8_t c;
while((c=pgm_read_byte(str++))!= '\0') {
- lcd.print(c);
+ lcd.print((char)c);
}
}
@@ -415,7 +416,7 @@ void OpenSprinkler::lcd_print_line_clear_pgm(PGM_P PROGMEM str, byte line) {
uint8_t c;
int8_t cnt = 0;
while((c=pgm_read_byte(str++))!= '\0') {
- lcd.print(c);
+ lcd.print((char)c);
cnt++;
}
for(; (16-cnt) >= 0; cnt ++) lcd.print(' ');
@@ -500,7 +501,7 @@ byte OpenSprinkler::lcd_print_station(byte line, char c)
else {
byte bitvalue = station_bitvalues[lcd_display_board];
for (byte i=0; i<8; i++) {
- lcd.print((bitvalue&1) ? c : '_');
+ lcd.print((bitvalue&1) ? (char)c : '_');
bitvalue >>= 1;
}
}
@@ -583,7 +584,7 @@ byte OpenSprinkler::button_read(byte waitmode)
int read_value = analogRead(PIN_READ_BUTTON);
delay(BUTTON_DELAY_MS);
-#ifdef SVC_HW_VERSION_12
+#if SVC_HW_VERSION == 12
if (read_value > 450) {
curr = button_read_busy(450, waitmode, BUTTON_1, is_holding);
}
@@ -881,45 +882,45 @@ void OpenSprinkler::ext_eeprom_clear(unsigned int start, unsigned int end)
void OpenSprinkler::ext_eeprom_write_byte(unsigned int eeaddress, byte data) {
int rdata = data;
Wire.beginTransmission(I2C_EEPROM_DEVICE_ADDR);
- Wire.send((int)(eeaddress >> 8)); // MSB
- Wire.send((int)(eeaddress & 0xFF)); // LSB
- Wire.send(rdata);
+ Wire.write((int)(eeaddress >> 8)); // MSB
+ Wire.write((int)(eeaddress & 0xFF)); // LSB
+ Wire.write(rdata);
Wire.endTransmission();
}
// WARNING: address is a page address, 6-bit end will wrap around
// also, data can be maximum of about 30 bytes, because the Wire library has a buffer of 32 bytes
void OpenSprinkler::ext_eeprom_write_buffer(unsigned int eeaddresspage, byte* buffer, byte length) {
Wire.beginTransmission(I2C_EEPROM_DEVICE_ADDR);
- Wire.send((int)(eeaddresspage >> 8)); // MSB
- Wire.send((int)(eeaddresspage & 0xFF)); // LSB
+ Wire.write((int)(eeaddresspage >> 8)); // MSB
+ Wire.write((int)(eeaddresspage & 0xFF)); // LSB
byte c;
for ( c = 0; c < length; c++)
- Wire.send(buffer[c]);
+ Wire.write(buffer[c]);
Wire.endTransmission();
delay(10);
}
byte OpenSprinkler::ext_eeprom_read_byte(unsigned int eeaddress) {
byte rdata = 0xFF;
Wire.beginTransmission(I2C_EEPROM_DEVICE_ADDR);
- Wire.send((int)(eeaddress >> 8)); // MSB
- Wire.send((int)(eeaddress & 0xFF)); // LSB
+ Wire.write((int)(eeaddress >> 8)); // MSB
+ Wire.write((int)(eeaddress & 0xFF)); // LSB
Wire.endTransmission();
Wire.requestFrom(I2C_EEPROM_DEVICE_ADDR,1);
- if (Wire.available()) rdata = Wire.receive();
+ if (Wire.available()) rdata = Wire.read();
return rdata;
}
// maybe let's not read more than 30 or 32 bytes at a time!
void OpenSprinkler::ext_eeprom_read_buffer(unsigned int eeaddress, byte *buffer, int length) {
Wire.beginTransmission(I2C_EEPROM_DEVICE_ADDR);
- Wire.send((int)(eeaddress >> 8)); // MSB
- Wire.send((int)(eeaddress & 0xFF)); // LSB
+ Wire.write((int)(eeaddress >> 8)); // MSB
+ Wire.write((int)(eeaddress & 0xFF)); // LSB
Wire.endTransmission();
Wire.requestFrom(I2C_EEPROM_DEVICE_ADDR,length);
int c = 0;
for ( c = 0; c < length; c++ )
- if (Wire.available()) buffer[c] = Wire.receive();
+ if (Wire.available()) buffer[c] = Wire.read();
}
@@ -8,6 +8,8 @@
#ifndef _OpenSprinkler_h
#define _OpenSprinkler_h
+#include <WProgram.h>
+#include <avr/eeprom.h>
#include "Wire.h"
#include "EEPROM.h"
#include "Time.h"
@@ -124,7 +124,7 @@ uint8_t TwoWire::endTransmission(void)
// must be called in:
// slave tx event callback
// or after beginTransmission(address)
-void TwoWire::send(uint8_t data)
+void TwoWire::write(uint8_t data)
{
if(transmitting){
// in master transmitter mode
@@ -147,12 +147,12 @@ void TwoWire::send(uint8_t data)
// must be called in:
// slave tx event callback
// or after beginTransmission(address)
-void TwoWire::send(uint8_t* data, uint8_t quantity)
+void TwoWire::write(const uint8_t *data, size_t quantity)
{
if(transmitting){
// in master transmitter mode
- for(uint8_t i = 0; i < quantity; ++i){
- send(data[i]);
+ for(size_t i = 0; i < quantity; ++i){
+ write(data[i]);
}
}else{
// in slave send mode
@@ -162,47 +162,48 @@ void TwoWire::send(uint8_t* data, uint8_t quantity)
}
// must be called in:
-// slave tx event callback
-// or after beginTransmission(address)
-void TwoWire::send(char* data)
-{
- send((uint8_t*)data, strlen(data));
-}
-
-// must be called in:
-// slave tx event callback
-// or after beginTransmission(address)
-void TwoWire::send(int data)
+// slave rx event callback
+// or after requestFrom(address, numBytes)
+int TwoWire::available(void)
{
- send((uint8_t)data);
+ return rxBufferLength - rxBufferIndex;
}
// must be called in:
// slave rx event callback
// or after requestFrom(address, numBytes)
-uint8_t TwoWire::available(void)
+int TwoWire::read(void)
{
- return rxBufferLength - rxBufferIndex;
+ int value = -1;
+
+ // get each successive byte on each call
+ if(rxBufferIndex < rxBufferLength){
+ value = rxBuffer[rxBufferIndex];
+ ++rxBufferIndex;
+ }
+
+ return value;
}
// must be called in:
// slave rx event callback
// or after requestFrom(address, numBytes)
-uint8_t TwoWire::receive(void)
+int TwoWire::peek(void)
{
- // default to returning null char
- // for people using with char strings
- uint8_t value = '\0';
+ int value = -1;
- // get each successive byte on each call
if(rxBufferIndex < rxBufferLength){
value = rxBuffer[rxBufferIndex];
- ++rxBufferIndex;
}
return value;
}
+void TwoWire::flush(void)
+{
+ // XXX: to be implemented.
+}
+
// behind the scenes function that is called when data is received
void TwoWire::onReceiveService(uint8_t* inBytes, int numBytes)
{
@@ -21,10 +21,11 @@
#define TwoWire_h
#include <inttypes.h>
+#include "Stream.h"
#define BUFFER_LENGTH 32
-class TwoWire
+class TwoWire : public Stream
{
private:
static uint8_t rxBuffer[];
@@ -51,14 +52,16 @@ class TwoWire
uint8_t endTransmission(void);
uint8_t requestFrom(uint8_t, uint8_t);
uint8_t requestFrom(int, int);
- void send(uint8_t);
- void send(uint8_t*, uint8_t);
- void send(int);
- void send(char*);
- uint8_t available(void);
- uint8_t receive(void);
+ virtual void write(uint8_t);
+ virtual void write(const uint8_t *, size_t);
+ virtual int available(void);
+ virtual int read(void);
+ virtual int peek(void);
+ virtual void flush(void);
void onReceive( void (*)(int) );
void onRequest( void (*)(void) );
+
+ using Print::write;
};
extern TwoWire Wire;
@@ -9,10 +9,10 @@
#define _Defines_h
// Firmware version
-#define SVC_FW_VERSION 14
+#define SVC_FW_VERSION 15
// ====== Hardware Defines ======
-#define MAX_EXT_BOARDS 7 // maximum number of ext. boards (each ext. board contains 8 stations), hence total number of stations: (1+MAX_EXT_BOARDS) * 8
+#define MAX_EXT_BOARDS 3 // maximum number of ext. boards (each ext. board contains 8 stations), hence total number of stations: (1+MAX_EXT_BOARDS) * 8
// External I2C EEPROM
#define I2C_EEPROM_DEVICE_ADDR 0x50
@@ -56,15 +56,19 @@ typedef enum {
#define OPFLAG_WEB_EDIT 0x02 // the option is editable through the web
#define OPFLAG_BOOL 0x10 // the option takes bool values
-
#define SC_RAINDELAY_MAX 144 // maximum number of rain delay hours
// ====== Arduino Pin Assignments ======
-// Different hardware versions may defined pins differently
+// Define hardware version here
+
+#define SVC_HW_VERSION 12
+//#define SVC_HW_VERSION 11
-//#define SVC_HW_VERSION_12
+#ifndef SVC_HW_VERSION
+#error "You must define SVC_HW_VERSION in libraries/OpenSprnikler/defines.h"
+#endif
-#ifdef SVC_HW_VERSION_12
+#if SVC_HW_VERSION == 12
#define PIN_READ_BUTTON 0 // analog pin assigned for button reading
#define PIN_SR_LATCH 7 // shift register latch pin
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -23,6 +23,7 @@
#include <avr/io.h>
#include <avr/interrupt.h>
#include <compat/twi.h>
+#include <WProgram.h> // for digitalWrite
#ifndef cbi
#define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))
@@ -32,6 +33,7 @@
#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))
#endif
+#include "pins_arduino.h"
#include "twi.h"
static volatile uint8_t twi_state;
@@ -63,23 +65,15 @@ void twi_init(void)
{
// initialize state
twi_state = TWI_READY;
-
- #if defined(__AVR_ATmega168__) || defined(__AVR_ATmega8__) || defined(__AVR_ATmega328P__)
- // activate internal pull-ups for twi
- // as per note from atmega8 manual pg167
- sbi(PORTC, 4);
- sbi(PORTC, 5);
- #else
- // activate internal pull-ups for twi
- // as per note from atmega128 manual pg204
- sbi(PORTD, 0);
- sbi(PORTD, 1);
- #endif
+
+ // activate internal pullups for twi.
+ digitalWrite(18, 1);
+ digitalWrite(19, 1);
// initialize twi prescaler and bit rate
cbi(TWSR, TWPS0);
cbi(TWSR, TWPS1);
- TWBR = ((CPU_FREQ / TWI_FREQ) - 16) / 2;
+ TWBR = ((F_CPU / TWI_FREQ) - 16) / 2;
/* twi bit rate formula from atmega128 manual pg 204
SCL Frequency = CPU Clock Frequency / (16 + (2 * TWBR))
@@ -232,7 +226,7 @@ uint8_t twi_writeTo(uint8_t address, uint8_t* data, uint8_t length, uint8_t wait
* 2 not slave transmitter
* 0 ok
*/
-uint8_t twi_transmit(uint8_t* data, uint8_t length)
+uint8_t twi_transmit(const uint8_t* data, uint8_t length)
{
uint8_t i;
@@ -24,10 +24,6 @@
//#define ATMEGA8
- #ifndef CPU_FREQ
- #define CPU_FREQ 16000000L
- #endif
-
#ifndef TWI_FREQ
#define TWI_FREQ 100000L
#endif
@@ -46,7 +42,7 @@
void twi_setAddress(uint8_t);
uint8_t twi_readFrom(uint8_t, uint8_t*, uint8_t);
uint8_t twi_writeTo(uint8_t, uint8_t*, uint8_t, uint8_t);
- uint8_t twi_transmit(uint8_t*, uint8_t);
+ uint8_t twi_transmit(const uint8_t*, uint8_t);
void twi_attachSlaveRxEvent( void (*)(uint8_t*, int) );
void twi_attachSlaveTxEvent( void (*)(void) );
void twi_reply(uint8_t);

0 comments on commit cd455de

Please sign in to comment.