Brad Bishop | f138c56 | 2017-06-15 23:08:09 -0400 | [diff] [blame] | 1 | /** |
| 2 | * Copyright © 2017 IBM Corporation |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Brad Bishop | f138c56 | 2017-06-15 23:08:09 -0400 | [diff] [blame] | 17 | #include "evdevpp/evdev.hpp" |
George Liu | 8426b2d | 2023-08-15 17:47:13 +0800 | [diff] [blame] | 18 | |
| 19 | #include <CLI/CLI.hpp> |
Matthew Barth | ebd1537 | 2020-05-28 11:42:38 -0500 | [diff] [blame] | 20 | // TODO https://github.com/openbmc/phosphor-fan-presence/issues/22 |
| 21 | // #include "sdevent/event.hpp" |
| 22 | // #include "sdevent/io.hpp" |
Brad Bishop | f138c56 | 2017-06-15 23:08:09 -0400 | [diff] [blame] | 23 | #include "utility.hpp" |
| 24 | |
Matthew Barth | 11fc0a7 | 2020-05-26 10:55:54 -0500 | [diff] [blame] | 25 | #include <algorithm> |
| 26 | #include <cassert> |
| 27 | #include <iostream> |
| 28 | #include <iterator> |
| 29 | #include <memory> |
| 30 | |
Brad Bishop | f138c56 | 2017-06-15 23:08:09 -0400 | [diff] [blame] | 31 | int main(int argc, char* argv[]) |
| 32 | { |
George Liu | 8426b2d | 2023-08-15 17:47:13 +0800 | [diff] [blame] | 33 | CLI::App app{"evmon utility"}; |
Brad Bishop | f138c56 | 2017-06-15 23:08:09 -0400 | [diff] [blame] | 34 | |
George Liu | 8426b2d | 2023-08-15 17:47:13 +0800 | [diff] [blame] | 35 | std::string path{}; |
| 36 | std::string stype{}; |
| 37 | std::string scode{}; |
Brad Bishop | f138c56 | 2017-06-15 23:08:09 -0400 | [diff] [blame] | 38 | |
George Liu | 8426b2d | 2023-08-15 17:47:13 +0800 | [diff] [blame] | 39 | app.add_option("-p,--path", path, "evdev devpath")->required(); |
| 40 | app.add_option("-t,--type", stype, "evdev type")->required(); |
| 41 | app.add_option("-c,--code", scode, "evdev code")->required(); |
| 42 | |
| 43 | try |
Brad Bishop | f138c56 | 2017-06-15 23:08:09 -0400 | [diff] [blame] | 44 | { |
George Liu | 8426b2d | 2023-08-15 17:47:13 +0800 | [diff] [blame] | 45 | app.parse(argc, argv); |
Brad Bishop | f138c56 | 2017-06-15 23:08:09 -0400 | [diff] [blame] | 46 | } |
George Liu | 8426b2d | 2023-08-15 17:47:13 +0800 | [diff] [blame] | 47 | catch (const CLI::Error& e) |
| 48 | { |
| 49 | return app.exit(e); |
| 50 | } |
| 51 | |
| 52 | unsigned int type = EV_KEY; |
| 53 | if (!stype.empty()) |
Brad Bishop | f138c56 | 2017-06-15 23:08:09 -0400 | [diff] [blame] | 54 | { |
| 55 | type = stoul(stype); |
| 56 | } |
| 57 | |
Matthew Barth | ebd1537 | 2020-05-28 11:42:38 -0500 | [diff] [blame] | 58 | // TODO https://github.com/openbmc/phosphor-fan-presence/issues/22 |
| 59 | // auto loop = sdevent::event::newDefault(); |
Brad Bishop | f138c56 | 2017-06-15 23:08:09 -0400 | [diff] [blame] | 60 | phosphor::fan::util::FileDescriptor fd( |
Matthew Barth | 11fc0a7 | 2020-05-26 10:55:54 -0500 | [diff] [blame] | 61 | open(path.c_str(), O_RDONLY | O_NONBLOCK)); |
Brad Bishop | f138c56 | 2017-06-15 23:08:09 -0400 | [diff] [blame] | 62 | auto evdev = evdevpp::evdev::newFromFD(fd()); |
Matthew Barth | ebd1537 | 2020-05-28 11:42:38 -0500 | [diff] [blame] | 63 | // sdevent::event::io::IO callback(loop, fd(), [&evdev](auto& s) { |
| 64 | // unsigned int type, code, value; |
| 65 | // std::tie(type, code, value) = evdev.next(); |
| 66 | // std::cout << "type: " << libevdev_event_type_get_name(type) |
| 67 | // << " code: " << libevdev_event_code_get_name(type, code) |
| 68 | // << " value: " << value << "\n"; |
| 69 | // }); |
Brad Bishop | f138c56 | 2017-06-15 23:08:09 -0400 | [diff] [blame] | 70 | |
| 71 | auto value = evdev.fetch(type, stoul(scode)); |
Matthew Barth | 11fc0a7 | 2020-05-26 10:55:54 -0500 | [diff] [blame] | 72 | std::cout << "type: " << libevdev_event_type_get_name(type) |
| 73 | << " code: " << libevdev_event_code_get_name(type, stoul(scode)) |
| 74 | << " value: " << value << "\n"; |
Brad Bishop | f138c56 | 2017-06-15 23:08:09 -0400 | [diff] [blame] | 75 | |
Matthew Barth | ebd1537 | 2020-05-28 11:42:38 -0500 | [diff] [blame] | 76 | // loop.loop(); |
Brad Bishop | f138c56 | 2017-06-15 23:08:09 -0400 | [diff] [blame] | 77 | |
| 78 | return 0; |
| 79 | } |