Subversion Repositories HomeAutomation

Rev

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

Rev 607 Rev 627
Line 4... Line 4...
4
 *
4
 *
5
 * Contains no intelligence. It just prints what it is told to.
5
 * Contains no intelligence. It just prints what it is told to.
6
 *
6
 *
7
 * @date    2006-12-11
7
 * @date    2006-12-11
8
 * @author  Erik Larsson
8
 * @author  Erik Larsson
-
 
9
 * @author  Martin Norden
9
 *
10
 *
10
 */
11
 */
11
 
12
 
12
/*-----------------------------------------------------------------------------
13
/*-----------------------------------------------------------------------------
13
 * Includes
14
 * Includes
Line 98... Line 99...
98
        rxMsgFull = 1;
99
        rxMsgFull = 1;
99
    }
100
    }
100
}
101
}
101
 
102
 
102
ISR( PCINT2_vect ){
103
ISR( PCINT2_vect ){
103
// For ROTENC_A and ROTENC_B FIXME är inte riktigt rätt
104
// For ROTENC_A and ROTENC_B FIXME Šr inte riktigt rŠtt. Verkar vara bra tycker jag?
104
    rotenc();
105
    rotenc();
105
}
106
}
106
 
107
 
107
ISR( PCINT0_vect ){
108
ISR( PCINT0_vect ){
108
// For ROTENC_BTN
109
// For ROTENC_BTN
Line 157... Line 158...
157
    lcd_init( LCD_DISP_ON );
158
    lcd_init( LCD_DISP_ON );
158
    lcd_clrscr();
159
    lcd_clrscr();
159
    lcd_puts("HomeAutomation\n");
160
    lcd_puts("HomeAutomation\n");
160
 
161
 
161
    send_dimensions();
162
    send_dimensions();
162
    lcd_puts("Very nice!\n");
163
    lcd_puts("CAN Connected!\n");
163
 
164
 
164
    /* main loop */
165
    /* main loop */
