Subversion Repositories HomeAutomation

Rev

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

Rev 348 Rev 349
Line 1... Line 1...
1
/**
1
/**
2
 * CanCLCD. Simple version.
2
 * CanSimpleCLCD. Simple version.
3
 * For HD44780- and KS0073-based LCD displays
3
 * For HD44780- and KS0073-based LCD displays
-
 
4
 *
-
 
5
 * Contains no intelligence. It just prints what it is told to.
4
 *
6
 *
5
 * @date    2006-12-11
7
 * @date    2006-12-11
6
 * @author  Erik Larsson
8
 * @author  Erik Larsson
7
 *
9
 *
8
 */
10
 */
9
 
11
 
10
/*-----------------------------------------------------------------------------
12
/*-----------------------------------------------------------------------------
11
 * Includes
13
 * Includes
12
 *---------------------------------------------------------------------------*/
14
 *---------------------------------------------------------------------------*/
13
/* system files */
15
/* system files */
14
#include <avr/io.h>
16
#include <avr/io.h>
Line 18... Line 20...
18
#include <bios.h>
20
#include <bios.h>
19
#include <lcd_HD44780.h>
21
#include <lcd_HD44780.h>
20
/* funcdefs */
22
/* funcdefs */
21
#include <funcdefs.h>
23
#include <funcdefs.h>
22
 
24
 
-
 
25
/*-----------------------------------------------------------------------------
23
/* defines */
26
 * Defines
-
 
27
 *---------------------------------------------------------------------------*/
24
#define SIZE_X  20
28
#define SIZE_X  20
25
#define SIZE_Y  4
29
#define SIZE_Y  4
26
#define SIZE_LCD LCD_SIZE_20x4
30
#define SIZE_LCD LCD_SIZE_20x4
27
 
31
 
28
#define BUFFER_SIZE SIZE_X
32
#define BUFFER_SIZE SIZE_X
Line 39... Line 43...
39
 
43
 
40
uint8_t rot_lastdir = 0,
44
uint8_t rot_lastdir = 0,
41
        rot_laststate = 0;
45
        rot_laststate = 0;
42
 
46
 
43
    char buffer[ BUFFER_SIZE ];
47
char buffer[ BUFFER_SIZE ];
44
 
48
 
45
void send_dimensions();
49
void send_dimensions();
46
 
50
 
47
void can_receive(Can_Message_t *msg){
51
void can_receive(Can_Message_t *msg){
48
    uint32_t act;
52
    uint32_t act;
49
    uint8_t m, act_type, lcd_action, lcd_size;
53
    uint8_t m, act_type, lcd_action, lcd_size;
Line 76... Line 80...
76
                break;
80
                break;
77
            case LCD_ACTION_SET_CONT:
81
            case LCD_ACTION_SET_CONT:
78
                // Set contrast
82
                // Set contrast
79
                if(msg->DataLength == 1){
83
                if(msg->DataLength == 1){
80
                    OCR0B = msg->Data.bytes[0];
84
                    OCR0B = msg->Data.bytes[0];
81
                }
85
                }
82
                break;
86
                break;
83
            case LCD_ACTION_SET_BLIGHT:
87
            case LCD_ACTION_SET_BLIGHT:
84
                // Set backlight
88
                // Set backlight
85
                if(msg->DataLength == 1){
89
                if(msg->DataLength == 1){
86
                    OCR1AL = msg->Data.bytes[0];
90
                    OCR1AL = msg->Data.bytes[0];
87
                }
91
                }
Line 96... Line 100...
96
            case LCD_ACTION_GET_BLIGHT:
100
            case LCD_ACTION_GET_BLIGHT:
97
                // Get backlight
101
                // Get backlight
98
                txMsg.DataLength = 1;
102
                txMsg.DataLength = 1;
99
                txMsg.Id = ( CLASS_ACT<<CLASS_MASK_BITS )|( ACT_TYPE_LCD<<ACT_TYPE_BITS )|( LCD_ACTION_SEND_BLIGHT<<LCD_ACTION_BITS )|NODE_ID;
103
                txMsg.Id = ( CLASS_ACT<<CLASS_MASK_BITS )|( ACT_TYPE_LCD<<ACT_TYPE_BITS )|( LCD_ACTION_SEND_BLIGHT<<LCD_ACTION_BITS )|NODE_ID;
100
                txMsg.Data.bytes[0] = OCR1AL;
104
                txMsg.Data.bytes[0] = OCR1AL;
101
                bios->can_send(&txMsg);
105
                bios->can_send(&txMsg);
102
                break;
106
                break;
103
            default:
107
            default:
104
                // Take over the world
108
                // Take over the world
105
                break;
109
                break;
106
        }
110
        }
