Subversion Repositories HomeAutomation

Rev

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

Rev 563 Rev 605
Line 19... Line 19...
19
#include <stdio.h>
19
#include <stdio.h>
20
/* lib files */
20
/* lib files */
21
#include <bios.h>
21
#include <bios.h>
22
#include <config.h>
22
#include <config.h>
23
#include <drivers/lcd/clcd/lcd_HD44780.h>
23
#include <drivers/lcd/clcd/lcd_HD44780.h>
-
 
24
 
-
 
25
#include <string.h> //for memcpy
-
 
26
 
-
 
27
 
24
/* funcdefs */
28
/* funcdefs */
25
#include <funcdefs/funcdefs.h>
29
//#include <funcdefs/funcdefs.h>
-
 
30
 
-
 
31
 
-
 
32
//a lot of crap from previous funcdefs
-
 
33
/* ACT LCD 12 bits <ACTION><SIZE> 0xFFFL
-
 
34
 *
-
 
35
 * <ACTION>, 4 bits = Type och action.
-
 
36
 * <SIZE>, 8 bits = Size of display.
-
 
37
 */
-
 
38
#define LCD_ACTION_MASK 0xF00L /* bit[12..8] */
-
 
39
#define LCD_SIZE_MASK 0x0FFL /* bit[7..0] */
-
 
40
 
-
 
41
#define LCD_ACTION_BITS 8
-
 
42
#define LCD_SIZE_BITS 0
-
 
43
 
-
 
44
 
-
 
45
/* <ACTION> 4 bits 0xFL */
-
 
46
 
-
 
47
#define LCD_ACTION_CLR          0x0L
-
 
48
#define LCD_ACTION_CURS         0x1L
-
 
49
#define LCD_ACTION_TEXT         0x2L
-
 
50
#define LCD_ACTION_GET_SIZE     0x3L
-
 
51
#define LCD_ACTION_SET_CONT     0x4L
-
 
52
#define LCD_ACTION_SET_BLIGHT   0x5L
-
 
53
#define LCD_ACTION_GET_CONT     0x6L
-
 
54
#define LCD_ACTION_GET_BLIGHT   0x7L
-
 
55
 
-
 
56
#define LCD_ACTION_SEND_CONT    0x8L
-
 
57
#define LCD_ACTION_SEND_BLIGHT  0x9L
-
 
58
 
-
 
59
 
-
 
60
 
-
 
61
/* <SIZE> 8 bits 0xFFL */
-
 
62
#define LCD_SIZE_ALL    0x00L
-
 
63
#define LCD_SIZE_16x2   0x02L
-
 
64
#define LCD_SIZE_20x4   0x10L
-
 
65
 
-
 
66
 
26
 
67
 
27
/*-----------------------------------------------------------------------------
68
/*-----------------------------------------------------------------------------
28
 * Defines
69
 * Defines
29
 *---------------------------------------------------------------------------*/
70
 *---------------------------------------------------------------------------*/
30
#define SIZE_X  20
71
#define SIZE_X  20
Line 44... Line 85...
44
uint8_t rxMsgFull;
85
uint8_t rxMsgFull;
45
 
86
 
46
 
87
 
47
char buffer[ BUFFER_SIZE ];
88
char buffer[ BUFFER_SIZE ];
48
 
89
 
49
void send_dimensions();
90
void send_dimensions(void);
50
void rotenc();
91
void rotenc(void);
51
 
92
 
