Subversion Repositories HomeAutomation

Rev

Rev 334 | Rev 344 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed

Rev 334 Rev 335
Line 1... Line 1...
1
/**
1
/**
2
 * CAN LCD.
2
 * CanCLCD.
3
 * For HD44780- and KS0073-based LCD displays
3
 * For HD44780- and KS0073-based LCD displays
4
 * This is the early version that only prints temperature sensor data.
4
 * Prints sensor data and other interesting things.
5
 *
5
 *
6
 * @date    2006-12-11
6
 * @date    2006-12-11
7
 * @author  Erik Larsson
7
 * @author  Erik Larsson
8
 *
8
 *
9
 * TODO Fix more types of output: relay status, mail recieved etc.
9
 * TODO Fix more types of output: relay status, mail recieved etc.
10
 * Make it configurable to use UART, because it's not necessary on the final PCB
-
 
11
 *
10
 *
12
 */
11
 */
13
 
12
 
14
/*-----------------------------------------------------------------------------
13
/*-----------------------------------------------------------------------------
15
 * Includes
14
 * Includes
Line 26... Line 25...
26
//#include <global_funcdefs.h>
25
//#include <global_funcdefs.h>
27
#include <eqlazer_funcdefs.h>
26
#include <eqlazer_funcdefs.h>
28
 
27
 
29
/* defines */
28
/* defines */
30
#define BUFFER_SIZE 20
29
#define BUFFER_SIZE 20
31
#define BOUNCE_TIME 10
-
 
32
#define TRUE 1
30
#define TRUE 1
33
#define FALSE 0
31
#define FALSE 0
34
 
32
 
35
uint8_t currentView = MAIN_VIEW, msg_received = FALSE, encoderPosition, rot = FALSE;
-
 
36
Can_Message_t rxMsg;
33
Can_Message_t rxMsg;
-
 
34
 
-
 
35
uint8_t currentView = MAIN_VIEW,
-
 
36
        msg_received = FALSE;
-
 
37
 
37
uint8_t temperatureData[8], servoPosition[4], //relayStatus[4], dimmerStatus[4],
38
uint8_t temperatureData[8],
-
 
39
        servoPosition[4],
-
 
40
        //relayStatus[4],
-
 
41
        //dimmerStatus[4],
-
 
42
        temperatureLength = 8,
-
 
43
        servoLength = 0;
38
            temperatureLength = 8, servoLength = 0; //, relayLength=0; //TODO mer generaliserat
44
        //, relayLength=0; //TODO mer generaliserat
-
 
45
 
39
uint32_t rot_timeStamp;
46
uint8_t rot_lastdir = 0,
40
char buf[10];
47
        rot_laststate = 0;
41
 
48
 
42
ISR( PCINT2_vect ){
49
ISR( PCINT2_vect ){
-
 
50
    uint8_t rot_data = 0;
43
 
51
 
-
 
52
    if(PIND&(1<<PD6)){
-
 
53
        rot_data |= 0x01;
-
 
54
    }
-
 
55
    if(PIND&(1<<PD7)){
-
 
56
        rot_data |= 0x02;
-
 
57
    }
-
 
58
 
44
    rot_timeStamp = bios->timebase_get();
59
    if( rot_data==3 && rot_laststate!=3 ){
-
 
60
        if( rot_lastdir&0x01 ){
-
 
61
            // Moving left
-
 
62
            if(currentView>0){
-
 
63
                currentView--;
-
 
64
                msg_received = TRUE;
-
 
65
            }
-
 
66
        }else{
-
 
67
            // Moving right
-
 
68
            if(currentView<LAST_VIEW){
-
 
69
                currentView++;
45
    rot = TRUE;
70
                msg_received = TRUE;
-
 
71
            }
-
 
72
        }
-
 
73
        rot_laststate=3;
-
 
74
    }else if( rot_data==0 && rot_laststate!=0 ){
-
 
75
        rot_laststate = 0;
46
    /* stäng av interrupt  pinnarna */
76
    }else if( rot_data==1 || rot_data==2 ){
47
    PCICR &= ~(1<<PCIE2);
77
        rot_lastdir = rot_data;
-
 
78
    }
48
}
79
}
49
 
80
 
50
void can_receive(Can_Message_t *msg){
81
void can_receive(Can_Message_t *msg){
51
    uint8_t temp, m;
82
    uint8_t temp, m;
52
    /* Check for incoming messages from IR-receiver node */
83
    /* Check for incoming messages from IR-receiver node */
Line 62... Line 93...
62
                    msg_received = TRUE;
93
                    msg_received = TRUE;
63
                }else if(msg->Data.bytes[3] == 6 && currentView<LAST_VIEW){
94
                }else if(msg->Data.bytes[3] == 6 && currentView<LAST_VIEW){
64
                    currentView++;
95
                    currentView++;
65
                    msg_received = TRUE;
96
                    msg_received = TRUE;
66
                }
97
                }
