|
|
|
@@ -2,15 +2,16 @@
|
|
|
|
|
#include "common/printing.h"
|
|
|
|
|
#include "common/bar.h"
|
|
|
|
|
#include "detection/battery/battery.h"
|
|
|
|
|
#include "modules/battery/battery.h"
|
|
|
|
|
|
|
|
|
|
#define FF_BATTERY_MODULE_NAME "Battery"
|
|
|
|
|
#define FF_BATTERY_NUM_FORMAT_ARGS 5
|
|
|
|
|
|
|
|
|
|
static void printBattery(FFinstance* instance, BatteryResult* result, uint8_t index)
|
|
|
|
|
static void printBattery(FFinstance* instance, FFBatteryOptions* options, BatteryResult* result, uint8_t index)
|
|
|
|
|
{
|
|
|
|
|
if(instance->config.battery.outputFormat.length == 0)
|
|
|
|
|
if(instance->config.battery.moduleArgs.outputFormat.length == 0)
|
|
|
|
|
{
|
|
|
|
|
ffPrintLogoAndKey(instance, FF_BATTERY_MODULE_NAME, index, &instance->config.battery.key);
|
|
|
|
|
ffPrintLogoAndKey(instance, FF_BATTERY_MODULE_NAME, index, &options->moduleArgs.key);
|
|
|
|
|
|
|
|
|
|
bool showStatus =
|
|
|
|
|
!(instance->config.percentType & FF_PERCENTAGE_TYPE_HIDE_OTHERS_BIT) &&
|
|
|
|
@@ -62,7 +63,7 @@ static void printBattery(FFinstance* instance, BatteryResult* result, uint8_t in
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
ffPrintFormat(instance, FF_BATTERY_MODULE_NAME, index, &instance->config.battery, FF_BATTERY_NUM_FORMAT_ARGS, (FFformatarg[]){
|
|
|
|
|
ffPrintFormat(instance, FF_BATTERY_MODULE_NAME, index, &options->moduleArgs, FF_BATTERY_NUM_FORMAT_ARGS, (FFformatarg[]){
|
|
|
|
|
{FF_FORMAT_ARG_TYPE_STRBUF, &result->manufacturer},
|
|
|
|
|
{FF_FORMAT_ARG_TYPE_STRBUF, &result->modelName},
|
|
|
|
|
{FF_FORMAT_ARG_TYPE_STRBUF, &result->technology},
|
|
|
|
@@ -73,7 +74,7 @@ static void printBattery(FFinstance* instance, BatteryResult* result, uint8_t in
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ffPrintBattery(FFinstance* instance)
|
|
|
|
|
void ffPrintBattery(FFinstance* instance, FFBatteryOptions* options)
|
|
|
|
|
{
|
|
|
|
|
FFlist results;
|
|
|
|
|
ffListInitA(&results, sizeof(BatteryResult), 0);
|
|
|
|
@@ -82,14 +83,14 @@ void ffPrintBattery(FFinstance* instance)
|
|
|
|
|
|
|
|
|
|
if (error)
|
|
|
|
|
{
|
|
|
|
|
ffPrintError(instance, FF_BATTERY_MODULE_NAME, 0, &instance->config.battery, "%s", error);
|
|
|
|
|
ffPrintError(instance, FF_BATTERY_MODULE_NAME, 0, &options->moduleArgs, "%s", error);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
for(uint8_t i = 0; i < (uint8_t) results.length; i++)
|
|
|
|
|
{
|
|
|
|
|
BatteryResult* result = ffListGet(&results, i);
|
|
|
|
|
printBattery(instance, result, i);
|
|
|
|
|
printBattery(instance, options, result, i);
|
|
|
|
|
|
|
|
|
|
ffStrbufDestroy(&result->manufacturer);
|
|
|
|
|
ffStrbufDestroy(&result->modelName);
|
|
|
|
@@ -97,8 +98,51 @@ void ffPrintBattery(FFinstance* instance)
|
|
|
|
|
ffStrbufDestroy(&result->status);
|
|
|
|
|
}
|
|
|
|
|
if(results.length == 0)
|
|
|
|
|
ffPrintError(instance, FF_BATTERY_MODULE_NAME, 0, &instance->config.battery, "No batteries found");
|
|
|
|
|
ffPrintError(instance, FF_BATTERY_MODULE_NAME, 0, &options->moduleArgs, "No batteries found");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ffListDestroy(&results);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ffInitBatteryOptions(FFBatteryOptions* options)
|
|
|
|
|
{
|
|
|
|
|
options->moduleName = FF_BATTERY_MODULE_NAME;
|
|
|
|
|
ffOptionInitModuleArg(&options->moduleArgs);
|
|
|
|
|
options->temp = false;
|
|
|
|
|
|
|
|
|
|
#ifdef __linux__
|
|
|
|
|
ffStrbufInit(&options->dir);
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool ffParseBatteryCommandOptions(FFBatteryOptions* options, const char* key, const char* value)
|
|
|
|
|
{
|
|
|
|
|
const char* subKey = ffOptionTestPrefix(key, FF_BATTERY_MODULE_NAME);
|
|
|
|
|
if (!subKey) return false;
|
|
|
|
|
if (ffOptionParseModuleArgs(key, subKey, value, &options->moduleArgs))
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
if (strcasecmp(subKey, "temp") == 0)
|
|
|
|
|
{
|
|
|
|
|
options->temp = ffOptionParseBoolean(value);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#ifdef __linux__
|
|
|
|
|
if (strcasecmp(subKey, "dir") == 0)
|
|
|
|
|
{
|
|
|
|
|
ffOptionParseString(key, value, &options->dir);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ffDestroyBatteryOptions(FFBatteryOptions* options)
|
|
|
|
|
{
|
|
|
|
|
ffOptionDestroyModuleArg(&options->moduleArgs);
|
|
|
|
|
#ifdef __linux__
|
|
|
|
|
ffStrbufDestroy(&options->dir);
|
|
|
|
|
#endif
|
|
|
|
|
}
|