add gitignore, update module with additional properties

This commit is contained in:
2026-08-21 21:24:16 +02:00
parent 2777dbfd01
commit f1a63fcea3
4 changed files with 53 additions and 11 deletions
+21 -7
View File
@@ -1,9 +1,12 @@
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/power_supply.h>
#include <linux/init.h>
#define VERSION_STR "0.1.1"
static struct power_supply *fake_battery;
static struct power_supply_desc battery_desc;
@@ -20,6 +23,9 @@ static enum power_supply_property fake_battery_props[] = {
POWER_SUPPLY_PROP_VOLTAGE_NOW,
POWER_SUPPLY_PROP_CURRENT_NOW,
POWER_SUPPLY_PROP_TEMP,
POWER_SUPPLY_PROP_MODEL_NAME,
POWER_SUPPLY_PROP_MANUFACTURER,
POWER_SUPPLY_PROP_SERIAL_NUMBER,
};
static int fake_battery_get_property(struct power_supply *psy,
@@ -61,7 +67,16 @@ static int fake_battery_get_property(struct power_supply *psy,
val->intval = 0; /* Not charging */
break;
case POWER_SUPPLY_PROP_TEMP:
val->intval = 250; /* 25°C in 0.1°C units */
val->intval = 253; /* 25°C in 0.1°C units */
break;
case POWER_SUPPLY_PROP_MODEL_NAME:
val->strval = "Fake Battery v" VERSION_STR;
break;
case POWER_SUPPLY_PROP_MANUFACTURER:
val->strval = "Thin Air";
break;
case POWER_SUPPLY_PROP_SERIAL_NUMBER:
val->strval = "deadbeef";
break;
default:
return -EINVAL;
@@ -73,7 +88,7 @@ static int __init fake_battery_init(void)
{
int ret;
pr_info("fake_battery: Loading fake battery module\n");
pr_debug("loading fake battery module\n");
// Initialize the power supply descriptor
battery_desc.name = "fake-battery";
@@ -86,19 +101,18 @@ static int __init fake_battery_init(void)
fake_battery = power_supply_register(NULL, &battery_desc, NULL);
if (IS_ERR(fake_battery)) {
ret = PTR_ERR(fake_battery);
pr_err("fake_battery: Failed to register power supply: %d\n", ret);
pr_err("failed to register power supply: %d\n", ret);
return ret;
}
pr_info("fake_battery: Fake battery registered successfully\n");
pr_info("fake_battery: Battery status: 100%% charged\n");
pr_debug("fake battery registered successfully\n");
return 0;
}
static void __exit fake_battery_exit(void)
{
pr_info("fake_battery: Unloading fake battery module\n");
pr_debug("unloading fake battery module\n");
if (fake_battery)
power_supply_unregister(fake_battery);
}
@@ -108,5 +122,5 @@ module_exit(fake_battery_exit);
MODULE_AUTHOR("Vincent Schweiger");
MODULE_DESCRIPTION("Fake battery module that reports a fully charged battery");
MODULE_VERSION("0.1.0");
MODULE_VERSION(VERSION_STR);
MODULE_LICENSE("GPL");