107
    }
111
    }
108
}
112
}
109
 
-
 
110
 
113
 
111
ISR( PCINT0_vect ){ // For ROTENC_A and ROTENC_B
114
ISR( PCINT0_vect ){ // For ROTENC_A and ROTENC_B
112
    uint8_t rot_data = 0;
115
    uint8_t rot_data = 0;
113
 
116
 
114
    txMsg.Id = ( CLASS_SNS<<CLASS_MASK_BITS )|( SNS_ACT_BUTTON<<SNS_TYPE_BITS )|( 0x01<<SNS_ID_BITS )| NODE_ID;
117
    txMsg.Id = ( CLASS_SNS<<CLASS_MASK_BITS )|( SNS_ACT_BUTTON<<SNS_TYPE_BITS )|( 0x01<<SNS_ID_BITS )| NODE_ID;
Line 134... Line 137...
134
                }
137
                }
135
            }else{
138
            }else{
136
                // Moving left
139
                // Moving left
137
                txMsg.Data.bytes[0]=LEFT;
140
                txMsg.Data.bytes[0]=LEFT;
138
                txMsg.Data.bytes[1] = (PIND&(1<<PD2))?0:1;
141
                txMsg.Data.bytes[1] = (PIND&(1<<PD2))?0:1;
139
                bios->can_send(&txMsg);
142
                bios->can_send(&txMsg);
140
                // For testing TODO remove
143
                // For testing TODO remove
141
                if(OCR1A>0){
144
                if(OCR1A>0){
142
                    OCR1A--;
145
                    OCR1A--;
143
                }
146
                }
144
            }
147
            }
145
        }
148
        }
146
        rot_laststate = rot_data;
149
        rot_laststate = rot_data;
147
    }else{
150
    }else{
148
        rot_lastdir = rot_data;
151
        rot_lastdir = rot_data;
149
    }
152
    }
150
}
153
}
151
 
154
 
152
ISR( PCINT2_vect ){ // For ROTENC_BTN
155
ISR( PCINT2_vect ){ // For ROTENC_BTN
153
    txMsg.Id = ( CLASS_SNS<<CLASS_MASK_BITS )|( SNS_ACT_BUTTON<<SNS_TYPE_BITS )|( 0x02<<SNS_ID_BITS )| NODE_ID;
156
    txMsg.Id = ( CLASS_SNS<<CLASS_MASK_BITS )|( SNS_ACT_BUTTON<<SNS_TYPE_BITS )|( 0x02<<SNS_ID_BITS )| NODE_ID;
154
    txMsg.Data.bytes[0] = (PIND&(1<<PD2))?0:1; // Check if buton is pressed or not
157
    txMsg.Data.bytes[0] = (PIND&(1<<PD2))?0:1; // Check if buton is pressed or not
155
    txMsg.DataLength=1;
158
    txMsg.DataLength=1;
156
    bios->can_send(&txMsg);
159
    bios->can_send(&txMsg);
157
}
160
}
158
 
-
 
159
 
161
 
160
/*-----------------------------------------------------------------------------
162
/*-----------------------------------------------------------------------------
161
 * Main Program
163
 * Main Program
162
 *---------------------------------------------------------------------------*/
164
 *---------------------------------------------------------------------------*/
163
int main(void) {
165
int main(void) {