165
    while(1){
166
    while(1){
166
        /* check if any messages have been received */
167
        /* check if any messages have been received */
167
        if(rxMsgFull){
168
        if(rxMsgFull){
168
            uint16_t act_type;
169
            uint16_t act_type;
169
            uint8_t lcdid;
170
            uint8_t lcdid;
170
            if ( ((rxMsg.Id & CAN_MASK_CLASS)>>CAN_SHIFT_CLASS) == CAN_ACT){// FIXME ett jäkla herk, städa upp
171
            if ( ((rxMsg.Id & CAN_MASK_CLASS)>>CAN_SHIFT_CLASS) == CAN_ACT){// FIXME ett jŠkla herk, stŠda upp
171
               
172
               
172
               
173
               
173
                act_type =(uint16_t)((rxMsg.Id & CAN_MASK_ACT_TYPE) >> CAN_SHIFT_ACT_TYPE);
174
                act_type =(uint16_t)((rxMsg.Id & CAN_MASK_ACT_TYPE) >> CAN_SHIFT_ACT_TYPE);
174
           
175
           
175
                lcdid = (uint8_t)((rxMsg.Id & CAN_MASK_ACT_ID) >> CAN_SHIFT_ACT_ID);
176
                lcdid = (uint8_t)((rxMsg.Id & CAN_MASK_ACT_ID) >> CAN_SHIFT_ACT_ID);
Line 246... Line 247...
246
    BIOS_CanSend(&txMsg);
247
    BIOS_CanSend(&txMsg);
247
}
248
}
248
 
249
 
249
void rotenc(){
250
void rotenc(){
250
    uint8_t rot_data = 0;
251
    uint8_t rot_data = 0;
251
    static uint8_t rot_lastdir = 0, rot_laststate = 0; // FIXME måste flyttas ut igen?
252
    static uint8_t rot_lastdir = 0, rot_laststate = 0, btn_laststate = 0;
252
 
253
 
253
    Can_Message_t txMsg;
254
    Can_Message_t txMsg;
254
    txMsg.ExtendedFlag=1;
255
    txMsg.ExtendedFlag=1;
255
    txMsg.RemoteFlag=0;
256
    txMsg.RemoteFlag=0;
256
    //txMsg.Id = ( CLASS_SNS<<CLASS_MASK_BITS )|( SNS_ACT_BUTTON<<SNS_TYPE_BITS )|( 0x01<<SNS_ID_BITS )| NODE_ID;//FIXME: borttaget
257
    //txMsg.Id = ( CLASS_SNS<<CLASS_MASK_BITS )|( SNS_ACT_BUTTON<<SNS_TYPE_BITS )|( 0x01<<SNS_ID_BITS )| NODE_ID;//FIXME: borttaget
257
    txMsg.DataLength=2;
258
    txMsg.DataLength=2;
258
 
259
 
-
 
260
    //Take care of button push
-
 
261
    if ((PINB&(1<<PB7)) != btn_laststate){ //The buttonstate has changed! Let's send a message!
-
 
262
        btn_laststate = (PINB&(1<<PB7));
-
 
263
        txMsg.Data.bytes[0] = 5;
-
 
264
        txMsg.Data.bytes[1] = (btn_laststate)?0:1;
-
 
265
        txMsg.DataLength=2;
-
 
266
        BIOS_CanSend(&txMsg);
-
 
267
    }
-
 
268
   
-
 
269
    //Take care of rotary encoder movement
259
    if(PINB&(1<<PB0)){
270
    if(PINB&(1<<PB0)){
260
        rot_data |= 0x01;
271
        rot_data |= 0x01;
261
    }
272
    }
262
    if(PIND&(1<<PD2)){
273
    if(PIND&(1<<PD2)){
263
        rot_data |= 0x02;
274
        rot_data |= 0x02;
264
    }
275
    }
265
 
276
 
266
    if( rot_data==0 || rot_data==3 ){
277
    if( rot_data==0 || rot_data==3 ){ // Are both signals high or low?
267
        if( rot_data==0 && rot_laststate!=rot_data ){
278
        if( rot_data==0 && rot_laststate!=rot_data ){ // Are both signals low? In that case we are finished with one turn and should print out the direction it went. 
268
            if( rot_lastdir&0x01 ){
279
            if( rot_lastdir&0x01 ){
269
                // Moving right
280
                // Moving right
270
                txMsg.Data.bytes[0]=RIGHT;
281
                txMsg.Data.bytes[0]=RIGHT;
271
                txMsg.Data.bytes[1] = (PINB&(1<<PB7))?0:1;
282
                txMsg.Data.bytes[1] = (PINB&(1<<PB7))?0:1;
272
                txMsg.DataLength=2;
283
                txMsg.DataLength=2;
273
                BIOS_CanSend(&txMsg);
284
                BIOS_CanSend(&txMsg);
274
                // For testing TODO remove
-
 
275
                if(OCR1A<0xFF){
-
 
276
                    OCR1A++;
-
 
277
                }
-
 
278
                if(OCR0B>0){
-
 
279
                    OCR0B--;
-
 
280
                }
-
 
281
            }else{
285
            }else{
282
                // Moving left
286
                // Moving left
283
                txMsg.Data.bytes[0]=LEFT;
287
                txMsg.Data.bytes[0]=LEFT;
284
                txMsg.Data.bytes[1] = (PINB&(1<<PB7))?0:1;
288
                txMsg.Data.bytes[1] = (PINB&(1<<PB7))?0:1;
285
                txMsg.DataLength=2;
289
                txMsg.DataLength=2;
286
                BIOS_CanSend(&txMsg);
290
                BIOS_CanSend(&txMsg);
287
                // For testing TODO remove
-
 
288
                if(OCR1A>0){
-
 
289
                    OCR1A--;
-
 
290
                }
-
 
291
                if(OCR0B<0xFF){
-
 
292
                    OCR0B++;
-
 
293
                }
-
 
294
            }
291
            }
295
        }
292
        }
296
        rot_laststate = rot_data;
293
        rot_laststate = rot_data;
297
    }else{
-
 
-
 
294
    } else { // No, only one of the signals are high. We can use this to find out what direction we are moving.
298
        rot_lastdir = rot_data;
295
        rot_lastdir = rot_data;
299
    }
296
    }
300
}
297
}
301
 
298