Function: battery--search-haiku-acpi-status

battery--search-haiku-acpi-status is a byte-compiled function defined in battery.el.gz.

Signature

(battery--search-haiku-acpi-status)

Documentation

Search forward for battery status in the current buffer.

Return a property list once all relevant properties are found. The following properties may be inside the list:

  - :capacity (the current capacity of the battery.)
  - :voltage (the current voltage of the battery.)
  - :rate, (the current rate of charge or discharge.)
  - :state (the current state of the battery.)
  - :design-capacity (the design capacity of the battery.)
  - :design-voltage (the design voltage of the battery.)
  - :last-full-charge (the capacity at the last full charge of
    the battery.)

:capacity and :design-capacity are both represented in
terms of milliamp-hours.

Source Code

;; Defined in /usr/src/emacs/lisp/battery.el.gz
;;; `/dev/power/acpi_battery' interface for Haiku.

(defun battery--search-haiku-acpi-status ()
  "Search forward for battery status in the current buffer.
Return a property list once all relevant properties are found.
The following properties may be inside the list:

  - `:capacity' (the current capacity of the battery.)
  - `:voltage' (the current voltage of the battery.)
  - `:rate', (the current rate of charge or discharge.)
  - `:state' (the current state of the battery.)
  - `:design-capacity' (the design capacity of the battery.)
  - `:design-voltage' (the design voltage of the battery.)
  - `:last-full-charge' (the capacity at the last full charge of
    the battery.)

`:capacity' and `:design-capacity' are both represented in
terms of milliamp-hours."
  (let ((state-regexp "State \\([[:digit:]]+\\), Current Rate \\([[:digit:]]+\\), \
Capacity \\([[:digit:]]+\\), Voltage \\([[:digit:]]+\\)")
        (pu-regexp "Power Unit \\([[:digit:]]\\)+, Design Capacity \\([[:digit:]]+\\), \
Last Full Charge \\([[:digit:]]+\\)")
        (design-regexp "Design Voltage \\([[:digit:]]+\\)")
        power-unit last-full-charge state rate capacity
        voltage design-capacity design-voltage)
    (when (re-search-forward state-regexp)
      (setq state (string-to-number (match-string 1)))
      (setq rate (string-to-number (match-string 2)))
      (setq capacity (string-to-number (match-string 3)))
      (setq voltage (/ (string-to-number (match-string 4)) 1000.0)))
    (when (re-search-forward pu-regexp)
      (setq power-unit (string-to-number (match-string 1)))
      (setq design-capacity (string-to-number (match-string 2)))
      (setq last-full-charge (string-to-number (match-string 3))))
    (when (re-search-forward design-regexp)
      (setq design-voltage (/ (string-to-number (match-string 1)) 1000.0)))
    ;; Convert capacity fields to milliamp-hours if they're
    ;; specified as miliwatt-hours.
    (when (eq power-unit 0)
      (setq capacity (/ capacity voltage))
      (setq design-capacity (/ design-capacity design-voltage))
      (setq last-full-charge (/ last-full-charge voltage)))
    (list :capacity capacity :voltage voltage
          :rate rate :state (cond
                             ((not (zerop (logand state 2))) 'charging)
                             ((not (zerop (logand state 1))) 'discharging)
                             ((not (zerop (logand state 4))) 'critical)
                             (t 'fully-charged))
          :design-capacity design-capacity
          :design-voltage design-voltage
          :last-full-charge last-full-charge)))