blob: 99fd27f48ef9542b6d9452d3eb7f387c89e75fee [file] [log] [blame]
Kuiying Wanga9d39e32018-08-14 13:47:32 +08001/*
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 Mosesa1af3292021-12-15 11:47:01 +053019// add the button iface class to registry
20static ButtonIFRegister<IDButton> buttonRegister;
21
Kuiying Wanga9d39e32018-08-14 13:47:32 +080022void IDButton::simPress()
23{
24 pressed();
Naveen Mosesa1af3292021-12-15 11:47:01 +053025}
26
George Liu94afa4b2022-06-20 13:36:43 +080027void IDButton::handleEvent(sd_event_source* /* es */, int fd,
28 uint32_t /* revents */)
Naveen Mosesa1af3292021-12-15 11:47:01 +053029{
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}