main/alles.c
void ip5306_monitor() {
    esp_err_t ret;

    // Check if the power button was pressed
    int buttons;
    ret = ip5306_button_press_get(&buttons);
    if(ret!= ESP_OK) {
        printf("Error reading button press\n");
        return;
    }

    if(buttons & BUTTON_LONG_PRESS) {
        printf("button long\n");
        const uint32_t button = BUTTON_POWER_LONG;
        xQueueSend(gpio_evt_queue, &button, 0);
    }
    if(buttons & BUTTON_SHORT_PRESS) {
        printf("button short\n");
        const uint32_t button = BUTTON_POWER_SHORT;
        xQueueSend(gpio_evt_queue, &button, 0);
    }

    // Update the battery charge state
    ip5306_charge_state_t charge_state;

    ret = ip5306_charge_state_get(&charge_state);
    if(ret != ESP_OK) {
        printf("Error reading battery charge state\n");
        return;
    }
    
    battery_mask = 0;

    switch(charge_state) {
    case CHARGE_STATE_CHARGED:
        battery_mask = battery_mask | BATTERY_STATE_CHARGED;
        break;
    case CHARGE_STATE_CHARGING:
        battery_mask = battery_mask | BATTERY_STATE_CHARGING;
        break;
    case CHARGE_STATE_DISCHARGING:
        battery_mask = battery_mask | BATTERY_STATE_DISCHARGING;
        break;
    case CHARGE_STATE_DISCHARGING_LOW_BAT:
        battery_mask = battery_mask | BATTERY_STATE_LOW;
        break;
    }

    ip5306_battery_voltage_t battery_voltage;

    ret = ip5306_battery_voltage_get(&battery_voltage);
    if(ret != ESP_OK) {
        //printf("Error getting battery voltage\n");
        return;
    } else {
        if(battery_voltage == BATTERY_OVER_395) battery_mask = battery_mask | BATTERY_VOLTAGE_4;
        if(battery_voltage == BATTERY_38_395) battery_mask = battery_mask | BATTERY_VOLTAGE_3;
        if(battery_voltage == BATTERY_36_38) battery_mask = battery_mask | BATTERY_VOLTAGE_2;
        if(battery_voltage == BATTERY_33_36) battery_mask = battery_mask | BATTERY_VOLTAGE_1;
    }
}
// Periodic task to poll the ip5306 for the battery charge and button states.
// Intented to be run from a low-priority timer at 1-2 Hz
Periodic task to poll the ip5306 for the battery charge and button states.
Intented to be run from a low-priority timer at 1-2 Hz
Periodic task to poll the ip5306 for the battery charge and button states . Intented to be run from a low - priority timer at 1 - 2 Hz
void ip5306_monitor() {
    esp_err_t ret;
    int buttons;
    ret = ip5306_button_press_get(&buttons);
    if(ret!= ESP_OK) {
        printf("Error reading button press\n");
        return;
    }
    if(buttons & BUTTON_LONG_PRESS) {
        printf("button long\n");
        const uint32_t button = BUTTON_POWER_LONG;
        xQueueSend(gpio_evt_queue, &button, 0);
    }
    if(buttons & BUTTON_SHORT_PRESS) {
        printf("button short\n");
        const uint32_t button = BUTTON_POWER_SHORT;
        xQueueSend(gpio_evt_queue, &button, 0);
    }
    ip5306_charge_state_t charge_state;
    ret = ip5306_charge_state_get(&charge_state);
    if(ret != ESP_OK) {
        printf("Error reading battery charge state\n");
        return;
    }
    battery_mask = 0;
    switch(charge_state) {
    case CHARGE_STATE_CHARGED:
        battery_mask = battery_mask | BATTERY_STATE_CHARGED;
        break;
    case CHARGE_STATE_CHARGING:
        battery_mask = battery_mask | BATTERY_STATE_CHARGING;
        break;
    case CHARGE_STATE_DISCHARGING:
        battery_mask = battery_mask | BATTERY_STATE_DISCHARGING;
        break;
    case CHARGE_STATE_DISCHARGING_LOW_BAT:
        battery_mask = battery_mask | BATTERY_STATE_LOW;
        break;
    }
    ip5306_battery_voltage_t battery_voltage;
    ret = ip5306_battery_voltage_get(&battery_voltage);
    if(ret != ESP_OK) {
        return;
    } else {
        if(battery_voltage == BATTERY_OVER_395) battery_mask = battery_mask | BATTERY_VOLTAGE_4;
        if(battery_voltage == BATTERY_38_395) battery_mask = battery_mask | BATTERY_VOLTAGE_3;
        if(battery_voltage == BATTERY_36_38) battery_mask = battery_mask | BATTERY_VOLTAGE_2;
        if(battery_voltage == BATTERY_33_36) battery_mask = battery_mask | BATTERY_VOLTAGE_1;
    }
}
void ip5306_monitor ( ) { esp_err_t ret ; int buttons ; ret = ip5306_button_press_get ( & buttons ) ; if ( ret != ESP_OK ) { printf ( " \n " ) ; return ; } if ( buttons & BUTTON_LONG_PRESS ) { printf ( " \n " ) ; const uint32_t button = BUTTON_POWER_LONG ; xQueueSend ( gpio_evt_queue , & button , 0 ) ; } if ( buttons & BUTTON_SHORT_PRESS ) { printf ( " \n " ) ; const uint32_t button = BUTTON_POWER_SHORT ; xQueueSend ( gpio_evt_queue , & button , 0 ) ; } ip5306_charge_state_t charge_state ; ret = ip5306_charge_state_get ( & charge_state ) ; if ( ret != ESP_OK ) { printf ( " \n " ) ; return ; } battery_mask = 0 ; switch ( charge_state ) { case CHARGE_STATE_CHARGED : battery_mask = battery_mask | BATTERY_STATE_CHARGED ; break ; case CHARGE_STATE_CHARGING : battery_mask = battery_mask | BATTERY_STATE_CHARGING ; break ; case CHARGE_STATE_DISCHARGING : battery_mask = battery_mask | BATTERY_STATE_DISCHARGING ; break ; case CHARGE_STATE_DISCHARGING_LOW_BAT : battery_mask = battery_mask | BATTERY_STATE_LOW ; break ; } ip5306_battery_voltage_t battery_voltage ; ret = ip5306_battery_voltage_get ( & battery_voltage ) ; if ( ret != ESP_OK ) { return ; } else { if ( battery_voltage == BATTERY_OVER_395 ) battery_mask = battery_mask | BATTERY_VOLTAGE_4 ; if ( battery_voltage == BATTERY_38_395 ) battery_mask = battery_mask | BATTERY_VOLTAGE_3 ; if ( battery_voltage == BATTERY_36_38 ) battery_mask = battery_mask | BATTERY_VOLTAGE_2 ; if ( battery_voltage == BATTERY_33_36 ) battery_mask = battery_mask | BATTERY_VOLTAGE_1 ; } }
Periodic task to poll the ip5306 for the battery charge and button states.
Periodic task to poll the ip5306 for the battery charge and button states .
// Check if the power button was pressed // Update the battery charge state //printf("Error getting battery voltage\n");