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
View File
@@ -0,0 +1,21 @@
# Kernel module build artifacts
*.o
*.ko
*.cmd
.*.cmd
*.mod
*.mod.c
*.mod.o
*.symvers
*.order
*.markers
.tmp_versions/
.cache.mk
# Backup files
*~
.#*
# clangd
.cache/
compile_commands.json
+10 -3
View File
@@ -1,6 +1,13 @@
fake-battery-dkms (0.1.1-1) stable; urgency=low
* Add manufacturer, model name and serial number
* Remove duplicated log prefixes
-- Vincent Schweiger <vincent.schweiger@icloud.com> Fri, 21 Aug 2026 21:20:15 +0200
fake-battery-dkms (0.1.0-1) stable; urgency=low fake-battery-dkms (0.1.0-1) stable; urgency=low
* Initial release * Initial release
-- Vincent Schweiger <vincent.schweiger@icloud.com> Fri, 21 Aug 2026 19:39:00 +0200
-- Vincent Schweiger <vincent.schweiger@icloud.com> Fri, 21 Aug 2026 19:39:00
+0200
+1 -1
View File
@@ -1,4 +1,4 @@
PACKAGE_VERSION="0.1.0" PACKAGE_VERSION="0.1.1"
PACKAGE_NAME="fake-battery" PACKAGE_NAME="fake-battery"
CLEAN=true CLEAN=true
BUILT_MODULE_NAME[0]="fake-battery" BUILT_MODULE_NAME[0]="fake-battery"
+21 -7
View File
@@ -1,9 +1,12 @@
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
#include <linux/module.h> #include <linux/module.h>
#include <linux/kernel.h> #include <linux/kernel.h>
#include <linux/power_supply.h> #include <linux/power_supply.h>
#include <linux/init.h> #include <linux/init.h>
#define VERSION_STR "0.1.1"
static struct power_supply *fake_battery; static struct power_supply *fake_battery;
static struct power_supply_desc battery_desc; 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_VOLTAGE_NOW,
POWER_SUPPLY_PROP_CURRENT_NOW, POWER_SUPPLY_PROP_CURRENT_NOW,
POWER_SUPPLY_PROP_TEMP, 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, 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 */ val->intval = 0; /* Not charging */
break; break;
case POWER_SUPPLY_PROP_TEMP: 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; break;
default: default:
return -EINVAL; return -EINVAL;
@@ -73,7 +88,7 @@ static int __init fake_battery_init(void)
{ {
int ret; int ret;
pr_info("fake_battery: Loading fake battery module\n"); pr_debug("loading fake battery module\n");
// Initialize the power supply descriptor // Initialize the power supply descriptor
battery_desc.name = "fake-battery"; 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); fake_battery = power_supply_register(NULL, &battery_desc, NULL);
if (IS_ERR(fake_battery)) { if (IS_ERR(fake_battery)) {
ret = PTR_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; return ret;
} }
pr_info("fake_battery: Fake battery registered successfully\n"); pr_debug("fake battery registered successfully\n");
pr_info("fake_battery: Battery status: 100%% charged\n");
return 0; return 0;
} }
static void __exit fake_battery_exit(void) 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) if (fake_battery)
power_supply_unregister(fake_battery); power_supply_unregister(fake_battery);
} }
@@ -108,5 +122,5 @@ module_exit(fake_battery_exit);
MODULE_AUTHOR("Vincent Schweiger"); MODULE_AUTHOR("Vincent Schweiger");
MODULE_DESCRIPTION("Fake battery module that reports a fully charged battery"); MODULE_DESCRIPTION("Fake battery module that reports a fully charged battery");
MODULE_VERSION("0.1.0"); MODULE_VERSION(VERSION_STR);
MODULE_LICENSE("GPL"); MODULE_LICENSE("GPL");