summaryrefslogtreecommitdiffhomepage
path: root/digital/io/src/elevator.c
blob: 1843fb425a67e253dbb286c4c34b197ba96885b9 (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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/* elevator.c */
/* io - Input & Output with Artificial Intelligence (ai) support on AVR. {{{
 *
 * Copyright (C) 2009 Nicolas Haller
 *
 * APBTeam:
 *        Web: http://apbteam.org/
 *      Email: team AT apbteam DOT org
 *
 * 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 *
 * }}} */
#include "common.h"
#include "elevator.h"

/**
 * State of the elevator
 */
uint8_t elvt_is_ready = 0;

/**
 * nb puck in the elevator
 */
uint8_t elvt_nb_puck = 0;

/**
 * new_puck information (from filterbridge)
 */
uint8_t elvt_new_puck = 0;

/**
 * elevator orders
 */
elvt_order_e elvt_order_position = CLOSE;
uint8_t elvt_order_in_progress = 0;
uint8_t elvt_degraded_mode = 0;
uint8_t elvt_position_required = 0;

/**
 * We prepare the elevator
*/
void
elvt_prepare(uint8_t pos)
{
    if(elvt_order_position == CLOSE)
      {
	elvt_order_in_progress = 1;
	elvt_order_position = PREPARE;
	elvt_position_required = pos;
      }
    else /* if we are already prepared, just say it's done */
	elvt_order_in_progress = 0;
}

/**
 * We open the elevator
*/
void
elvt_open(uint8_t pos)
{
    if(elvt_order_position == PREPARE)
      {
	elvt_order_in_progress = 1;
	elvt_order_position = OPEN;
	elvt_position_required = pos;
	elvt_degraded_mode = 0;
      }
    else /* We are already open, just say it's done and whistle */
	elvt_order_in_progress = 0;
}

/**
 * We open the elevator in degradad mode
*/
void
elvt_open_degraded(uint8_t pos)
{
    if(elvt_order_position == PREPARE)
      {
	elvt_order_in_progress = 1;
	elvt_order_position = OPEN;
	elvt_position_required = pos;
	elvt_degraded_mode = 1;
      }
    else /* We are already open, just say it's done and whistle */
	elvt_order_in_progress = 0;
}


/**
 * We close the elevator and go away
*/
void
elvt_close(void)
{
    if(elvt_order_position == OPEN)
      {
	elvt_order_in_progress = 1;
	elvt_order_position = CLOSE;
      }
    else /* We are already close, just say it's done and play maracas */
	elvt_order_in_progress = 0;
}

/* +AutoDec */
/* -AutoDec */