Ejemplo n.º 1
0
// format and display eeprom data on lcd
void show_eeprom_data(EEPROM_DATA *data){
    lcd_line_three();
    fprintf_P(&lcd_stream, PSTR("%1d %s %04X %02X %4.2f"), 
        data->need_initalization,
        data->author,
        data->read_count,
        data->brightness,
        data->version       
        ); 
}
Ejemplo n.º 2
0
void getTemp() {
	uint16_t last_sample = 0;
	double this_temp;
	double temp_avg;
	uint16_t i;
	temp_avg = 0.0;

	for (i=0; i<500; i++) {
		last_sample = adc_read();
		this_temp = sampleToFahrenheit(last_sample);
		temp_avg = temp_avg + this_temp/500.0;
	}

	double c = fahrenheitToCelsius(temp_avg);
	double k = celsiusToKelvin(c);

	// write message to LCD
	lcd_init();
	FILE lcd_stream = FDEV_SETUP_STREAM(lcd_putchar, 0, _FDEV_SETUP_WRITE);
	lcd_home();
	lcd_write_string(PSTR("ADC: "));
	lcd_write_int16(last_sample);
	lcd_write_string(PSTR(" of 1024 "));
	lcd_line_two();

	fprintf_P(&lcd_stream, PSTR("%.2f"), temp_avg);
	lcd_write_data(0xdf);
	lcd_write_string(PSTR("F"));

	lcd_line_three();
	fprintf_P(&lcd_stream, PSTR("%.2f"), c);
	lcd_write_data(0xdf);
	lcd_write_string(PSTR("C"));

	lcd_line_four();
	fprintf_P(&lcd_stream, PSTR("%.2f"), k);
	lcd_write_data(0xdf);
	lcd_write_string(PSTR("K"));
}
Ejemplo n.º 3
0
void poll(){
  // Main polling loop
  
  // Check for a character from the USART
  // See if there is a command comming in
  if (uart_char_is_waiting()) {
    char c = uart_read();
    
    // Update the command state-machine
    if (c == '\n' || c == '\r' ) {
      // End of a command, process it and reset the command string
      if (current_command == COMMAND_NONE) {
      } else if (current_command == COMMAND_INFLATE) {
	syringe_inflate();
	current_state = STATE_INFLATE;
      } else if (current_command == COMMAND_DEFLATE) {
	syringe_deflate();
	current_state = STATE_DEFLATE;
      } else if (current_command == COMMAND_SET_PRESSURE) {
	int ret = sscanf_P(value_str, PSTR("%d"), &target_pressure);
	//	printf_P(PSTR("1 = %d\r\n"), ret );  
	//	printf_P(PSTR("2 = %d\r\n"), target_pressure );
      }
      value_str_i = 0;
      current_command = COMMAND_NONE;
      current_command_state = CMD_STATE_COMMAND;
    } else {
      // In a command string
      if (current_command_state == CMD_STATE_COMMAND) {
	// Command character
	if (c == 'i') {
	  // Inflate
	  current_command = COMMAND_INFLATE;
	} else if (c == 'd') {
	  // Deflate
	  current_command = COMMAND_DEFLATE;
	} else if (c == 'p') {
	  // Set pressure point
	  current_command = COMMAND_SET_PRESSURE;
	} else {
	  current_command = COMMAND_NONE;
	}
	current_command_state = CMD_STATE_EQUAL;
      } else if (current_command_state == CMD_STATE_EQUAL) {
	// Assume the second char is always '='
	current_command_state = CMD_STATE_VALUE;
      } else if (current_command_state == CMD_STATE_VALUE) {
	// In value part of command
	value_str[value_str_i++] = c;
	if (value_str_i >= MAX_VALUE_LENGTH) {
	  value_str_i = MAX_VALUE_LENGTH-1;
	}
	value_str[value_str_i] = 0; // Write NULL terminator
      }
    }
  }
  
  // Check the current pressure
  // take 100 samples and average them!
  // holder variables for temperature data
  uint16_t last_sample = 0;
  double this_temp;
  double pres_avg = 0.0;
  uint8_t i;
  
  for(i=0; i<100; i++) {
    last_sample = adc_read();
    //this_temp = sampleTokPi(last_sample);
    this_temp = last_sample;
    
    // add this contribution to the average
    pres_avg = pres_avg + this_temp/100.0;
  }

  // Check to see if we hit the target presure
  if ( current_state == STATE_INFLATE ) {
    if ( pres_avg >= target_pressure ) {
      // Stop Inflating
      syringe_off();
      current_state = STATE_IDLE;
    }
  } else if ( current_state == STATE_DEFLATE ) {
    if ( pres_avg <= target_pressure ) {
      // Stop Deflating
      syringe_off();
      current_state = STATE_IDLE;      
    }
  }   

  // write message to LCD
  lcd_home();
  lcd_write_string(PSTR("ADC: "));
  lcd_write_int16(last_sample);
  lcd_write_string(PSTR(" of 1024   "));
  lcd_line_two();
  if ( current_state == STATE_IDLE ) {
    fprintf_P(&lcd_stream, PSTR("State: Idle      "));
  } else if ( current_state == STATE_RECV ) {
    fprintf_P(&lcd_stream, PSTR("State: Recv      "));
  } else if ( current_state == STATE_INFLATE ) {
    fprintf_P(&lcd_stream, PSTR("State: Inflate   "));
  } else if ( current_state == STATE_DEFLATE ) {
    fprintf_P(&lcd_stream, PSTR("State: Deflate   "));
  }
  lcd_line_three();
  fprintf_P(&lcd_stream, PSTR("Target Pres: %d"), target_pressure );
  // write message to serial port
  //printf_P(PSTR("%.2f degrees F\r\n"), temp_avg);
  //printf_P(PSTR("Pres = %d\r\n"), target_pressure );
  //printf_P(PSTR("Value = %s\r\n"), value_str );

}