summaryrefslogtreecommitdiff
path: root/libs/surfaces/tranzport/lights.cc
blob: c0e8092f45290c48911a7929a09d407becca6528 (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
89
90
91
92
93
94
95
/*
 *   Copyright (C) 2006 Paul Davis 
 *   Copyright (C) 2007 Michael Taht
 *
 *   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.
 *
 *   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 General Public License
 *   along with this program; if not, write to the Free Software
 *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 *  
 *   */

#include <tranzport_control_protocol.h>

// Lights are buffered, and arguably these functions should be eliminated or inlined

void
TranzportControlProtocol::lights_on ()
{
	lights_pending.set();
}

void
TranzportControlProtocol::lights_off ()
{
	lights_pending.reset();
}

int
TranzportControlProtocol::light_on (LightID light)
{
	lights_pending.set(light);
	return 0;
}

int
TranzportControlProtocol::light_off (LightID light)
{
	lights_pending.reset(light);
	return 0;
}

void TranzportControlProtocol::lights_init()
{
	lights_invalid.set();
	lights_flash = lights_pending = lights_current.reset(); 
}


// Now that all this is bitsets, I don't see much 
// need for these 4 to remain in the API

void TranzportControlProtocol::light_validate (LightID light) 
{
	lights_invalid.reset(light);
}

void TranzportControlProtocol::light_invalidate (LightID light) 
{
	lights_invalid.set(light);
}

void TranzportControlProtocol::lights_validate () 
{
	lights_invalid.reset();
}

void TranzportControlProtocol::lights_invalidate () 
{
	lights_invalid.set();
}

int
TranzportControlProtocol::light_set (LightID light, bool offon)
{
	uint8_t cmd[8];
	cmd[0] = 0x00;  cmd[1] = 0x00;  cmd[2] = light;  cmd[3] = offon;
	cmd[4] = 0x00;  cmd[5] = 0x00;  cmd[6] = 0x00;  cmd[7] = 0x00;

	if (write (cmd) == 0) {
		lights_current[light] = offon;
		lights_invalid.reset(light);
		return 0;
	} else {
		return 1;
	}
}