52
// CAN message reception callback
93
// CAN message reception callback
53
// This function runs with interrupts disabled, keep it as short as possible
94
// This function runs with interrupts disabled, keep it as short as possible
54
void can_receive(Can_Message_t *msg){
95
void can_receive(Can_Message_t *msg){
55
    if(!rxMsgFull){
96
    if(!rxMsgFull){
Line 120... Line 161...
120
 
161
 
121
    /* main loop */
162
    /* main loop */
122
    while(1){
163
    while(1){
123
        /* check if any messages have been received */
164
        /* check if any messages have been received */
124
        if(rxMsgFull){
165
        if(rxMsgFull){
125
 
-
 
-
 
166
/* FIXME noddan kommenterar bort allt
126
            if( ((rxMsg.Id & CLASS_MASK)>> CLASS_MASK_BITS) == CLASS_ACT ){ // FIXME ett jäkla herk, städa upp
167
            if( ((rxMsg.Id & CLASS_MASK)>> CLASS_MASK_BITS) == CLASS_ACT ){ // FIXME ett jäkla herk, städa upp
127
                act = (rxMsg.Id & TYPE_MASK) >> TYPE_MASK_BITS;
168
                act = (rxMsg.Id & TYPE_MASK) >> TYPE_MASK_BITS;
128
                act_type = (act & ACT_TYPE_MASK) >> ACT_TYPE_BITS;
169
                act_type = (act & ACT_TYPE_MASK) >> ACT_TYPE_BITS;
129
                lcd_action = (act & LCD_ACTION_MASK) >> LCD_ACTION_BITS;
170
                lcd_action = (act & LCD_ACTION_MASK) >> LCD_ACTION_BITS;
130
                lcd_size = (act & LCD_SIZE_MASK) >> LCD_SIZE_BITS;
171
                lcd_size = (act & LCD_SIZE_MASK) >> LCD_SIZE_BITS;
Line 161... Line 202...
161
                            OCR1AL = rxMsg.Data.bytes[0];
202
                            OCR1AL = rxMsg.Data.bytes[0];
162
                        }
203
                        }
163
                    break;
204
                    break;
164
                    case LCD_ACTION_GET_CONT:
205
                    case LCD_ACTION_GET_CONT:
165
                        // Get contrast
206
                        // Get contrast
166
                        txMsg.DataLength = 1;
207
                        txMsg.DataLength = 1;
167
                        txMsg.Id = ( CLASS_ACT<<CLASS_MASK_BITS )|( ACT_TYPE_LCD<<ACT_TYPE_BITS )|( LCD_ACTION_SEND_CONT<<LCD_ACTION_BITS )|NODE_ID;
208
                        txMsg.Id = ( CLASS_ACT<<CLASS_MASK_BITS )|( ACT_TYPE_LCD<<ACT_TYPE_BITS )|( LCD_ACTION_SEND_CONT<<LCD_ACTION_BITS )|NODE_ID;
168
                        txMsg.Data.bytes[0] = OCR0B;
209
                        txMsg.Data.bytes[0] = OCR0B;
169
                        BIOS_CanSend(&txMsg);
210
                        BIOS_CanSend(&txMsg);
170
                    break;
211
                    break;
171
                    case LCD_ACTION_GET_BLIGHT:
212
                    case LCD_ACTION_GET_BLIGHT:
172
                        // Get backlight
213
                        // Get backlight
173
                        txMsg.DataLength = 1;
214
                        txMsg.DataLength = 1;
174
                        txMsg.Id = ( CLASS_ACT<<CLASS_MASK_BITS )|( ACT_TYPE_LCD<<ACT_TYPE_BITS )|( LCD_ACTION_SEND_BLIGHT<<LCD_ACTION_BITS )|NODE_ID;
215
                        txMsg.Id = ( CLASS_ACT<<CLASS_MASK_BITS )|( ACT_TYPE_LCD<<ACT_TYPE_BITS )|( LCD_ACTION_SEND_BLIGHT<<LCD_ACTION_BITS )|NODE_ID;
Line 178... Line 219...
178
                    default:
219
                    default:
179
                    // Take over the world
220
                    // Take over the world
180
                    break;
221
                    break;
181
                    }
222
                    }
182
                }
223
                }
183
            }
224
            }
184
            rxMsgFull = 0;
225
            rxMsgFull = 0;
185
        }
226
        */}
186
    }
227
    }
187
}
228
}
188
 
229
 
189
void send_dimensions(){
230
void send_dimensions(){
190
    Can_Message_t txMsg;
231
    Can_Message_t txMsg;
Line 204... Line 245...
204
    static uint8_t rot_lastdir = 0, rot_laststate = 0; // FIXME måste flyttas ut igen?
245
    static uint8_t rot_lastdir = 0, rot_laststate = 0; // FIXME måste flyttas ut igen?
205
 
246
 
206
    Can_Message_t txMsg;
247
    Can_Message_t txMsg;
207
    txMsg.ExtendedFlag=1;
248
    txMsg.ExtendedFlag=1;
208
    txMsg.RemoteFlag=0;
249
    txMsg.RemoteFlag=0;
209
    txMsg.Id = ( CLASS_SNS<<CLASS_MASK_BITS )|( SNS_ACT_BUTTON<<SNS_TYPE_BITS )|( 0x01<<SNS_ID_BITS )| NODE_ID;
250
    //txMsg.Id = ( CLASS_SNS<<CLASS_MASK_BITS )|( SNS_ACT_BUTTON<<SNS_TYPE_BITS )|( 0x01<<SNS_ID_BITS )| NODE_ID;//FIXME: borttaget
210
    txMsg.DataLength=2;
251
    txMsg.DataLength=2;
211
 
252
 
212
    if(PINB&(1<<PB0)){
253
    if(PINB&(1<<PB0)){
213
        rot_data |= 0x01;
254
        rot_data |= 0x01;
214
    }
255
    }