mirror of
https://github.com/lretq/fake-battery-linux.git
synced 2026-08-22 13:27:19 +00:00
initial commit; version 0.1.0
This commit is contained in:
@@ -0,0 +1,8 @@
|
|||||||
|
KVER ?= $(shell uname -r)
|
||||||
|
obj-m := fake-battery.o
|
||||||
|
|
||||||
|
all:
|
||||||
|
$(MAKE) -C /lib/modules/$(KVER)/build M=$(PWD) modules
|
||||||
|
|
||||||
|
clean:
|
||||||
|
$(MAKE) -C /lib/modules/$(KVER)/build M=$(PWD) clean
|
||||||
Vendored
+6
@@ -0,0 +1,6 @@
|
|||||||
|
fake-battery-dkms (0.1.0-1) stable; urgency=low
|
||||||
|
|
||||||
|
* Initial release
|
||||||
|
|
||||||
|
-- Vincent Schweiger <vincent.schweiger@icloud.com> Fri, 21 Aug 2026 19:39:00
|
||||||
|
+0200
|
||||||
Vendored
+14
@@ -0,0 +1,14 @@
|
|||||||
|
Source: fake-battery-dkms
|
||||||
|
Maintainer: Vincent Schweiger <vincent.schweiger@icloud.com>
|
||||||
|
Section: kernel
|
||||||
|
Priority: optional
|
||||||
|
Build-Depends: debhelper-compat (= 13),
|
||||||
|
dh-sequence-dkms,
|
||||||
|
Standards-Version: 4.7.0
|
||||||
|
Rules-Requires-Root: no
|
||||||
|
|
||||||
|
Package: fake-battery-dkms
|
||||||
|
Architecture: all
|
||||||
|
Depends: ${misc:Depends}
|
||||||
|
Description: Fake Battery
|
||||||
|
Creates a fake battery module
|
||||||
Vendored
+1
@@ -0,0 +1 @@
|
|||||||
|
dkms.conf
|
||||||
+5
@@ -0,0 +1,5 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
for dir in fake-battery.c Makefile; do
|
||||||
|
echo ${dir} /usr/src/${PACKAGE_NAME}-${PACKAGE_VERSION}
|
||||||
|
done
|
||||||
+14
@@ -0,0 +1,14 @@
|
|||||||
|
#!/usr/bin/make -f
|
||||||
|
|
||||||
|
PACKAGE_NAME=$(shell grep PACKAGE_NAME= dkms.conf | cut -d= -f2 | cut -d\" -f2)
|
||||||
|
PACKAGE_VERSION=$(shell grep PACKAGE_VERSION= dkms.conf | cut -d= -f2 | cut -d\" -f2)
|
||||||
|
export PACKAGE_NAME PACKAGE_VERSION
|
||||||
|
|
||||||
|
%:
|
||||||
|
dh $@ --with dkms
|
||||||
|
|
||||||
|
# Nothing to configure, build or auto-install (this all happens after
|
||||||
|
# installation using dkms)
|
||||||
|
override_dh_auto_configure:
|
||||||
|
override_dh_auto_build:
|
||||||
|
override_dh_auto_install:
|
||||||
Vendored
+1
@@ -0,0 +1 @@
|
|||||||
|
3.0 (quilt)
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
PACKAGE_VERSION="0.1.0"
|
||||||
|
PACKAGE_NAME="fake-battery"
|
||||||
|
CLEAN=true
|
||||||
|
BUILT_MODULE_NAME[0]="fake-battery"
|
||||||
|
BUILT_MODULE_LOCATION[0]=""
|
||||||
|
DEST_MODULE_LOCATION[0]="/extra"
|
||||||
|
MAKE[0]="make KVER=$kernelver -C ${dkms_tree}/${PACKAGE_NAME}/${PACKAGE_VERSION}/build"
|
||||||
|
AUTOINSTALL="yes"
|
||||||
|
|
||||||
+112
@@ -0,0 +1,112 @@
|
|||||||
|
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
|
||||||
|
#include <linux/module.h>
|
||||||
|
#include <linux/kernel.h>
|
||||||
|
#include <linux/power_supply.h>
|
||||||
|
#include <linux/init.h>
|
||||||
|
|
||||||
|
static struct power_supply *fake_battery;
|
||||||
|
static struct power_supply_desc battery_desc;
|
||||||
|
|
||||||
|
static enum power_supply_property fake_battery_props[] = {
|
||||||
|
POWER_SUPPLY_PROP_STATUS,
|
||||||
|
POWER_SUPPLY_PROP_HEALTH,
|
||||||
|
POWER_SUPPLY_PROP_PRESENT,
|
||||||
|
POWER_SUPPLY_PROP_TECHNOLOGY,
|
||||||
|
POWER_SUPPLY_PROP_CAPACITY,
|
||||||
|
POWER_SUPPLY_PROP_CAPACITY_LEVEL,
|
||||||
|
POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN,
|
||||||
|
POWER_SUPPLY_PROP_CHARGE_FULL,
|
||||||
|
POWER_SUPPLY_PROP_CHARGE_NOW,
|
||||||
|
POWER_SUPPLY_PROP_VOLTAGE_NOW,
|
||||||
|
POWER_SUPPLY_PROP_CURRENT_NOW,
|
||||||
|
POWER_SUPPLY_PROP_TEMP,
|
||||||
|
};
|
||||||
|
|
||||||
|
static int fake_battery_get_property(struct power_supply *psy,
|
||||||
|
enum power_supply_property psp,
|
||||||
|
union power_supply_propval *val)
|
||||||
|
{
|
||||||
|
switch (psp) {
|
||||||
|
case POWER_SUPPLY_PROP_STATUS:
|
||||||
|
val->intval = POWER_SUPPLY_STATUS_FULL;
|
||||||
|
break;
|
||||||
|
case POWER_SUPPLY_PROP_HEALTH:
|
||||||
|
val->intval = POWER_SUPPLY_HEALTH_GOOD;
|
||||||
|
break;
|
||||||
|
case POWER_SUPPLY_PROP_PRESENT:
|
||||||
|
val->intval = 1;
|
||||||
|
break;
|
||||||
|
case POWER_SUPPLY_PROP_TECHNOLOGY:
|
||||||
|
val->intval = POWER_SUPPLY_TECHNOLOGY_LIPO;
|
||||||
|
break;
|
||||||
|
case POWER_SUPPLY_PROP_CAPACITY:
|
||||||
|
val->intval = 100;
|
||||||
|
break;
|
||||||
|
case POWER_SUPPLY_PROP_CAPACITY_LEVEL:
|
||||||
|
val->intval = POWER_SUPPLY_CAPACITY_LEVEL_FULL;
|
||||||
|
break;
|
||||||
|
case POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN:
|
||||||
|
val->intval = 5000000; /* 5000 mAh */
|
||||||
|
break;
|
||||||
|
case POWER_SUPPLY_PROP_CHARGE_FULL:
|
||||||
|
val->intval = 5000000; /* 5000 mAh */
|
||||||
|
break;
|
||||||
|
case POWER_SUPPLY_PROP_CHARGE_NOW:
|
||||||
|
val->intval = 5000000; /* 5000 mAh (fully charged) */
|
||||||
|
break;
|
||||||
|
case POWER_SUPPLY_PROP_VOLTAGE_NOW:
|
||||||
|
val->intval = 4200000; /* 4.2V */
|
||||||
|
break;
|
||||||
|
case POWER_SUPPLY_PROP_CURRENT_NOW:
|
||||||
|
val->intval = 0; /* Not charging */
|
||||||
|
break;
|
||||||
|
case POWER_SUPPLY_PROP_TEMP:
|
||||||
|
val->intval = 250; /* 25°C in 0.1°C units */
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return -EINVAL;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int __init fake_battery_init(void)
|
||||||
|
{
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
pr_info("fake_battery: Loading fake battery module\n");
|
||||||
|
|
||||||
|
// Initialize the power supply descriptor
|
||||||
|
battery_desc.name = "fake-battery";
|
||||||
|
battery_desc.type = POWER_SUPPLY_TYPE_BATTERY;
|
||||||
|
battery_desc.properties = fake_battery_props;
|
||||||
|
battery_desc.num_properties = ARRAY_SIZE(fake_battery_props);
|
||||||
|
battery_desc.get_property = fake_battery_get_property;
|
||||||
|
|
||||||
|
// Register the power supply
|
||||||
|
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);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
pr_info("fake_battery: Fake battery registered successfully\n");
|
||||||
|
pr_info("fake_battery: Battery status: 100%% charged\n");
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void __exit fake_battery_exit(void)
|
||||||
|
{
|
||||||
|
pr_info("fake_battery: Unloading fake battery module\n");
|
||||||
|
if (fake_battery)
|
||||||
|
power_supply_unregister(fake_battery);
|
||||||
|
}
|
||||||
|
|
||||||
|
module_init(fake_battery_init);
|
||||||
|
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_LICENSE("GPL");
|
||||||
Reference in New Issue
Block a user