summaryrefslogtreecommitdiffstats
path: root/kbiff/led.cpp
blob: cc27d71997b1bd8b43f583631b8905efa107bf8a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/***************************************************************************
                          led.cpp  -  description
                             -------------------
    begin                : do okt 9 2003
    copyright            : (C) 2003 by Roeland Merks
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include "led.h"

#ifdef HAVE_MLED
#include <fstream>
#include <string>
#include <fstream>
#include <iostream>
using namespace std;

const char *ASUS_ACPI="/proc/acpi/asus/";

Led::Led()
{
  Led("wled");
}

Led::Led(const char *ledname)
{
  string fname(string(ASUS_ACPI)+string(ledname));

  led=new ofstream(fname.c_str());

  // If there is no LED, just give a one time warning on cerr
  if (!(*led)) {
    static bool error_given=false;
    if (!error_given) {
      cerr << "Warning: trying to use Asus LED, but no ACPI-entry found.\n";
      error_given=true;
    }
  }
}

Led::~Led()
{
  Off();
  delete led;
}


void Led::On()
{
  if (*led) {
    *led << 1;
    led->flush();
  }
}

void Led::Off()
{
  if (*led) {
    *led << 0;
    led->flush();
  }
}
#else
Led::Led() {}
Led::Led(const char *) {}
Led::~Led() {}
void Led::On() {}
void Led::Off() {}
#endif