blob: 71e853999dc697241ed9feadfe867a15ddca5817 [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
27void IDButton::handleEvent(sd_event_source* es, int fd, uint32_t revents)
28{
29 int n = -1;
30 char buf = '0';
31 n = ::lseek(fd, 0, SEEK_SET);
32
33 if (n < 0)
34 {
35 phosphor::logging::log<phosphor::logging::level::ERR>(
36 (getFormFactorType() + " : lseek error!").c_str());
37 return;
38 }
39
40 n = ::read(fd, &buf, sizeof(buf));
41 if (n < 0)
42 {
43 phosphor::logging::log<phosphor::logging::level::ERR>(
44 (getFormFactorType() + " : read error!").c_str());
45 return;
46 }
47
48 if (buf == '0')
49 {
50 phosphor::logging::log<phosphor::logging::level::DEBUG>(
51 (getFormFactorType() + " : pressed").c_str());
52 // emit pressed signal
53 pressed();
54 }
55 else
56 {
57 phosphor::logging::log<phosphor::logging::level::DEBUG>(
58 (getFormFactorType() + " : released").c_str());
59 // released
60 released();
61 }
62}