Skip to content

Potential sensor framework issue regarding the timer #884

@LinJian1982

Description

@LinJian1982

It looks like we shall reset the ms_to_next_check if it is large than "s->read_interval".
for example, we have two sensors in the system. The read interval of them are 100ms and 1000ms. The current code causes the ms_to_next_check be set to 1000ms, so the callback of the shorter one only be called after 1000ms.

if (elpased_ms >= s->read_interval) {
            attr_container_t * data = s->read(s);
            if (data) {
                sensor_client_t * client = s->clients;
                while (client) {
                    client->client_callback(client, s->sensor_id, data);
                    client = client->next;
                }
                attr_container_destroy(data);
            }
            s->last_read = now;

            if (ms_to_next_check == -1 || (ms_to_next_check < s->read_interval))
                ms_to_next_check = s->read_interval;
        } else {
            int remaining = s->read_interval - elpased_ms;
            if (ms_to_next_check == -1 || (ms_to_next_check < remaining))
                ms_to_next_check = remaining;

        }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions