Exemplo n.º 1
0
void
metering_init(void)
{
  /* Load reference values from EEPROM */
  metering_reference_value = eeprom_read_word((void*) EE_METERING_REF );
  metering_calibration_power = eeprom_read_word((void*)EE_METERING_CAL_LOAD);

#if METERING_ENERGY
  // reset energy metering value
  metering_pulses = metering_pulses_total = 0;
#if METERING_ENERGY_PERSISTENT
  DDRB &= ~(1 << METERING_POWERDOWN_DETECT_PIN); // Set PB3 as input -> Cut trace to relay, add voltage divider instead.
  DDRB &= ~(1 << METERING_ANALOG_COMPARATOR_REF_PIN); // Set PB2 as input
  PORTB &= ~(1 << METERING_POWERDOWN_DETECT_PIN); // no internal pullup
  PORTB &= ~(1 << METERING_ANALOG_COMPARATOR_REF_PIN); // no internal pullup
  ENABLE_POWERDOWN_INTERRUPT();
  sei(); // global interrupt enable

  eeprom_read((uint8_t*)EE_ENERGY_METERING_PULSES_TOTAL, (uint8_t*)&metering_pulses_total, sizeof(metering_pulses));
  eeprom_read((uint8_t*)EE_ENERGY_METERING_PULSES, (uint8_t*)&metering_pulses, sizeof(metering_pulses));
#endif // METERING_ENERGY_PERSISTENT
#endif // METERING_ENERGY

  SET_METERING_INT();

  metering_start();

	ENDPOINT_REGISTER(endpoint_power);
#if METERING_ENERGY
	ENDPOINT_REGISTER(endpoint_energy_total);
	ENDPOINT_REGISTER(endpoint_energy);
#endif
}
Exemplo n.º 2
0
void presence_detector_init() {
    global_presence = NO_PRESENCE;
#if PRESENCE_DETECTOR_SERVER
    ctimer_set(&pd_timeout, CLOCK_SECOND*60*PRESENCE_DETECTOR_SERVER_TIMEOUT, no_global_presence, NULL);
    ctimer_stop(&pd_timeout);
#endif
#if PRESENCE_DETECTOR_CLIENT
    presence = NO_PRESENCE;
    if(PRESENCE_DETECTOR_CLIENT_KEEP_ALIVE != 0) {
        ctimer_set(&pd_keep_alive, CLOCK_SECOND*PRESENCE_DETECTOR_CLIENT_KEEP_ALIVE, presence_keep_alive, NULL);
        ctimer_stop(&pd_keep_alive);
    }
#endif
	ENDPOINT_REGISTER(endpoint_presence_detector);
}
Exemplo n.º 3
0
void humidity_init(void)
{
	ENDPOINT_REGISTER(endpoint_humidity);
}