Subversion Repositories HomeAutomation

Rev

Rev 563 | Rev 607 | Go to most recent revision | Show entire file | Ignore 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 32... Line 73...
32
#define SIZE_LCD LCD_SIZE_20x4
73
#define SIZE_LCD LCD_SIZE_20x4
33
 
74
 
34
#define BUFFER_SIZE SIZE_X
75
#define BUFFER_SIZE SIZE_X
35
#define TRUE 1
76
#define TRUE 1
36
#define FALSE 0
77
#define FALSE 0
37
 
78
 
38
#define LEFT    0x01
79
#define LEFT    0x01
39
#define RIGHT   0x02
80
#define RIGHT   0x02
40
 
81
 
41
volatile Can_Message_t rxMsg;
82
volatile Can_Message_t rxMsg;
42
 
83
 
43
char incoming_text[ BUFFER_SIZE ];
84
char incoming_text[ BUFFER_SIZE ];
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){
56
        memcpy((void*)&rxMsg, msg, sizeof(rxMsg));
97
        memcpy((void*)&rxMsg, msg, sizeof(rxMsg));
Line 59... Line 100...
59
}
100
}
60
 
101
 
61
ISR( PCINT2_vect ){
102
ISR( PCINT2_vect ){
62
// For ROTENC_A and ROTENC_B FIXME är inte riktigt rätt
103
// For ROTENC_A and ROTENC_B FIXME är inte riktigt rätt
63
    rotenc();
104
    rotenc();
64
}
105
}
65
 
106
 
66
ISR( PCINT0_vect ){
107
ISR( PCINT0_vect ){
67
// For ROTENC_BTN
108
// For ROTENC_BTN
68
rotenc();
109
rotenc();
69
}
110
}
Line 108... Line 149...
108
    Can_Message_t txMsg;
149
    Can_Message_t txMsg;
109
    txMsg.ExtendedFlag=1;
150
    txMsg.ExtendedFlag=1;
110
    txMsg.RemoteFlag=0;
151
    txMsg.RemoteFlag=0;
111
// FIXME skicka app startad
152
// FIXME skicka app startad
112
    BIOS_CanCallback = &can_receive;
153
    BIOS_CanCallback = &can_receive;
113
 
154
 
114
    lcd_init( LCD_DISP_ON );
155
    lcd_init( LCD_DISP_ON );
115
    lcd_clrscr();
156
    lcd_clrscr();
116
    lcd_puts("HomeAutomation\n");
157
    lcd_puts("HomeAutomation\n");
117
 
158
 
118
    send_dimensions();
159
    send_dimensions();
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 180... Line 221...
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
    }