aboutsummaryrefslogtreecommitdiffstats
path: root/src/osmo-bts-litecell15/hw_misc.c
blob: 9f070bba9d4a674f840434924e3494a8f5bf1a3b (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
82
83
84
85
86
87
88
/* Misc HW routines for NuRAN Wireless Litecell 1.5 BTS */

/* Copyright (C) 2015 by Yves Godin <support@nuranwireless.com>
 * 
 * Based on sysmoBTS:
 * 	(C) 2012 by Harald Welte <laforge@gnumonks.org>
 *
 * All Rights Reserved
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

#include <stdint.h>
#include <unistd.h>
#include <limits.h>
#include <fcntl.h>
#include <errno.h>
#include <stdio.h>
#include <string.h>

#include <sys/types.h>
#include <sys/stat.h>

#include <osmocom/core/utils.h>

#include "hw_misc.h"

int lc15bts_led_set(enum lc15bts_led_color c)
{
	int fd, rc;
	uint8_t cmd[2];

	switch (c) {	
	case LED_OFF:
		cmd[0] = 0;
		cmd[1] = 0;
		break;
	case LED_RED:
		cmd[0] = 1;
		cmd[1] = 0;
		break;
	case LED_GREEN:
		cmd[0] = 0;
		cmd[1] = 1;
		break;
	case LED_ORANGE:
		cmd[0] = 1;
		cmd[1] = 1;
		break;
	default:
		return -EINVAL;
	}

	fd = open("/var/lc15/leds/led0/brightness", O_WRONLY);
	if (fd < 0)
		return -ENODEV;

	rc = write(fd, cmd[0] ? "1" : "0", 2);
	if (rc != 2) {
		close(fd);
		return -1;
	}
	close(fd);

	fd = open("/var/lc15/leds/led1/brightness", O_WRONLY);
	if (fd < 0)
		return -ENODEV;

	rc = write(fd, cmd[1] ? "1" : "0", 2);
	if (rc != 2) {
		close(fd);
		return -1;
	}
	close(fd);
	return 0;
}