Fix pcf85063.start_timer action
This commit is contained in:
parent
aa371c22a4
commit
7c3016349b
3 changed files with 22 additions and 11 deletions
|
@ -82,20 +82,20 @@ void PCF85063Component::write_time() {
|
|||
}
|
||||
|
||||
void PCF85063Component::write_nvram(uint8_t data) {
|
||||
this->pcf85063_.reg.nvram = data;
|
||||
this->write_bytes(0x03, &this->pcf85063_.raw[0x03], 1);
|
||||
pcf85063_.reg.nvram = data;
|
||||
this->write_bytes(0x03, &pcf85063_.raw[0x03], 1);
|
||||
}
|
||||
|
||||
uint8_t PCF85063Component::read_nvram() {
|
||||
this->read_bytes(0x03, &this->pcf85063_.raw[0x03], 1);
|
||||
return this->pcf85063_.reg.nvram;
|
||||
this->read_bytes(0x03, &pcf85063_.raw[0x03], 1);
|
||||
return pcf85063_.reg.nvram;
|
||||
}
|
||||
|
||||
/*
|
||||
TIMER_CLOCK_MINUTE 60 15300 1m 4h15m
|
||||
TIMER_CLOCK_SECOND 1 255 1s 4m15s
|
||||
*/
|
||||
bool PCF85063Component::set_timer_interval(uint16_t interval_seconds) {
|
||||
bool PCF85063Component::write_timer_interval(uint16_t interval_seconds) {
|
||||
if (interval_seconds < 256) {
|
||||
pcf85063_.reg.timer_clock_frequency = TIMER_CLOCK_SECOND;
|
||||
pcf85063_.reg.timer_value = interval_seconds;
|
||||
|
@ -116,6 +116,14 @@ bool PCF85063Component::set_timer_interval(uint16_t interval_seconds) {
|
|||
return this->write_timer_();
|
||||
}
|
||||
|
||||
void PCF85063Component::set_timer_interrupt_enable_(bool state) {
|
||||
pcf85063_.reg.timer_interrupt_enable = state;
|
||||
}
|
||||
|
||||
void PCF85063Component::set_timer_interrupt_mode_(PCF85063ATimerInterruptMode_t mode) {
|
||||
pcf85063_.reg.timer_interrupt_mode = mode;
|
||||
}
|
||||
|
||||
bool PCF85063Component::write_timer_() {
|
||||
if (!this->write_bytes(0x10, &this->pcf85063_.raw[0x03], 2)) {
|
||||
ESP_LOGE(TAG, "Can't write I2C data.");
|
||||
|
|
|
@ -30,7 +30,10 @@ class PCF85063Component : public time::RealTimeClock, public i2c::I2CDevice {
|
|||
void write_nvram(uint8_t);
|
||||
uint8_t read_nvram();
|
||||
|
||||
bool set_timer_interval(uint16_t interval);
|
||||
//bool set_timer_interval_us(uint64_t interval_us);
|
||||
bool write_timer_interval(uint16_t interval);
|
||||
void set_timer_interrupt_enable_(bool state);
|
||||
void set_timer_interrupt_mode_(PCF85063ATimerInterruptMode_t mode);
|
||||
|
||||
|
||||
protected:
|
||||
|
@ -143,9 +146,9 @@ template<typename... Ts> class StartTimerAction : public Action<Ts...>, public P
|
|||
public:
|
||||
TEMPLATABLE_VALUE(uint16_t, timer_seconds);
|
||||
void play(Ts... x) override {
|
||||
this->parent_->pcf85063_.reg.timer_interrupt_enable = true;
|
||||
this->parent_->pcf85063_.reg.timer_interrupt_mode = TIMER_INTERRUPT_MODE_FLAG;
|
||||
this->parent_->set_timer_interval(this->timer_seconds_.value(x...));
|
||||
this->parent_->set_timer_interrupt_enable_(true);
|
||||
this->parent_->set_timer_interrupt_mode_(TIMER_INTERRUPT_MODE_FLAG);
|
||||
this->parent_->write_timer_interval(this->timer_seconds_.value(x...));
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -81,8 +81,8 @@ def validate_timer_seconds(value):
|
|||
async def pcf85063_start_timer_to_code(config, action_id, template_arg, args):
|
||||
var = cg.new_Pvariable(action_id, template_arg)
|
||||
|
||||
template_ = await cg.templatable(config[CONF_INTERVAL], args, cv.TimePeriodSeconds)
|
||||
cg.add(var.start_timer(template_))
|
||||
#template_ = await cg.templatable(config[CONF_INTERVAL], args, cv.TimePeriodSeconds)
|
||||
#cg.add(var.timer_seconds_(template_))
|
||||
|
||||
await cg.register_parented(var, config[CONF_ID])
|
||||
return var
|
||||
|
|
Loading…
Reference in a new issue