#include #include #include #include "CORE_power.h" #include "CORE_xml.h" /* Init defaults power values */ void power_init(power_t* p){ p->auto_light_off = 0; p->to_off = 0; p->light_on = 1; return; } /* Auto light off */ void power_auto_light(power_t* p){ static u8 frames = 0; // always on if(p->auto_light_off == 0) return; // if light off, nothing to do if(!p->light_on) return; // count seconds.. if(++frames == 60){ frames = 0; p->to_off++; } // is time elapsed ? if(p->to_off == p->auto_light_off){ power_off_light(p); } return; } void power_off_light(power_t* p){ p->light_on = 0; p->to_off = 0; PA_SetScreenLight(0, 0); PA_SetScreenLight(1, 0); return; } void power_on_light(power_t* p){ p->light_on = 1; p->to_off = 0; PA_SetScreenLight(0, 1); PA_SetScreenLight(1, 1); return; } void power_switch_light(power_t* p){ if(p->light_on) power_off_light(p); else power_on_light(p); return; } /* Process xml atoms */ int power_process_xml(void* elem, char* tag, char* content){ power_t* p = (power_t*)elem; if(tag != NULL && content != NULL){ if(strcmp(content, "")){ /* process atom: */ if(!strcmp(tag, "auto_light_off")){ p->auto_light_off = atoi(content); return 1; } return xml_read(elem, power_process_xml, content); } } /* Should not happend... (compiler warning) */ return 0; } /* Write xml atoms */ void power_write_xml(power_t* p, FILE* out){ fprintf(out, " \n"); fprintf(out, " \n"); fprintf(out, " %d\n", p->auto_light_off); fprintf(out, " \n"); return; }