Пример #1
0
int ds18x_init()
{
	ow_init();
	if(ds18x_read_serial(ds18x_id) < 0)
		return -1;

	return ds18x_read_temp(ds18x_id, NULL);
}
Пример #2
0
struct owctx * ow_new_ex(struct xl_io_handler io_handler, char *filename)
{
  struct owctx *ow;

  ow = malloc(sizeof(struct owctx));

  if (ow_init(ow, io_handler, filename) == -1) {
    free(ow);
    return NULL;
  }

  return ow;
}
Пример #3
0
int main(int argc, char *argv[]) {
  if (argc != 2) {
    puts("Path to COM port required.\n");
    return 1;
  }
  if (ow_init(argv[1])) {
    puts("Bus INIT failed. Check COM port.\n");
    return 1;
  }

  uint8_t c = 0, diff = OW_SEARCH_FIRST;
  int16_t temp_dc;

  while (diff != OW_LAST_DEVICE) {
    DS18X20_find_sensor(&diff, id);
    if (diff == OW_ERR_PRESENCE) {
      puts("All sensors are offline now.\n");
      ow_finit();
      return 1;
    }
    if (diff == OW_ERR_DATA) {
      puts("Bus error.\n");
      ow_finit();
      return 1;
    }
    fprintf(stdout, "Bus %s Device %03u Type 0x%02hx (%s) ID %02hx%02hx%02hx%02hx%02hx%02hx CRC 0x%02hx ", \
           argv[1], c, id[0], get_type_by_id(id[0]), id[6], id[5], id[4], id[3], id[2], id[1], id[7]);
    fflush(stdout);
    c ++;

    if (DS18X20_start_meas(DS18X20_POWER_EXTERN, NULL) == DS18X20_OK) {
      while (DS18X20_conversion_in_progress() == DS18X20_CONVERTING) {
        delay_ms(100); /* It will take a while */
      }
      if (DS18X20_read_decicelsius(id, &temp_dc) == DS18X20_OK) {
        /* Copied from my MCU code, so no float point */
        fprintf(stdout, "TEMP %3d.%01d C\n", temp_dc / 10, temp_dc > 0 ? temp_dc % 10 : -temp_dc % 10);
        continue;
      }
    }

    puts("MEASURE FAILED!\n");

  }
  puts("Sensors listed.\n");

  ow_finit();
  return 0;
}
Пример #4
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(ds18b20_poll_process, ev, data)
{
  static struct etimer et;
  static uint8_t scratchpad[DS18B20_SCRATCHPAD_SIZE];
  static ow_rom_code_t id;

  PROCESS_BEGIN();

  printf("\nDS18B20 test\n");

  printf("VSEC ON\n");
  power_control_vsec_set(1);

  /* initialize the DS18B20 hardware */
  printf("Initialize 1-wire\n");
  ow_init();
  printf("1-wire READ ROM\n");
  id = ow_read_rom();
  printf("Initialize DS18B20\n");
  ds18b20_init();
  printf("DS18B20 init done\n");

  /* Poll at 1Hz */
  etimer_set(&et, CLOCK_SECOND);

  while(1) {
    PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));

    /* Reset the etimer to trig again */
    etimer_reset(&et);

    ds18b20_read_scratchpad(id, scratchpad);
    ds18b20_convert_temperature(id);
  }

  PROCESS_END();
}
Пример #5
0
int main(void)
{
	uint8_t last_min = 0;
	cli();

	DDRC = _BV(C_SCL);

	DDRD = _BV(D_LCD_BL) | _BV(D_LCD_SEL) | _BV(D_LCD_SCK) |
		_BV(D_LCD_MOSI) | _BV(D_LCD_RESET) | _BV(D_ALERT);

#if (FOSC == 18432000UL)
	/*
	 * Fosc = 18432000
	 * Fping = 100 Hz
	 *
	 * Fosc / Fping / 1024 = 180;
	 */
	set_timer2(_BV(CS22) | _BV(CS21) | _BV(CS20), 180);
#elif (FOSC == 7372800UL)
	/*
	 * Fosc = 7372800
	 * Fping = 100 Hz
	 *
	 * Fosc / Fping / 1024 = 72;
	 */
	set_timer2(_BV(CS22) | _BV(CS21) | _BV(CS20), 72);
#elif (FOSC == 16000000UL)
	/*
	 * Fosc = 16000000
	 * Fping = 100 Hz
	 *
	 * Fosc / Fping / 1024 = 156;
	 */
	set_timer2(_BV(CS22) | _BV(CS21) | _BV(CS20), 156);
#else
#error "unsupported FOSC freq"
#endif

	twi_master_init();
	twi_add_device(rtc_begin, rtc_end);
	twi_add_device(relay_begin, relay_end);
	sei();

	lcd_init();
	lcd_fill(0, 0, 131, 131, 0x000);

	ow_init();
	ds18b20_init();
	adc_sample();

	set_point = 25 << 8;

	while (1) {
		ds18b20_ping();

		if (last_min != time[1]) {
			temp_history[temp_history_idx] = ds18b20_temps[1];
			temp_history_idx++;
			if (temp_history_idx == ARRAY_SIZE(temp_history))
				temp_history_idx = 0;
			last_min = time[1];
		}

		if (ph == 0) {
			ph = (uint32_t)adc_data[2] << PH_IIR_SHIFT;
		} else {
			ph -= ph >> PH_IIR_SHIFT;
			ph += adc_data[2];
		}

		ui();

		if (alert)
			PORTD |= _BV(D_ALERT);
		else
			PORTD &= ~_BV(D_ALERT);

		cli();
		if (ds18b20_temps[1] < set_point)
			relays &= ~0x1;
		else if(ds18b20_temps[1] > (set_point + (1 << 4)))
			relays |= 0x1;
		sei();
	}

}
Пример #6
0
//! You expected it: This routine is expected never to exit
void main (void)
{
    port_init();
    watchdog_init();
    timer_gpt3_init();
    adc_init();
    cursors_init();
    power_init();

    uart_init();

    /* enable interrupts. */
    EA = 1;

    get_board_id();
    startup_message();

    dump_xdata_sfr();
    gpio_check_IO_direction();
    dump_gpio();
    dump_mcs51();

tx_drain();  // oops, UART routines seem not yet clean

    print_states_ruler();
    print_states_enable = 1;
    print_states();
    print_states_enable = 0;

    save_old_states();
    states.number = 0;

    manufacturing_print_all();

    ow_init();
    timer1_init();
    battery_charging_table_init();

    LED_CHG_G_OFF();
    LED_CHG_R_OFF();
    LED_PWR_OFF();

    /* The main loop contains several state machines handling
       various subsystems on the EC.
       The idea is to have each subroutine return as quickly
       as it can (no busy wait unless for a _very_ short delay).
       Also the subroutines should be pretty much self contained.

       Unless it is noted _here_ no state machine should need
       more than xxx microseconds before returning control.
       When a state machine returns control it is expected to
       have the variables it is working on in a consistent
       state. Period (just in case it was missed:^)

       If it helps: you may want to think of the main loop
       as a round-robin cooperative scheduler without the
       overhead this usually implies. This works well if, well,
       if _all_ routines within the main loop cooperate well.
     */
    while(1)
    {
        STATES_TIMESTAMP();

        busy = handle_command();
        busy |= handle_cursors();
        handle_leds();
        handle_power();
        handle_ds2756_requests();
        handle_ds2756_readout();
        busy |= handle_battery_charging_table();

        watchdog_all_up_and_well |= WATCHDOG_MAIN_LOOP_IS_FINE;

        print_states();

        monitor();

        handle_debug();

        sleep_if_allowed();
    }
}
Пример #7
0
void ds18b20_init()
{
    ow_init();
}