30-11-2019, 22:33
Biblioteka nie jest na przerywaniu. Na esp8266 działa pulsenIn(), nie działa tylko pulsenInlong()
te wycinki z biblioteki
a tu biblioteka esp
te wycinki z biblioteki
Kod:
double HLW8012::getCurrent() {
// Power measurements are more sensitive to switch offs,
// so we first check if power is 0 to set _current to 0 too
if (_power == 0) {
_current_pulse_width = 0;
} else if (_use_interrupts) {
_checkCF1Signal();
} else if (_mode == _current_mode) {
_current_pulse_width = pulseIn(_cf1_pin, HIGH, _pulse_timeout);
}
_current = (_current_pulse_width > 0) ? _current_multiplier / _current_pulse_width / 2 : 0;
return _current;
}
unsigned int HLW8012::getVoltage() {
if (_use_interrupts) {
_checkCF1Signal();
} else if (_mode != _current_mode) {
_voltage_pulse_width = pulseIn(_cf1_pin, HIGH, _pulse_timeout);
}
_voltage = (_voltage_pulse_width > 0) ? _voltage_multiplier / _voltage_pulse_width / 2 : 0;
return _voltage;
}
unsigned int HLW8012::getActivePower() {
if (_use_interrupts) {
_checkCFSignal();
} else {
_power_pulse_width = pulseIn(_cf_pin, HIGH, _pulse_timeout);
}
_power = (_power_pulse_width > 0) ? _power_multiplier / _power_pulse_width / 2 : 0;
return _power;
}
a tu biblioteka esp
Kod:
// max timeout is 27 seconds at 160MHz clock and 54 seconds at 80MHz clock
unsigned long pulseIn(uint8_t pin, uint8_t state, unsigned long timeout)
{
const uint32_t max_timeout_us = clockCyclesToMicroseconds(UINT_MAX);
if (timeout > max_timeout_us) {
timeout = max_timeout_us;
}
const uint32_t timeout_cycles = microsecondsToClockCycles(timeout);
const uint32_t start_cycle_count = xthal_get_ccount();
WAIT_FOR_PIN_STATE(!state);
WAIT_FOR_PIN_STATE(state);
const uint32_t pulse_start_cycle_count = xthal_get_ccount();
WAIT_FOR_PIN_STATE(!state);
return clockCyclesToMicroseconds(xthal_get_ccount() - pulse_start_cycle_count);
}
Arduino zostało wymyślone po to, by robić dobrze jedną prostą rzecz – migać diodą.