// Self_test function
void OpenSprinkler::self_test(unsigned long ms) {
	byte sid;
	while(1) {
		for(sid=0; sid<nstations; sid++) {
			lcd.clear();
			lcd.setCursor(0, 0);
			lcd.print((int)sid+1);
			clear_all_station_bits();
			set_station_bit(sid, 1);
			apply_all_station_bits();
			// run each station for designated amount of time
			delay(ms);	
		}
	}
}
示例#2
0
// Self_test function
void OpenSprinkler::self_test() {
	byte sid;
	while(1) {
		for(sid=0; sid<nstations; sid++) {
			lcd.clear();
			lcd.setCursor(0, 0);
			lcd.print((int)sid+1);
			clear_all_station_bits();
			set_station_bit(sid, 1);
			apply_all_station_bits();
			// run each station for designated amount of time
			delay((unsigned long)options[OPTION_SELFTEST_TIME].value*1000);
      //delay(3000);  // 3 seconds delay between every two stations			
		}
	}
}
// OpenSprinkler init function
void OpenSprinkler::begin() {

  // shift register setup
  pinMode(PIN_SR_LATCH, OUTPUT);
  pinMode(PIN_SR_OE, OUTPUT);
  pinMode(PIN_SR_CLOCK, OUTPUT);
  pinMode(PIN_SR_DATA,  OUTPUT);
  
  digitalWrite(PIN_SR_LATCH, HIGH);
  // pull shift register OE high to disable output
  digitalWrite(PIN_SR_OE, HIGH);
 
	// Reset all stations
  clear_all_station_bits();
  apply_all_station_bits();
  
  // pull shift register OE low to enable output
  digitalWrite(PIN_SR_OE, LOW);

  // set sd cs pin high
  pinMode(PIN_SD_CS, OUTPUT);
  digitalWrite(PIN_SD_CS, HIGH);
  
#ifdef USE_TINYFAT
  file.setSSpin(PIN_SD_CS);
#endif
  
  // set PWM frequency for LCD
  TCCR1B = 0x01;
  // turn on LCD backlight and contrast
  pinMode(PIN_LCD_BACKLIGHT, OUTPUT);
  pinMode(PIN_LCD_CONTRAST, OUTPUT);
  analogWrite(PIN_LCD_CONTRAST, options[OPTION_LCD_CONTRAST].value);
  analogWrite(PIN_LCD_BACKLIGHT, 255-options[OPTION_LCD_BACKLIGHT].value); 

  // begin lcd
  lcd.begin(16, 2);
   
  // Rain sensor port set up
  pinMode(PIN_RAINSENSOR, INPUT);
  digitalWrite(PIN_RAINSENSOR, HIGH); // enabled internal pullup

  // Init I2C
  Wire.begin();
  
  // Reset status variables
  status.enabled = 1;
  status.rain_delayed = 0;
  status.rain_sensed = 0;
  status.program_busy = 0;
  status.manual_mode = 0;
  status.has_rtc = 0;
  status.has_sd = 0;
  status.display_board = 0;
  status.network_fails = 0;

  nboards = 1;
  nstations = 8;
  raindelay_stop_time = 0;
  
  // define lcd custom characters
  byte lcd_wifi_char[8] = {
    B00000,
    B10100,
    B01000,
    B10101,
    B00001,
    B00101,
    B00101,
    B10101
  };
  byte lcd_sd_char[8] = {
    B00000,
    B00000,
    B11111,
    B10001,
    B11111,
    B10001,
    B10011,
    B11110
  };
  lcd.createChar(1, lcd_wifi_char);  
  lcd_wifi_char[1]=0;
  lcd_wifi_char[2]=0;
  lcd_wifi_char[3]=1;    
  lcd.createChar(0, lcd_wifi_char);  
  lcd.createChar(2, lcd_sd_char);

  // set rf data pin
  pinMode(PIN_RF_DATA, OUTPUT);
  digitalWrite(PIN_RF_DATA, LOW);
  
  // set button pins
  // enable internal pullup
  pinMode(PIN_BUTTON_1, INPUT);
  pinMode(PIN_BUTTON_2, INPUT);
  pinMode(PIN_BUTTON_3, INPUT);    
  digitalWrite(PIN_BUTTON_1, HIGH);
  digitalWrite(PIN_BUTTON_2, HIGH);
  digitalWrite(PIN_BUTTON_3, HIGH);    
  
  // detect if DS1307 RTC exists
  if (RTC.testerr()==0) {
    status.has_rtc = 1;
  }
}
示例#4
0
// OpenSprinkler init function
void OpenSprinkler::begin() {

  // shift register setup
  pinMode(PIN_SR_LATCH, OUTPUT);
  
#ifdef PIN_SR_OE  
  // shift register output enable
  pinMode(PIN_SR_OE, OUTPUT);
#endif
  pinMode(PIN_SR_CLOCK, OUTPUT);
  pinMode(PIN_SR_DATA,  OUTPUT);
  
  digitalWrite(PIN_SR_LATCH, HIGH);

#ifdef PIN_SR_OE
  // pull shift register OE high to disable output
  digitalWrite(PIN_SR_OE, HIGH);
#endif
 
	// Reset all stations
  clear_all_station_bits();
  apply_all_station_bits();
  
#ifdef PIN_SR_OE  
  // pull shift register OE low to enable output
  digitalWrite(PIN_SR_OE, LOW);
#endif
 
#ifdef PIN_RAINSENSOR  
  // Rain sensor port set up
  pinMode(PIN_RAINSENSOR, INPUT);
  digitalWrite(PIN_RAINSENSOR, HIGH); // enabled internal pullup
#endif
  
  // Init I2C
  Wire.begin();
  
  // Reset status variables
	status.enabled = 1;
	status.rain_delayed = 0;
	status.rain_sensed = 0;
	status.program_busy = 0;
	status.manual_mode = 0;
	status.has_rtc = 0;
	status.display_board = 0;
	status.network_fails = 0;

  nboards = 1;
  nstations = 8;
  raindelay_stop_time = 0;
  
  // define lcd custom characters
  byte lcd_custom_char[8] = {
    B00000,
    B10100,
    B01000,
    B10101,
    B00001,
    B00101,
    B00101,
    B10101
  };
  lcd.createChar(1, lcd_custom_char);  
  lcd_custom_char[1]=0;
  lcd_custom_char[2]=0;
  lcd_custom_char[3]=1;    
  lcd.createChar(0, lcd_custom_char);  
  // begin lcd
  lcd.begin(16, 2);
  
  // detect if DS1307 RTC exists
  if (RTC.testerr()==0) {
    status.has_rtc = 1;
  }
}
// OpenSprinkler init function
void OpenSprinkler::begin() {

  // shift register setup
  pinMode(PIN_SR_OE, OUTPUT);
  // pull shift register OE high to disable output
  digitalWrite(PIN_SR_OE, HIGH);
  pinMode(PIN_SR_LATCH, OUTPUT);
  digitalWrite(PIN_SR_LATCH, HIGH);

  pinMode(PIN_SR_CLOCK, OUTPUT);
  pinMode(PIN_SR_DATA,  OUTPUT);
  
	// Reset all stations
  clear_all_station_bits();
  apply_all_station_bits();
  
  // pull shift register OE low to enable output
  digitalWrite(PIN_SR_OE, LOW);

  // set sd cs pin high to release SD
  pinMode(PIN_SD_CS, OUTPUT);
  digitalWrite(PIN_SD_CS, HIGH);
  
  // set PWM frequency for adjustable LCD backlight and contrast 
  TCCR1B = 0x01;
  // turn on LCD backlight and contrast
  pinMode(PIN_LCD_BACKLIGHT, OUTPUT);
  pinMode(PIN_LCD_CONTRAST, OUTPUT);
  analogWrite(PIN_LCD_CONTRAST, options[OPTION_LCD_CONTRAST].value);
  analogWrite(PIN_LCD_BACKLIGHT, 255-options[OPTION_LCD_BACKLIGHT].value); 

  // turn on lcd
  lcd.init(1, PIN_LCD_RS, 255, PIN_LCD_EN, PIN_LCD_D4, PIN_LCD_D5, PIN_LCD_D6, PIN_LCD_D7, 0,0,0,0);
  lcd.begin(16, 2);
   
  // Rain sensor port set up
  pinMode(PIN_RAINSENSOR, INPUT);
  digitalWrite(PIN_RAINSENSOR, HIGH); // enabled internal pullup

  // Init I2C
  Wire.begin();
  
  // Default controller status variables
  // AVR assigns 0 to static variables by default
  // so only need to initialize non-zero ones
  status.enabled = 1;
  status.seq = 1;
  
  old_status = status;
  
  nvdata.sunrise_time = 360;  // 6:00am default
  nvdata.sunset_time = 1080;  // 6:00pm default
  
  nboards = 1;
  nstations = 8;
  
  // define lcd custom icons
  byte lcd_wifi_char[8] = {
    B00000,
    B10100,
    B01000,
    B10101,
    B00001,
    B00101,
    B00101,
    B10101
  };
  byte lcd_sd_char[8] = {
    B00000,
    B00000,
    B11111,
    B10001,
    B11111,
    B10001,
    B10011,
    B11110
  };
  byte lcd_rain_char[8] = {
    B00000,
    B00000,
    B00110,
    B01001,
    B11111,
    B00000,
    B10101,
    B10101
  };  
  byte lcd_connect_char[8] = {
    B00000,
    B00000,
    B00111,
    B00011,
    B00101,
    B01000,
    B10000,
    B00000
  };
  lcd.createChar(1, lcd_wifi_char);  
  lcd_wifi_char[1]=0;
  lcd_wifi_char[2]=0;
  lcd_wifi_char[3]=1;    
  lcd.createChar(0, lcd_wifi_char);  
  lcd.createChar(2, lcd_sd_char);
  lcd.createChar(3, lcd_rain_char);
  lcd.createChar(4, lcd_connect_char);
  
  // set rf data pin
  pinMode(PIN_RF_DATA, OUTPUT);
  digitalWrite(PIN_RF_DATA, LOW);
  
  pinMode(PIN_RELAY, OUTPUT);
  digitalWrite(PIN_RELAY, LOW);
  
  // set button pins
  // enable internal pullup
  pinMode(PIN_BUTTON_1, INPUT);
  pinMode(PIN_BUTTON_2, INPUT);
  pinMode(PIN_BUTTON_3, INPUT);    
  digitalWrite(PIN_BUTTON_1, HIGH);
  digitalWrite(PIN_BUTTON_2, HIGH);
  digitalWrite(PIN_BUTTON_3, HIGH);    
  
  // detect if DS1307 RTC exists
  if (RTC.detect()==0) {
    status.has_rtc = 1;
  }
}
void OpenSprinkler::begin() {

  // shift register setup
  pinMode(PIN_SR_OE, OUTPUT);
  // pull shift register OE high to disable output
  digitalWrite(PIN_SR_OE, HIGH);
  pinMode(PIN_SR_LATCH, OUTPUT);
  digitalWrite(PIN_SR_LATCH, HIGH);

  pinMode(PIN_SR_CLOCK, OUTPUT);
  
#if defined(OSPI)
  pin_sr_data = PIN_SR_DATA;
  // detect RPi revision
  unsigned int rev = detect_rpi_rev();
  if (rev==0x0002 || rev==0x0003) 
    pin_sr_data = PIN_SR_DATA_ALT;
  // if this is revision 1, use PIN_SR_DATA_ALT
  pinMode(pin_sr_data, OUTPUT);
#else
  pinMode(PIN_SR_DATA,  OUTPUT);
#endif

	// Reset all stations
  clear_all_station_bits();
  apply_all_station_bits();

  // pull shift register OE low to enable output
  digitalWrite(PIN_SR_OE, LOW);

  // Rain sensor port set up
  pinMode(PIN_RAINSENSOR, INPUT);

#if defined(ARDUINO)
  digitalWrite(PIN_RAINSENSOR, HIGH); // enabled internal pullup on rain sensor
#else
  // RPI and BBB have external pullups
#endif

  // Default controller status variables
  // AVR assigns 0 to static variables by default
  // so only need to initialize non-zero ones
  status.enabled = 1;
  status.safe_reboot = 0;
  
  old_status = status;

  nvdata.sunrise_time = 360;  // 6:00am default sunrise
  nvdata.sunset_time = 1080;  // 6:00pm default sunset

  nboards = 1;
  nstations = 8;

  // set rf data pin
  pinMode(PIN_RF_DATA, OUTPUT);
  digitalWrite(PIN_RF_DATA, LOW);

  /*pinMode(PIN_RELAY, OUTPUT);
  digitalWrite(PIN_RELAY, LOW);*/

  hw_type = HW_TYPE_AC;
#if defined(ARDUINO)  // AVR SD and LCD functions
  // Init I2C
  Wire.begin();

  #if defined(__AVR_ATmega1284P__) || defined(__AVR_ATmega1284__) // OS 2.3 specific detections
    uint8_t ret;

    // detect hardware type
    Wire.beginTransmission(MAC_CTRL_ID);
    Wire.write(0x00);
  	ret = Wire.endTransmission();
  	if (!ret) {
    	Wire.requestFrom(MAC_CTRL_ID, 1);
    	while(!Wire.available());
    	ret = Wire.read();
      if (ret == HW_TYPE_AC || ret == HW_TYPE_DC || ret == HW_TYPE_LATCH) {
        hw_type = ret;
      } else {
        // hardware type is not assigned
      }
    }
    
    if (hw_type == HW_TYPE_DC) {
      pinMode(PIN_BOOST, OUTPUT);
      digitalWrite(PIN_BOOST, LOW);

      pinMode(PIN_BOOST_EN, OUTPUT);
      digitalWrite(PIN_BOOST_EN, LOW);        
    }
  #endif

  lcd_start();

  // define lcd custom icons
  byte _icon[8];
  // WiFi icon
  _icon[0] = B00000;
  _icon[1] = B10100;
  _icon[2] = B01000;
  _icon[3] = B10101;
  _icon[4] = B00001;
  _icon[5] = B00101;
  _icon[6] = B00101;
  _icon[7] = B10101;
  lcd.createChar(1, _icon);
  
  _icon[1]=0;
  _icon[2]=0;
  _icon[3]=1;
  lcd.createChar(0, _icon);
  
  // uSD card icon
  _icon[0] = B00000;
  _icon[1] = B00000;
  _icon[2] = B11111;
  _icon[3] = B10001;
  _icon[4] = B11111;
  _icon[5] = B10001;
  _icon[6] = B10011;
  _icon[7] = B11110;
  lcd.createChar(2, _icon);  
  
  // Rain icon
  _icon[0] = B00000;
  _icon[1] = B00000;
  _icon[2] = B00110;
  _icon[3] = B01001;
  _icon[4] = B11111;
  _icon[5] = B00000;
  _icon[6] = B10101;
  _icon[7] = B10101;
  lcd.createChar(3, _icon);
  
  // Connect icon
  _icon[0] = B00000;
  _icon[1] = B00000;
  _icon[2] = B00111;
  _icon[3] = B00011;
  _icon[4] = B00101;
  _icon[5] = B01000;
  _icon[6] = B10000;
  _icon[7] = B00000;
  lcd.createChar(4, _icon);

  // set sd cs pin high to release SD
  pinMode(PIN_SD_CS, OUTPUT);
  digitalWrite(PIN_SD_CS, HIGH);

  if(sd.begin(PIN_SD_CS, SPI_HALF_SPEED)) {
    status.has_sd = 1;
  }

  // set button pins
  // enable internal pullup
  pinMode(PIN_BUTTON_1, INPUT);
  pinMode(PIN_BUTTON_2, INPUT);
  pinMode(PIN_BUTTON_3, INPUT);
  digitalWrite(PIN_BUTTON_1, HIGH);
  digitalWrite(PIN_BUTTON_2, HIGH);
  digitalWrite(PIN_BUTTON_3, HIGH);

  // detect if DS1307 RTC exists
  if (RTC.detect()==0) {
    status.has_rtc = 1;
  }
#endif
}