root / trunk / programmer / test / main.c @ 160
History | View | Annotate | Download (2.66 KB)
1 |
/********
|
---|---|
2 |
* This file is part of Tooltron.
|
3 |
*
|
4 |
* Tooltron is free software: you can redistribute it and/or modify
|
5 |
* it under the terms of the Lesser GNU General Public License as published by
|
6 |
* the Free Software Foundation, either version 3 of the License, or
|
7 |
* (at your option) any later version.
|
8 |
*
|
9 |
* Tooltron is distributed in the hope that it will be useful,
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
12 |
* Lesser GNU General Public License for more details.
|
13 |
* You should have received a copy of the Lesser GNU General Public License
|
14 |
* along with Tooltron. If not, see <http://www.gnu.org/licenses/>.
|
15 |
*
|
16 |
* Copyright 2009 Kevin Woo <kwoo@2ndt.com>
|
17 |
*
|
18 |
********/
|
19 |
/** @file main.c
|
20 |
* @brief Contains the main function for the toolbox code.
|
21 |
*
|
22 |
* @author Suresh Nidhiry (snidhiry), Kevin Woo (kwoo)
|
23 |
*/
|
24 |
|
25 |
//Includes
|
26 |
#include <avr/io.h> |
27 |
#include <avr/interrupt.h> |
28 |
#include <stdint.h> |
29 |
#include <util/delay.h> |
30 |
|
31 |
#define RELAY _BV(PORTD4)
|
32 |
#define VAC_SENSE _BV(PIND3)
|
33 |
#define BUT_RED _BV(PINB4)
|
34 |
#define BUT_BLACK _BV(PINB3)
|
35 |
#define LED_GREEN _BV(PORTB2)
|
36 |
#define LED_YELLOW _BV(PORTB1)
|
37 |
#define LED_RED _BV(PORTB0)
|
38 |
#define ON 0x01 |
39 |
#define OFF 0x00 |
40 |
|
41 |
/***** change ADDR ****/
|
42 |
#define ADDR 18 |
43 |
#define DELIM '^' |
44 |
#define SERVER 1 |
45 |
#define TURNON 'O' |
46 |
|
47 |
/***
|
48 |
* TWAIT - minutes to wait before green button is pressed to kill power
|
49 |
* TWARN - minutes until warning (blink yellow, allow more time with green button)
|
50 |
* TMAX - minutes until power is killed (unless tool is on)
|
51 |
*/
|
52 |
#define TWAIT 1 |
53 |
#define TWARN 1 |
54 |
#define TMAX 2 |
55 |
|
56 |
uint8_t sec; |
57 |
uint8_t min; |
58 |
|
59 |
typedef enum { |
60 |
sd, // start delimitor
|
61 |
src, // src
|
62 |
dest, // destination
|
63 |
data, // data
|
64 |
cs, // checksum
|
65 |
ack, // send ack
|
66 |
pwron, // poweron
|
67 |
idiot, // user tried to hit green with the machine switch on
|
68 |
toolon, // tool on
|
69 |
warn, // time warning
|
70 |
off // tool off
|
71 |
} state_t; |
72 |
|
73 |
void init_pins(void) { |
74 |
DDRB = 0x00;
|
75 |
DDRB = _BV(DDB0) | _BV(DDB1) | _BV(DDB2) | _BV(DDB5); |
76 |
DDRD = _BV(DDB4); |
77 |
PORTB = 0x00;
|
78 |
} |
79 |
|
80 |
void toggle_led(uint8_t which, uint8_t state) {
|
81 |
if (state == ON) {
|
82 |
PORTB &= ~which; |
83 |
} else {
|
84 |
PORTB |= which; |
85 |
} |
86 |
} |
87 |
|
88 |
|
89 |
int main(int argc, char **argv) { |
90 |
state_t state = sd; |
91 |
uint8_t packet[3];
|
92 |
uint8_t ms_timer=0;
|
93 |
|
94 |
/***** Start Start-up Sequence *****/
|
95 |
init_pins(); //Set pin directions
|
96 |
// init_uart(51); //Set registers for uart
|
97 |
/***** End Start-up Sequence *****/
|
98 |
|
99 |
uint8_t r; |
100 |
|
101 |
while(1) { |
102 |
toggle_led(LED_GREEN, ON); |
103 |
_delay_ms(100);
|
104 |
toggle_led(LED_GREEN, OFF); |
105 |
_delay_ms(100);
|
106 |
} |
107 |
|
108 |
return 0; |
109 |
} |