My configuration files for Debian/Ubuntu applications
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

tp_smapi.md 4.0 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. # Description
  2. [`tp_smapi`](http://www.thinkwiki.org/wiki/Tp_smapi) interface and widget creator.
  3. ```lua
  4. local tp_smapi = lain.widget.contrib.tp_smapi(apipath)
  5. ```
  6. The argument `apipath` is an optional string which defines the API path. Its default value is `"/sys/devices/platform/smapi"`.
  7. # Functions
  8. ## tp_smapi.get(batid, feature)
  9. Gets the `feature` of battery `batid`. Returns a string. The list of available features is available at [this page](https://www.thinkwiki.org/wiki/Tp_smapi#Battery_status_features).
  10. ## tp_smapi.installed(batid)
  11. Checks if battery `batid` is installed. Returns a boolean.
  12. ## tp_smapi.status(batid)
  13. Gets the status of battery `batid`. Returns a string ("charging", "discharging", or "full").
  14. ## tp_smapi.percentage(batid)
  15. Gets the percentage of battery `batid`. Returns a numeric string.
  16. ## tp_smapi.time(batid)
  17. Gets the time of battery `batid`. Depending on the current status, it can be either running or charging time. Returns a string of the format `HH:MM`.
  18. ## tp_smapi.hide()
  19. Removes any notification spawned by `tp_smapi.show`.
  20. ## tp_smapi.show(batid, seconds, scr)
  21. Notifies the current information of battery `batid` for `seconds` seconds on screen `scr`.
  22. The argument `scr` is optional, and if missing, the notification will be displayed on the currently focused screen.
  23. ## tp_smapi.create_widget(args)
  24. Creates a [lain widget](https://github.com/lcpz/lain/wiki/Widgets#usage) of the available ThinkPad batteries.
  25. ```lua
  26. local tpbat = tp_smapi.create_widget()
  27. ```
  28. ### Input table
  29. Variable | Meaning | Type | Default
  30. --- | --- | --- | ---
  31. `widget` | The widget type to use | [`wibox.widget`](https://awesomewm.org/doc/api/classes/wibox.widget.html) | [`wibox.widget.textbox`](https://awesomewm.org/doc/api/classes/wibox.widget.textbox.html)
  32. `timeout` | Refresh timeout (in seconds) | integer | 30
  33. `pspath` | Power supply directory path | string | "/sys/class/power_supply/"
  34. `battery` | Single battery id | string | autodetected
  35. `batteries` | Multiple batteries id table | table of strings | autodetected
  36. `settings` | User settings | function | empty function
  37. `widget` | Widget to render | function | `wibox.widget.textbox`
  38. The widget will try to autodetect `battery` and `batteries`. If something
  39. goes wrong, you will have to define them manually. In that case, you only have
  40. to define one between `battery` and `batteries`. If you have one battery, you
  41. can either use `args.battery = "BAT*"` or `args.batteries = {"BAT*"}`, where `BAT*`
  42. is the identifier of your battery in `pspath` (do not use it as a wildcard).
  43. Of course, if you have multiple batteries, you need to use the latter option.
  44. If you define `pspath`, **be sure** to not forget the final slash (/).
  45. `settings` can use the `tpbat_now` table, which contains the following strings:
  46. - `status`, general status ("N/A", "discharging", "charging", "full");
  47. - `n_status[i]`, i-th battery status (like above);
  48. - `n_perc[i]`, i-th battery charge percentage (like above);
  49. - `n_time[i]`, i-th battery running or charging time (HH:MM string or "N/A");
  50. `n_time[i]` is the running time of battery `i` when it is discharging, and the charging time otherwise.
  51. ### Output table
  52. Variable | Meaning | Type
  53. --- | --- | ---
  54. `widget` | The widget | [`wibox.widget`](https://awesomewm.org/doc/api/classes/wibox.widget.html) | [textbox](https://awesomewm.org/doc/api/classes/wibox.widget.textbox.html)
  55. `batteries` | Battery identifiers | Table of strings
  56. `update` | Update `widget` | function
  57. `timer` | The widget timer | [`gears.timer`](https://awesomewm.org/doc/api/classes/gears.timer.html)
  58. The `update` function can be used to refresh the widget before `timeout` expires.
  59. ### Usage example
  60. ```lua
  61. local tp_smapi = lain.widget.contrib.tp_smapi()
  62. local bat = tp_smapi.create_widget {
  63. battery = "BAT0",
  64. settings = function()
  65. widget:set_markup(tpbat_now.n_perc[1] .. "%")
  66. end
  67. }
  68. bat.widget:connect_signal("mouse::enter", function () tp_smapi.show("BAT0") end)
  69. bat.widget:connect_signal("mouse::leave", function () tp_smapi.hide() end)
  70. ```