Subversion Repositories HomeAutomation

Rev

Go to most recent revision | Details | Last modification | View Log | SVN | RSS feed

Rev Author Line No. Line
179 eqlazer 1
/**
335 eqlazer 2
 * CanCLCD.
179 eqlazer 3
 * For HD44780- and KS0073-based LCD displays
335 eqlazer 4
 * Prints sensor data and other interesting things.
179 eqlazer 5
 *
6
 * @date    2006-12-11
7
 * @author  Erik Larsson
8
 *
9
 * TODO Fix more types of output: relay status, mail recieved etc.
10
 *
11
 */
12
 
13
/*-----------------------------------------------------------------------------
14
 * Includes
15
 *---------------------------------------------------------------------------*/
16
/* system files */
17
#include <avr/io.h>
18
#include <avr/interrupt.h>
19
#include <stdio.h>
20
/* lib files */
332 eqlazer 21
#include <bios.h>
179 eqlazer 22
#include <lcd_HD44780.h>
196 eqlazer 23
/* funcdefs */
344 eqlazer 24
//#include <eqlazer_funcdefs.h>
179 eqlazer 25
 
26
/* defines */
344 eqlazer 27
#define SIZE_X  20
28
#define SIZE_Y  4
29
 
30
//#define BUFFER_SIZE 20
332 eqlazer 31
#define TRUE 1
32
#define FALSE 0
179 eqlazer 33
 
344 eqlazer 34
#define LEFT    0x01
35
#define RIGHT   0x02
36
 
332 eqlazer 37
Can_Message_t rxMsg;
344 eqlazer 38
Can_Message_t txMsg;
256 eqlazer 39
 
335 eqlazer 40
 
344 eqlazer 41
uint8_t     msg_received = FALSE;
335 eqlazer 42
 
43
uint8_t rot_lastdir = 0,
44
        rot_laststate = 0;
45
 
344 eqlazer 46
 
47
void can_receive(Can_Message_t *msg){
48
// FIXME
49
}
50
 
51
 
52
ISR( PCINT0_vect ){ // For ROTENC_A and ROTENC_B
335 eqlazer 53
    uint8_t rot_data = 0;
256 eqlazer 54
 
344 eqlazer 55
    txMsg.Id=0xA000000;
56
    txMsg.DataLength=2;
57
 
58
    if(PINB&(1<<PB7)){
335 eqlazer 59
        rot_data |= 0x01;
60
    }
344 eqlazer 61
    if(PINB&(1<<PB0)){
335 eqlazer 62
        rot_data |= 0x02;
63
    }
64
 
344 eqlazer 65
    if( rot_data==0 || rot_data==3 ){
66
        if( rot_data==0 && rot_laststate!=rot_data ){
67
            if( rot_lastdir&0x01 ){
68
                // Moving right
69
                txMsg.Data.bytes[0]=RIGHT;
70
                txMsg.Data.bytes[1] = (PIND&(1<<PD2))?0:1;
71
                bios->can_send(&txMsg);
72
            }else{
73
                // Moving left
74
                txMsg.Data.bytes[0]=LEFT;
75
                txMsg.Data.bytes[1] = (PIND&(1<<PD2))?0:1;
76
                bios->can_send(&txMsg);
335 eqlazer 77
            }
78
        }
344 eqlazer 79
        rot_laststate = rot_data;
80
    }else{
335 eqlazer 81
        rot_lastdir = rot_data;
82
    }
332 eqlazer 83
}
179 eqlazer 84
 
344 eqlazer 85
ISR( PCINT2_vect ){ // For ROTENC_BTN
86
    lcd_puts("a");
332 eqlazer 87
}
88
 
344 eqlazer 89
    void send_dimensions();
332 eqlazer 90
 
179 eqlazer 91
/*-----------------------------------------------------------------------------
92
 * Main Program
93
 *---------------------------------------------------------------------------*/
94
int main(void) {
95
 
344 eqlazer 96
//    char buffer[ BUFFER_SIZE ];
335 eqlazer 97
    /*
98
     * Initialize rotaryencoders and buttons
99
     */
100
    /* Set as input */
344 eqlazer 101
    DDRD &= ~(1<<DDD2);
102
    DDRB &= ~((1<<DDB7)|(1<<DDB0));
103
    /* Enable pull-up */
104
    PORTD |= (1<<PD2);
105
    PORTB |= (1<<PB7)|(1<<PB0);
335 eqlazer 106
    /* Enable IO-pin interrupt */
344 eqlazer 107
    PCICR |= (1<<PCIE2)|(1<<PCIE0);
108
    /* Unmask PB7, PB0 and PD2 */
109
    PCMSK2 |= (1<<PCINT18);
110
    PCMSK0 |= (1<<PCINT7)|(1<<PCINT0);
179 eqlazer 111
 
344 eqlazer 112
    txMsg.ExtendedFlag=1;
113
    txMsg.RemoteFlag=0;
114
 
335 eqlazer 115
    sei();
332 eqlazer 116
    bios->can_callback = &can_receive;
256 eqlazer 117
 
332 eqlazer 118
    lcd_init( LCD_DISP_ON );
119
    lcd_clrscr();
179 eqlazer 120
 
344 eqlazer 121
    send_dimensions();
179 eqlazer 122
 
123
    /* main loop */
332 eqlazer 124
    while(1){
125
        /* check if any messages have been received */
126
        if(msg_received){
344 eqlazer 127
 
334 eqlazer 128
            msg_received = FALSE;
129
        }
332 eqlazer 130
    }
179 eqlazer 131
}
344 eqlazer 132
 
133
void send_dimensions(){
134
    txMsg.Id=0xA000001;
135
    txMsg.Data.bytes[0] = SIZE_X;
136
    txMsg.Data.bytes[1] = SIZE_Y;
137
    txMsg.DataLength = 2;
138
    bios->can_send(&txMsg);
139
}