2 * Copyright (C) 2006 Paul Davis
3 * Copyright (C) 2007 Michael Taht
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 /* The routines in here should know absolutely nothing about how io is actually done */
23 #include <tranzport_control_protocol.h>
26 TranzportControlProtocol::flush ()
30 // Always write the lights first
31 if(!(pending
= lights_flush())) {
32 pending
= screen_flush();
35 #if DEBUG_TRANZPORT_BITS > 9
37 if(s
= (screen_invalid
.count())) { // + lights_invalid.count())) {
38 printf("VALID : %s %s\n",
39 screen_invalid
.to_string().c_str(),
40 lights_invalid
.to_string().c_str());
41 printf("CURR : %s %s\n",
42 screen_invalid
.to_string().c_str(),
43 lights_current
.to_string().c_str());
44 printf("PENDING : %s %s\n",
45 screen_invalid
.to_string().c_str(),
46 lights_pending
.to_string().c_str());
47 #if DEBUG_TRANZPORT_BITS > 10
48 printf("invalid bits: %d\n",s
);
57 TranzportControlProtocol::lights_flush ()
59 std::bitset
<LIGHTS
> light_state
;
60 light_state
= lights_pending
^ lights_current
;
61 if ( (light_state
.none() || lights_invalid
.none()))
66 #if DEBUG_TRANZPORT_LIGHTS
67 printf("LPEND : %s\n", lights_pending
.to_string().c_str());
68 printf("LCURR : %s\n", lights_current
.to_string().c_str());
71 // if ever we thread reads/writes STATUS_OK will have to move into the loop
74 if ( _device_status
== STATUS_OK
|| _device_status
== STATUS_ONLINE
) {
75 for (i
= 0; i
<LIGHTS
; i
++) {
77 if(light_set ((LightID
)i
,lights_pending
[i
])) {
78 #if DEBUG_TRANZPORT_LIGHTS > 2
79 printf("Did %d light writes\n",i
);
81 return light_state
.count();
89 light_state
= lights_pending
^ lights_current
;
90 #if DEBUG_TRANZPORT_LIGHTS > 2
91 printf("Did %d light writes, left: %d\n",i
, light_state
.count());
94 return light_state
.count();