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
/**
2
 * CAN LCD.
3
 * For HD44780- and KS0073-based LCD displays
4
 * This is the early version that only prints temperature sensor data.
5
 *
6
 * @date    2006-12-11
7
 * @author  Erik Larsson
8
 *
9
 * TODO Fix more types of output: relay status, mail recieved etc.
10
 * Make it configurable to use UART, because it's not necessary on the final PCB
11
 *
12
 */
13
 
196 eqlazer 14
#define DEBUG 1
179 eqlazer 15
 
16
/*-----------------------------------------------------------------------------
17
 * Includes
18
 *---------------------------------------------------------------------------*/
19
/* system files */
20
#include <avr/io.h>
21
#include <avr/interrupt.h>
22
#include <avr/wdt.h>
23
#include <stdio.h>
24
/* lib files */
25
#include <can.h>
26
#include <serial.h>
27
#include <timebase.h>
28
#include <lcd_HD44780.h>
196 eqlazer 29
#include <clcd20x4.h>
30
/* funcdefs */
31
#include <global_funcdefs.h>
32
#include <eqlazer_funcdefs.h>
179 eqlazer 33
 
34
/* defines */
196 eqlazer 35
#define BUFFER_SIZE 20
179 eqlazer 36
 
196 eqlazer 37
uint8_t currentView = MAIN_VIEW;
38
/*static const PROGMEM unsigned char symbolThermometer[] =
39
{
40
    0x04, 0x0A, 0x0A, 0x0A, 0x0A, 0x0A, 0x0E, 0x0E,
41
    0x0E, 0x0E, 0x0E, 0x0A, 0x11, 0x11, 0x0A, 0x04
42
};*/ // TODO behövs symbol för termometer?
179 eqlazer 43
 
196 eqlazer 44
// TODO ISR() för att använda optoencoders
45
ISR( PCINT2_vect ){
46
    // TODO do the magic stuff
47
    // vriden medurs currentView++
48
    // moturs currentView--
49
} // TODO lägga denna koden i ett eget lib?
179 eqlazer 50
 
51
/*-----------------------------------------------------------------------------
52
 * Main Program
53
 *---------------------------------------------------------------------------*/
54
int main(void) {
55
 
56
    char buffer[ BUFFER_SIZE ];
196 eqlazer 57
    uint8_t subzero; // TODO städa upp
58
    uint8_t m, temperatureData[8], relayStatus[4], dimmerStatus[4];
179 eqlazer 59
 
196 eqlazer 60
    /*
61
     * Initialize optoencoders and buttons
62
     */
63
    /* Set as input and enable pull-up */ // TODO fixa rätt ingångar
64
    DDRD &= ~( (1<<DDD6)|(1<<DDD7) );
65
    PORTD |= (1<<PD6)|(1<<PD7);
66
    /* Enable IO-pin interrupt */
67
    PCICR |= (1<<PCIE1);
68
    /* Unmask PD6 and PD7 */
69
    PCMSK2 |= (1<<PCINT22)|(1<<PCINT23);
179 eqlazer 70
 
71
 
196 eqlazer 72
    Timebase_Init();
73
#if DEBUG
74
    Serial_Init();
75
#endif
76
    sei();
77
    lcd_init( LCD_DISP_ON );
78
#if DEBUG
79
    printf("\n------------------------------------------------------------\n");
80
    printf(  "   CAN LCD\n");
81
    printf(  "------------------------------------------------------------\n");
82
#endif
179 eqlazer 83
    lcd_clrscr();
84
    lcd_puts("CAN LCD test\n");
196 eqlazer 85
#if DEBUG
86
    printf("CanInit...");
179 eqlazer 87
    lcd_puts("CanInit... ");
196 eqlazer 88
    if (Can_Init() != CAN_OK) {
89
        printf("FAILED!\n");
179 eqlazer 90
        lcd_puts("FAILED!\n");
196 eqlazer 91
    }
92
    else {
93
        printf("OK!\n");
179 eqlazer 94
        lcd_puts("OK!\n");
196 eqlazer 95
    }
96
#else
97
    lcd_puts("CanInit... ");
98
    if (Can_Init() != CAN_OK) {
99
        lcd_puts("FAILED!\n");
100
    }else{
101
        lcd_puts("OK!\n");
102
    }
103
#endif
104
    uint32_t timeStamp = 0;
179 eqlazer 105
 
196 eqlazer 106
    Can_Message_t txMsg;
107
    Can_Message_t rxMsg;
108
    txMsg.Id = 0;
109
    txMsg.RemoteFlag = 0;
110
    txMsg.ExtendedFlag = 1;
111
 
179 eqlazer 112
    lcd_clrscr();
113
 
114
    /* main loop */
115
    while (1) {
116
        /* service the CAN routines */
117
        Can_Service();
118
 
119
        /* check if any messages have been received and print to uart */
120
        while (Can_Receive(&rxMsg) == CAN_OK) {
196 eqlazer 121
#if DEBUG
179 eqlazer 122
            printf("MSG Received: ID=%lx, DLC=%u, EXT=%u, RTR=%u, ", rxMsg.Id, (uint16_t)(rxMsg.DataLength), (uint16_t)(rxMsg.ExtendedFlag), (uint16_t)(rxMsg.RemoteFlag));
123
            printf("data={ ");
124
 
125
            for (uint8_t i=0; i<rxMsg.DataLength; i++) {
126
                printf("%x ", rxMsg.Data.bytes[i]);
127
            }
128
            printf("}\n");
196 eqlazer 129
#endif
130
            /* Get data from bus and store */
131
            if( rxMsg.Id == 0x300 ){
132
                /* Temperature sensor data */
133
                for(m=0; m<rxMsg.DataLength; m++){
134
                    temperatureData[m] = rxMsg.Data.bytes[m];
135
                }
136
            }else if( rxMsg.Id == 0x1201 ){
137
                /* Relay status (ON/OFF) */
138
                relayStatus[1] = rxMsg.Data.bytes[2];
139
            } /* TODO Add extra messages here */
140
        }
179 eqlazer 141
 
196 eqlazer 142
        /* Print views */
143
        // TODO använd optoencoders för att växla view
144
        printLCDview( MAIN_VIEW );
179 eqlazer 145
 
196 eqlazer 146
    }
179 eqlazer 147
 
196 eqlazer 148
    return 0;
179 eqlazer 149
}