Ejemplo n.º 1
0
void Device::print(unsigned int num, std::string filename)
{
        print_header(filename);
        print_readings(num, filename);
}
Ejemplo n.º 2
0
int main(void) {
  uint8_t i;
  
  //TODO: Enable watchdog.
  //TODO: Define compile-switch to disable serial output.
  
  // UART init
  uart_init((UART_BAUD_SELECT((BAUD),F_OSC)));
  // USB code init
  //	wdt_enable(WDTO_1S);
  //odDebugInit();
  DDRD = ~(1 << 2);   /* all outputs except PD2 = INT0 */
  PORTD = 0; /* no pullups on USB pins */
  /* We fake an USB disconnect by pulling D+ and D- to 0 during reset. This is
   * necessary if we had a watchdog reset or brownout reset to notify the host
   * that it should re-enumerate the device. Otherwise the host's and device's
   * concept of the device-ID would be out of sync.
   */
  //DDRB = ~USBMASK;    /* set all pins as outputs except USB */
  //computeOutputStatus();  /* set output status before we do the delay */
  usbDeviceDisconnect();  /* enforce re-enumeration, do this while interrupts are disabled! */
  i = 250;
  while(--i){         /* fake USB disconnect for > 500 ms */
	//wdt_reset();
	_delay_ms(2);
  }
  usbDeviceConnect();
  //TCCR0 = 5;          /* set prescaler to 1/1024 */
  usbInit();
  sei();

  // Init DS18X20 Connect LED.
  // Turn LED on: Pull to GND 
  DS18X20_STATUS_LED_DDR |= (1 << DS18X20_STATUS_LED_PIN);  // Output

  // search for the available sensors.
  nSensors = search_sensors();
  // TODO: Use LED to signal errors, i.e. CRC errors.
  if (nSensors == 0)
    DS18X20_STATUS_LED_PORT |= (1 << DS18X20_STATUS_LED_PIN); // Disable
  else
    DS18X20_STATUS_LED_PORT &= ~(1 << DS18X20_STATUS_LED_PIN); // Enable


  // Print debugging header
  logs_P( "\r\nUSBtemp - temperature at your fingertips\r\n" );
  logs_P( "----------------------------------------\r\n" );
  logi((int) nSensors);
  logs_P( " DS18X20 Sensor(s) available:\r\n" );
  for (i=0; i<nSensors; i++) {
    logs_P("# in Bus :");
    logi((int) i+1);
    logs_P(" : ");
#ifdef DEBUG
    DS18X20_show_id_uart( &gSensorIDs[i][0], OW_ROMCODE_SIZE );
#endif
    logs_P( "\r\n" );
  }
  sync_read_sensors();
  print_readings();
  // main loop
  uint32_t delay_counter=0;
  enum read_state_t state=IDLE;
  for(;;) {
    //wdt_reset();
    usbPoll();
    delay_ms(MAIN_DELAY_MS); 
    delay_counter+=MAIN_DELAY_MS;
    // statemachine
    if (state == IDLE && delay_counter > READOUT_INTERVAL_MS) {
      // start measurement.
      async_start_read_sensors();
      delay_counter=0;
      state=MEASURING;
    }
    if (state==MEASURING && delay_counter > READOUT_WAIT_MS) {
      // Read the values from the sensors.
      async_finish_read_sensors();
      delay_counter = 0;
      state=UPDATED;
    }
    if (state==UPDATED) {
      // print temperature on uart.
      print_readings();
      delay_counter = 0;
      state=IDLE;
    }
  }
}