Skip to content

Commit

Permalink
Merge pull request #157 from numtide/feat/improve-inputs
Browse files Browse the repository at this point in the history
Capture touchpads
  • Loading branch information
Mic92 authored Nov 18, 2024
2 parents 3cd662d + 97f673f commit 42e00a6
Show file tree
Hide file tree
Showing 16 changed files with 2,200 additions and 7 deletions.
18 changes: 14 additions & 4 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"flag"
"fmt"
"log"
"log/slog"
"os"
"strings"

Expand Down Expand Up @@ -65,6 +66,7 @@ Flags:
-h, --help help for nixos-facter
-o, --output string path to write the report
--swap capture swap entries
--log-level string log level, one of <error|warn|info|debug> (default "info")
--hardware strings Hardware items to probe.
Default: %s
Possible values: %s
Expand Down Expand Up @@ -94,17 +96,25 @@ func Execute() {
}

// Set the log level
switch logLevel {
case "debug":

var slogLevel slog.Level
if err := slogLevel.UnmarshalText([]byte(logLevel)); err != nil {
log.Fatalf("invalid log level: %v", err)
}

switch slogLevel {
case slog.LevelDebug:
log.SetFlags(log.LstdFlags | log.Lshortfile)
case "info":
case slog.LevelInfo:
log.SetFlags(log.LstdFlags)
case "warn", "error":
case slog.LevelWarn, slog.LevelError:
log.SetFlags(0)
default:
log.Fatalf("invalid log level: %s", logLevel)
}

slog.SetLogLoggerLevel(slogLevel)

report, err := scanner.Scan()
if err != nil {
log.Fatalf("failed to scan: %v", err)
Expand Down
4 changes: 1 addition & 3 deletions nix/packages/nixos-facter/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ in
modules = ./gomod2nix.toml;

buildInputs = [
pkgs.libusb1
pkgs.systemdMinimal.dev
perSystem.hwinfo.default
];

Expand All @@ -48,9 +48,7 @@ in
];

runtimeInputs = with pkgs; [
libusb1
util-linux
pciutils
];

ldflags = [
Expand Down
133 changes: 133 additions & 0 deletions pkg/hwinfo/hardware.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,90 @@ const (
HardwareClassAll
)

// BaseClass values (superset of PCI classes)
//
//go:generate enumer -type=BaseClass -json -transform=snake -trimprefix BaseClass -output=./hardware_enum_base_class.go
type BaseClass uint16

// these *must* match standard PCI class numbers
const (
BaseClassNone BaseClass = iota
BaseClassStorage
BaseClassNetwork
BaseClassDisplay
BaseClassMultimedia

BaseClassMemory
BaseClassBridge
BaseClassComm
BaseClassSystem
BaseClassInput
BaseClassDocking

BaseClassProcessor
BaseClassSerial
BaseClassWireless
BaseClassI2o
BaseClassOther BaseClass = 0xff
)

// add our own base classes here (starting at 0x100 as PCI values are 8 bit)
const (
BaseClassMonitor BaseClass = iota + 0x100
BaseClassInternal
BaseClassModem
BaseClassIsdn
BaseClassPs2
BaseClassMouse

BaseClassStorageDevice
BaseClassNetworkInterface
BaseClassKeyboard
BaseClassPrinter

BaseClassHub
BaseClassBraille
BaseClassScanner
BaseClassJoystick
BaseClassChipcard
BaseClassCamera

BaseClassFramebuffer
BaseClassDvb
BaseClassTv
BaseClassPartition
BaseClassDsl
BaseClassBluetooth
BaseClassFingerprint

BaseClassMmcController
BaseClassTouchpad
)

// SubClassKeyboard values of BaseClassKeyboard
//
//go:generate enumer -type=SubClassKeyboard -json -transform=snake -trimprefix SubClassKeyboard -output=./hardware_enum_sub_class_keyboard.go
type SubClassKeyboard uint16

const (
SubClassKeyboardKbd SubClassKeyboard = iota
SubClassKeyboardConsole
)

// SubClassMouse values of BaseClassMouse
//
//go:generate enumer -type=SubClassMouse -json -transform=snake -trimprefix SubClassMouse -output=./hardware_enum_sub_class_mouse.go
type SubClassMouse uint16

const (
SubClassMousePs2 SubClassMouse = iota
SubClassMouseSer
SubClassMouseBus
SubClassMouseUsb
SubClassMouseSun
SubClassMouseOther SubClassMouse = 0x80
)

// Slot represents a bus and slot number.
// Bits 0-7: slot number, 8-31 bus number
type Slot uint
Expand Down Expand Up @@ -260,6 +344,55 @@ const (
HotplugFirewire
)

// Bus types similar to PCI bridge subclasses
//
//go:generate enumer -type=Bus -json -transform=snake -trimprefix Bus -output=./hardware_enum_bus.go
type Bus uint16

const (
BusNone Bus = iota
BusIsa
BusEisa
BusMc
BusPci
BusPcmcia
BusNubus

BusCardbus
BusOther
)

const (
/** outside the range of the PCI values **/

BusPs2 Bus = iota + 0x80
BusSerial
BusParallel
BusFloppy
BusScsi
BusIde
BusUsb

BusAdb
BusRaid
BusSbus
BusI2o
BusVio
BusCcw
BusIucv
BusPs3SystemBus

BusVirtio
BusIbmebus
BusGameport
BusUisvirtpci
BusMmc
BusSdio
BusNd

BusNvme
)

// HardwareDevice represents a hardware component detected in the system.
type HardwareDevice struct {
// Index is a unique index provided by hwinfo, starting at 1
Expand Down
Loading

0 comments on commit 42e00a6

Please sign in to comment.