Kuiying Wang | a9d39e3 | 2018-08-14 13:47:32 +0800 | [diff] [blame] | 1 | /* |
| 2 | // Copyright (c) 2018 Intel 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 | |
| 17 | #include "id_button.hpp" |
| 18 | |
Naveen Moses | a1af329 | 2021-12-15 11:47:01 +0530 | [diff] [blame] | 19 | // add the button iface class to registry |
| 20 | static ButtonIFRegister<IDButton> buttonRegister; |
| 21 | |
Kuiying Wang | a9d39e3 | 2018-08-14 13:47:32 +0800 | [diff] [blame] | 22 | void IDButton::simPress() |
| 23 | { |
| 24 | pressed(); |
Naveen Moses | a1af329 | 2021-12-15 11:47:01 +0530 | [diff] [blame] | 25 | } |
| 26 | |
George Liu | 94afa4b | 2022-06-20 13:36:43 +0800 | [diff] [blame] | 27 | void IDButton::handleEvent(sd_event_source* /* es */, int fd, |
| 28 | uint32_t /* revents */) |
Naveen Moses | a1af329 | 2021-12-15 11:47:01 +0530 | [diff] [blame] | 29 | { |
| 30 | int n = -1; |
| 31 | char buf = '0'; |
| 32 | n = ::lseek(fd, 0, SEEK_SET); |
| 33 | |
| 34 | if (n < 0) |
| 35 | { |
| 36 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 37 | (getFormFactorType() + " : lseek error!").c_str()); |
| 38 | return; |
| 39 | } |
| 40 | |
| 41 | n = ::read(fd, &buf, sizeof(buf)); |
| 42 | if (n < 0) |
| 43 | { |
| 44 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 45 | (getFormFactorType() + " : read error!").c_str()); |
| 46 | return; |
| 47 | } |
| 48 | |
| 49 | if (buf == '0') |
| 50 | { |
| 51 | phosphor::logging::log<phosphor::logging::level::DEBUG>( |
| 52 | (getFormFactorType() + " : pressed").c_str()); |
| 53 | // emit pressed signal |
| 54 | pressed(); |
| 55 | } |
| 56 | else |
| 57 | { |
| 58 | phosphor::logging::log<phosphor::logging::level::DEBUG>( |
| 59 | (getFormFactorType() + " : released").c_str()); |
| 60 | // released |
| 61 | released(); |
| 62 | } |
| 63 | } |