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