NAMESPACE_UPP #ifdef PLATFORM_POSIX bool GetBatteryStatus(bool &discharging, int &percentage, int &remainingMin) { /* This is only if acpi package is present StringParse data = Sys("acpi -V"); data.GoAfter("AC Adapter", ":"); String sacStatus = data.GetText(); discharging = sacStatus != "on-line"; data.GoInit(); data.GoAfter("Battery", ":"); data.GoAfter(","); percentage = data.GetInt("%"); data.GoAfter(","); String remaining; if (discharging) { remaining = data.GetText(" "); int hour, min; double secs; StringToHMS(remaining, hour, min, secs); // It is really days:hour:min in this case remainingMin = int(secs) + min*60 + hour*24*60; } else remainingMin = Null; */ percentage = 100; Array<String> files = SearchFile("/proc/acpi/battery", "state"); if (files.GetCount() == 0) return false; StringParse state = LoadFile_Safe(files[0]); if (state == "") return false; bool present; if(!state.GoAfter_Init("present", ":")) return false; present = state.GetText() == "yes"; if (!present) return false; // No battery inserted state.GoAfter_Init("charging state", ":"); discharging = state.GetText() == "discharging"; int presentRate, remainingCapacity; state.GoAfter_Init("present rate", ":"); presentRate = state.GetInt(); state.GoAfter_Init("remaining capacity", ":"); remainingCapacity = state.GetInt(); if (presentRate == 0 || !discharging) remainingMin = Null; else remainingMin = (int)((60.*remainingCapacity)/presentRate); int designCapacity,lastFullCapacity; String vendor, type, model, serial; if (!GetBatteryInfo(present/*, designCapacity, lastFullCapacity, vendor, type, model, serial*/)) percentage = (int)((100.*remainingCapacity)/lastFullCapacity); return true; }
bool GetBatteryInfo(bool &present/*, int &designCapacity, int &lastFullCapacity, String &vendor, String &type, String &model, String &serial*/) { Array<String> files = SearchFile("/proc/acpi/battery", "info"); if (files.GetCount() == 0) return false; StringParse info = LoadFile_Safe(files[0]); if (info == "") return false; info.GoAfter_Init("present", ":"); present = info.GetText() == "yes"; /* info.GoAfter_Init("design capacity", ":"); designCapacity = info.GetInt(); info.GoAfter_Init("last full capacity", ":");lastFullCapacity = info.GetInt(); info.GoAfter_Init("OEM info", ":"); vendor = info.GetText(); info.GoAfter_Init("battery type", ":"); type = info.GetText(); info.GoAfter_Init("model number", ":"); model = info.GetText(); info.GoAfter_Init("serial number", ":"); serial = info.GetText(); */ return true; }
static boolean setconfig_handler(TinyWebServer& web_server) { const char* length_str = web_server.get_header_value("Content-Length"); int length = atoi(length_str); uint32_t start_time = millis(); StringParse buf; Client& client = web_server.get_client(); if (length <= 0) return true; while (buf.length() < length && client.connected() && (millis() - start_time < 30000)) { if (!client.available()) continue; buf += client.readString(); } IP_Config.ParseConfig(buf); IP_Config.SaveConfig(); return true; }
static boolean config_handler(TinyWebServer& web_server) { web_server.send_error_code(200); web_server.end_headers(); const char* length_str = web_server.get_header_value("Content-Length"); int length = atoi(length_str); uint32_t start_time = millis(); StringParse buf; EthernetClient client = web_server.get_client(); while (buf.length() < length && client.connected() && (millis() - start_time < 30000)) { if (!client.available()) continue; buf += client.readString(); } ParseConfig(buf); IP_Config.SaveConfig(); main_page(client, F("<font color='green'>IP Config saved</font>")); return true; }
static void ParseConfig(StringParse &buf) { Serial << buf << '\n'; IP_Config.useDHCP = buf.Get(F("useDHCP")) == "true" ? true : false; Ascii2MAC(buf.Get(F("mac")), IP_Config.mac_address); Ascii2IP(buf.Get(F("ip")), IP_Config.local_ip); Ascii2IP(buf.Get(F("subnet")), IP_Config.subnet); Ascii2IP(buf.Get(F("gateway")), IP_Config.gateway); Ascii2IP(buf.Get(F("dns")), IP_Config.dns_server); }