Use deque for pending commands
This commit is contained in:
parent
6877f64812
commit
924bad62ed
10
tw7100.cpp
10
tw7100.cpp
|
@ -8,7 +8,7 @@ namespace esphome {
|
|||
namespace tw7100 {
|
||||
|
||||
bool waiting_for_answer = false;
|
||||
std::vector<std::string> cmd_queue;
|
||||
std::deque<std::string> cmd_queue;
|
||||
|
||||
std::vector<std::string> pwr_off_query_cmds{ "PWR?", "LAMP?" };
|
||||
std::vector<std::string> pwr_on_query_cmds{
|
||||
|
@ -96,7 +96,7 @@ void tw7100Component::setup() {
|
|||
|
||||
void tw7100Component::update() {
|
||||
static const char *const TAG = "update()";
|
||||
if (cmd_queue.size() == 0) {
|
||||
if (cmd_queue.empty()) {
|
||||
for (auto &cmd : pwr_off_query_cmds) {
|
||||
cmd_queue.push_back(cmd);
|
||||
}
|
||||
|
@ -120,10 +120,10 @@ void tw7100Component::loop() {
|
|||
std::string response = readStringUntil(':');
|
||||
|
||||
if (response == "") { // no response on bus, we can use our time to do something else
|
||||
if (cmd_queue.size() > 0 && !waiting_for_answer) {
|
||||
if (!cmd_queue.empty() && !waiting_for_answer) {
|
||||
waiting_for_answer = true;
|
||||
std::string cmd = cmd_queue[0];
|
||||
cmd_queue.erase(cmd_queue.begin());
|
||||
std::string cmd = cmd_queue.front();
|
||||
cmd_queue.pop_front();
|
||||
ESP_LOGV(TAG, "sending out command: %s", cmd.c_str());
|
||||
write_str((cmd + "\r\n").c_str());
|
||||
flush();
|
||||
|
|
Loading…
Reference in a new issue