hardware

package
v0.0.0-...-81d58bd Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 31, 2024 License: GPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetBatteryHealth

func GetBatteryHealth(batteryStats *types.BatteryStats) (float64, error)

GetBatteryHealth calculates the battery health based on the battery statistics. It returns the battery health percentage.

Example:

batteryStats, err := hardware.GetBatteryStats()
if err != nil {
  fmt.Printf("Error: %v\n", err)
  return
}

batteryHealth, err := hardware.GetBatteryHealth(batteryStats)
if err != nil {
  fmt.Printf("Error: %v\n", err)
  return
}

fmt.Printf("Health: %f\n", batteryHealth)

func GetBatteryStats

func GetBatteryStats() (*types.BatteryStats, error)

GetBatteryStats retrieves battery statistics using sysfs. If the battery capacity information is not available, it returns nil assuming it's not a portable device.

Example:

batteryStats, err := hardware.GetBatteryStats()
if err != nil {
  fmt.Printf("Error: %v\n", err)
  return
}

fmt.Printf("Percentage: %d\n", batteryStats.Percentage)
fmt.Printf("Status: %s\n", batteryStats.Status)
fmt.Printf("Voltage: %d\n", batteryStats.Voltage)

func GetInputDevices

func GetInputDevices() ([]types.InputDevice, error)

GetInputDevices returns a list of input devices with specific details.

Example:

inputDevices, err := hardware.GetInputDevices()
if err != nil {
  fmt.Printf("Error: %v\n", err)
  return
}

for _, inputDevice := range inputDevices {
  fmt.Printf("Name: %s\n", inputDevice.Name)
  fmt.Printf("Product: %s\n", inputDevice.Product)
}

func GetMachineInfo

func GetMachineInfo() (types.MachineInfo, error)

func GetPCIDeviceByIDs

func GetPCIDeviceByIDs(vendorID, deviceID string) (types.PCIDeviceMapDevice, string, error)

GetPCIDeviceByIDs returns a PCIDeviceMapDevice by vendor ID and device ID, useful for getting the name of a PCI device or the vendor name. It returns an error if the device is not found.

Example:

device, vendorName, err := hardware.GetPCIDeviceByIDs("8086", "10f8")
if err != nil {
  fmt.Printf("Error: %v\n", err)
  return
}

fmt.Printf("Device name: %s\n", device.Name)
fmt.Printf("Vendor name: %s\n", vendorName)

func GetPCIDevices

func GetPCIDevices() ([]types.PCIDevice, error)

GetPCIDevices returns a list of PCI devices from /sys/bus/pci/devices.

Example:

pciDevices, err := hardware.GetPCIDevices()
if err != nil {
  fmt.Printf("Error: %v\n", err)
  return
}

for _, pciDevice := range pciDevices {
  fmt.Printf("ID: %s\n", pciDevice.ID)
}

func GetPeripheralList

func GetPeripheralList() ([]types.Peripheral, error)

GetPeripheralList returns a list of all system peripherals.

Example:

peripherals, err := hardware.GetPeripheralList()
if err != nil {
  fmt.Printf("Error: %v\n", err)
  return
}

for _, peripheral := range peripherals {
  fmt.Printf("ID: %s\n", peripheral.ID)
  fmt.Printf("Name: %s\n", peripheral.Name)
  fmt.Printf("Type: %s\n", peripheral.Type)
}

func LoadPCIDeviceMap

func LoadPCIDeviceMap() error

LoadPCIDeviceMap loads the PCI IDs from /usr/share/misc/pci.ids. This function should be called at the beginning of the program or before using any other function from this package.

# File syntax Syntax: # vendor vendor_name # device device_name <-- single tab # subvendor subdevice subsystem_name <-- two tabs # ...

Example:

err := hardware.Loadtypes.PCIDeviceMap()
if err != nil {
  fmt.Printf("Error: %v\n", err)
  return
}

Notes:

Subdevice is not supported yet.

func MapChassisType

func MapChassisType(chassisTypeID int) types.ChassisType

MapChassisType maps the chassis type to a standardized representation. Refer to https://www.dmtf.org/sites/default/files/standards/documents/DSP0134_3.7.0.pdf section 7.4.1 (System Enclosure or Chassis Types) and https://superuser.com/a/1107191 for more information.

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL