Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 67 additions & 1 deletion config/common/developer.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,70 @@ switch:
id(udp_streamer).request_stop(); // Stop the stream when Comm mic is turned off
}
- delay: 500ms
- micro_wake_word.start:
- micro_wake_word.start:

select:
- platform: template
name: TAS2780 AMP LEVEL (dbV)
id: tas_amp_level_select
options:
- "11"
- "11.5"
- "12"
- "12.5"
- "13"
- "13.5"
- "14"
- "14.5"
- "15"
- "15.5"
- "16"
- "16.5"
- "17"
- "17.5"
- "18"
- "18.5"
- "19"
- "19.5"
- "20"
- "20.5"
- "21"
initial_option: "15"
optimistic: true
on_value:
- tas2780.update_config:
amp_level_idx: !lambda |-
auto index = id(tas_amp_level_select).active_index();
if (index.has_value()){
return index.value();
}
ESP_LOGI("main", "No amp level selected");

number:
- platform: template
name: Volume Range Min
id: vol_rng_min
mode: "slider"
optimistic: true
min_value: 0
max_value: 1.
step: .05
initial_value: .3
on_value:
then:
- tas2780.update_config:
vol_range_min: !lambda "return x;"

- platform: template
name: Volume Range Max
id: vol_rng_max
mode: "slider"
optimistic: true
min_value: 0
max_value: 1.
initial_value: 1.
step: .05
on_value:
then:
- tas2780.update_config:
vol_range_max: !lambda "return x;"
4 changes: 4 additions & 0 deletions config/common/media_player.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ fusb302b:
return id(pd_fusb302b).contract_voltage >= 9;
then:
- tas2780.activate:
mode: 2
else:
- tas2780.activate:
mode: 0
speaker:
- platform: i2s_audio
id: i2s_audio_speaker
Expand Down
4 changes: 4 additions & 0 deletions config/satellite1.base.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,10 @@ memory_flasher:
return id(pd_fusb302b).contract_voltage >= 9;
then:
- tas2780.activate:
mode: 2
else:
- tas2780.activate:
mode: 0

on_flashing_failed:
then:
Expand Down
57 changes: 53 additions & 4 deletions esphome/components/tas2780/audio_dac.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,20 @@
)

ActivateAction = tas2780_ns.class_(
"ActivateAction", automation.Action, cg.Parented.template(tas2780)
"ActivateAction", automation.Action
)

UpdateConfigAction = tas2780_ns.class_(
"UpdateConfigAction", automation.Action
)

DeactivateAction = tas2780_ns.class_(
"DeactivateAction", automation.Action, cg.Parented.template(tas2780)
)


CONF_VOL_RNG_MIN = "vol_range_min"
CONF_VOL_RNG_MAX = "vol_range_max"
CONF_AMP_LEVEL_IDX = "amp_level_idx"

CONFIG_SCHEMA = (
cv.Schema(
Expand All @@ -37,16 +43,59 @@
)


TAS2780_ACTION_SCHEMA = automation.maybe_simple_id({cv.GenerateID(): cv.use_id(tas2780)})
TAS2780_ACTION_SCHEMA = cv.Schema(
{
cv.GenerateID(): cv.use_id(tas2780),
cv.Optional(CONF_MODE, default=2) : cv.int_range(0,3)
}
)

@automation.register_action("tas2780.deactivate", DeactivateAction, TAS2780_ACTION_SCHEMA)
@automation.register_action("tas2780.activate", ActivateAction, TAS2780_ACTION_SCHEMA)
@automation.register_action("tas2780.reset", RestAction, TAS2780_ACTION_SCHEMA)
async def tas2780_action(config, action_id, template_arg, args):
var = cg.new_Pvariable(action_id, template_arg)
await cg.register_parented(var, config[CONF_ID])
return var

@automation.register_action("tas2780.activate", ActivateAction, TAS2780_ACTION_SCHEMA)
async def tas2780_action(config, action_id, template_arg, args):
tas2780 = await cg.get_variable(config[CONF_ID])
var = cg.new_Pvariable(action_id, template_arg, tas2780)
mode_ = config.get(CONF_MODE)
template_ = await cg.templatable(mode_, args, cg.uint8)
cg.add(var.set_mode(template_))
return var



TAS2780_UPDATE_CONFIG_SCHEMA = cv.Schema(
{
cv.GenerateID(): cv.use_id(tas2780),
cv.Optional(CONF_VOL_RNG_MIN, default=.3) : cv.templatable(cv.float_range(0.,1.)),
cv.Optional(CONF_VOL_RNG_MAX, default=1.) : cv.templatable(cv.float_range(0.,1.)),
cv.Optional(CONF_AMP_LEVEL_IDX) : cv.templatable(cv.int_range(0, 20))
}
)


@automation.register_action("tas2780.update_config", UpdateConfigAction, TAS2780_UPDATE_CONFIG_SCHEMA)
async def tas2780_action(config, action_id, template_arg, args):
tas2780 = await cg.get_variable(config[CONF_ID])
var = cg.new_Pvariable(action_id, template_arg, tas2780)
vol_min_ = config.get(CONF_VOL_RNG_MIN)
template_ = await cg.templatable(vol_min_, args, float)
cg.add(var.set_vol_range_min(template_))
vol_max_ = config.get(CONF_VOL_RNG_MAX)
template_ = await cg.templatable(vol_max_, args, float)
cg.add(var.set_vol_range_max(template_))
if CONF_AMP_LEVEL_IDX in config:
amp_level_idx = config.get(CONF_AMP_LEVEL_IDX)
template_ = await cg.templatable(amp_level_idx, args, cg.uint8)
cg.add(var.set_amp_level(template_))

return var



async def to_code(config):
var = cg.new_Pvariable(config[CONF_ID])
Expand Down
46 changes: 44 additions & 2 deletions esphome/components/tas2780/automation.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,53 @@ class ResetAction : public Action<Ts...>, public Parented<TAS2780> {
};

template< typename... Ts>
class ActivateAction : public Action<Ts...>, public Parented<TAS2780> {
class ActivateAction : public Action<Ts...> {
public:
void play(Ts... x) override { this->parent_->activate(); }
ActivateAction(TAS2780 *parent) : parent_(parent) {}
TEMPLATABLE_VALUE(uint8_t, mode)

void play(Ts... x) override {
if( this->mode_.has_value() ){
this->parent_->activate(this->mode_.value(x...));
}
else{
this->parent_->activate();
}
}

protected:
TAS2780 *parent_;
};

template< typename... Ts>
class UpdateConfigAction : public Action<Ts...> {
public:
UpdateConfigAction(TAS2780 *parent) : parent_(parent) {}
TEMPLATABLE_VALUE(uint8_t, amp_level)
TEMPLATABLE_VALUE(float, vol_range_min)
TEMPLATABLE_VALUE(float, vol_range_max)

void play(Ts... x) override {
if( this->amp_level_.has_value() ){
this->parent_->set_amp_level(this->amp_level_.value(x...));
this->parent_->update_register();
}
if( this->vol_range_min_.has_value() ){
this->parent_->set_vol_range_min(this->vol_range_min_.value(x...));
}
if( this->vol_range_max_.has_value() ){
this->parent_->set_vol_range_max(this->vol_range_max_.value(x...));
}
}

protected:
TAS2780 *parent_;
};





template< typename... Ts>
class DeactivateAction : public Action<Ts...>, public Parented<TAS2780> {
public:
Expand Down
Loading