67
            }
98
            }
68
        }
99
        }
69
        /* Other sensor messages should be placed here */
100
        /* Other sensor messages should be placed here */
70
 
101
 
71
        /* DS18S20 sensors */
102
        /* DS18S20 sensors */
72
        if( SNS_TEMP_DS18S20 == (msg->Id & SNS_TYPE_MASK)>>SNS_TYPE_BITS ){
103
        if( SNS_TEMP_DS18S20 == (msg->Id & SNS_TYPE_MASK)>>SNS_TYPE_BITS ){
73
            temp = (msg->Id & SNS_ID_MASK)>>SNS_ID_BITS;
104
            temp = (msg->Id & SNS_ID_MASK)>>SNS_ID_BITS;
Line 80... Line 111...
80
            temp = msg->DataLength - 3;
111
            temp = msg->DataLength - 3;
81
            for(m=0;m<temp;m++){
112
            for(m=0;m<temp;m++){
82
                servoPosition[ m ] = msg->Data.bytes[m+3];
113
                servoPosition[ m ] = msg->Data.bytes[m+3];
83
            }
114
            }
84
            servoLength = temp;
115
            servoLength = temp;
85
        }
116
        }
86
 
117
 
87
    }
118
    }
88
}
119
}
89
 
120
 
90
 
121
 
91
/*-----------------------------------------------------------------------------
122
/*-----------------------------------------------------------------------------
92
 * Main Program
123
 * Main Program
93
 *---------------------------------------------------------------------------*/
124
 *---------------------------------------------------------------------------*/
Line 95... Line 126...
95
 
126
 
96
    char buffer[ BUFFER_SIZE ];
127
    char buffer[ BUFFER_SIZE ];
97
    /*
128
    /*
98
     * Initialize rotaryencoders and buttons
129
     * Initialize rotaryencoders and buttons
99
     */
130
     */
100
    /* Set as input and enable pull-up */
131
    /* Set as input */
101
    DDRD &= ~( (1<<DDD6)|(1<<DDD7) );
132
    DDRD &= ~( (1<<DDD6)|(1<<DDD7) );
102
//    PORTD |= (1<<PD6)|(1<<PD7);
-
 
103
    /* Enable IO-pin interrupt */
133
    /* Enable IO-pin interrupt */
104
//    PCICR |= (1<<PCIE2);
134
    PCICR |= (1<<PCIE2);
105
    /* Unmask PD6 and PD7 */
135
    /* Unmask PD6 and PD7 */
106
    PCMSK2 |= (1<<PCINT22)|(1<<PCINT23);
136
    PCMSK2 |= (1<<PCINT22)|(1<<PCINT23);
107
 
137
 
108
    sei();
138
    sei();
109
    bios->can_callback = &can_receive;
139
    bios->can_callback = &can_receive;
110
 
140
 
111
    lcd_init( LCD_DISP_ON );
141
    lcd_init( LCD_DISP_ON );
112
    lcd_clrscr();
142
    lcd_clrscr();
113
 
143
 
114
    lcd_clrscr();
144
    lcd_clrscr();
115
    printLCDview( MAIN_VIEW );
145
    printLCDview( MAIN_VIEW );
116
 
146
 
117
    /* main loop */
147
    /* main loop */
118
    while(1){
148
    while(1){
119
        /* check if any messages have been received */
149
        /* check if any messages have been received */
Line 125... Line 155...
125
            }else if(currentView == SERVO_VIEW){
155
            }else if(currentView == SERVO_VIEW){
126
                printLCDviewData( SERVO_VIEW, servoPosition, servoLength);
156
                printLCDviewData( SERVO_VIEW, servoPosition, servoLength);
127
            }
157
            }
128
            msg_received = FALSE;
158
            msg_received = FALSE;
129
        }
159
        }
130
 
-
 
131
        // TODO använd rotary encoders för att växla view
-
 
132
        // också med fjärrkontroll
-
 
133
/*      if((bios->timebase_get() - rot_timeStamp >= BOUNCE_TIME) && rot == TRUE){
-
 
134
            PCICR |= (1<<PCIE2);
-
 
135
            rot = FALSE;
-
 
136
        }*/
-
 
137
    }
160
    }
138
 
-
 
139
 
-
 
140
}
161
}