Subversion Repositories HomeAutomation

Rev

Rev 164 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed

Rev 164 Rev 167
Line 20... Line 20...
20
#include <can.h>
20
#include <can.h>
21
#include <serial.h>
21
#include <serial.h>
22
#include <timebase.h>
22
#include <timebase.h>
23
#include <lcd_HD44780.h>
23
#include <lcd_HD44780.h>
24
 
24
 
-
 
25
#include <eqlazer_funcdefs.h>
-
 
26
 
25
#define BUFFER_SIZE 20
27
#define BUFFER_SIZE 20
26
 
28
 
27
/*-----------------------------------------------------------------------------
29
/*-----------------------------------------------------------------------------
28
 * Main Program
30
 * Main Program
29
 *---------------------------------------------------------------------------*/
31
 *---------------------------------------------------------------------------*/
30
int main(void) {
32
int main(void) {
31
 
33
 
32
    char buffer[ BUFFER_SIZE ];
34
    char buffer[ BUFFER_SIZE ];
33
    int num=1234;
35
    uint8_t subzero;
34
 
36
 
35
    Timebase_Init();
37
    Timebase_Init();
36
    Serial_Init();
38
    Serial_Init();
37
    sei();
39
    sei();
38
    lcd_init( LCD_DISP_ON );
40
    lcd_init( LCD_DISP_ON );
39
 
41
 
40
    printf("\n------------------------------------------------------------\n");
42
    printf("\n------------------------------------------------------------\n");
41
    printf(  "   CAN Test: Periodic Transmission\n");
43
    printf(  "   CAN Test: LCD\n");
42
    printf(  "------------------------------------------------------------\n");
44
    printf(  "------------------------------------------------------------\n");
43
 
45
 
44
    lcd_clrscr();
46
    lcd_clrscr();
45
    lcd_puts("CAN LCD test\n");
47
    lcd_puts("CAN LCD test\n");
46
 
48
 
47
    printf("CanInit...");
49
    printf("CanInit...");
48
    lcd_puts("CanInit... ");
50
    lcd_puts("CanInit... ");
Line 52... Line 54...
52
    }
54
    }
53
    else {
55
    else {
54
        printf("OK!\n");
56
        printf("OK!\n");
55
        lcd_puts("OK!\n");
57
        lcd_puts("OK!\n");
56
    }
58
    }
57
   
-
 
58
//    snprintf(buffer, BUFFER_SIZE, "yo %d 98765432109\n", num);
-
 
59
//    lcd_puts(buffer);
-
 
60
//    lcd_puts("test\n");
-
 
61
//    lcd_puts(buffer);
-
 
62
 
59
   
63
    uint32_t timeStamp = 0;
60
    uint32_t timeStamp = 0;
64
   
61
   
65
    Can_Message_t txMsg;
62
    Can_Message_t txMsg;
66
    Can_Message_t rxMsg;
63
    Can_Message_t rxMsg;
67
    txMsg.Id = 0;
64
    txMsg.Id = 0;
68
    txMsg.RemoteFlag = 0;
65
    txMsg.RemoteFlag = 0;
69
    txMsg.ExtendedFlag = 1; //DataLength and the databytes are just what happens to be in the memory. They are never set.
66
    txMsg.ExtendedFlag = 1; //DataLength and the databytes are just what happens to be in the memory. They are never set.
-
 
67
 
-
 
68
    lcd_clrscr();
70
   
69
 
71
    /* main loop */
70
    /* main loop */
72
    while (1) {
71
    while (1) {
73
        /* service the CAN routines */
72
        /* service the CAN routines */
74
        Can_Service();
73
        Can_Service();
75
       
74
       
76
        /* send CAN message and check for CAN errors once every second */
75
        /* send CAN message and check for CAN errors once every second */
77
        if (Timebase_PassedTimeMillis(timeStamp) >= 1000) {
76
//      if (Timebase_PassedTimeMillis(timeStamp) >= 1000) {
78
            timeStamp = Timebase_CurrentTime();
77
//          timeStamp = Timebase_CurrentTime();
79
            /* send txMsg */
78
            /* send txMsg */
80
            txMsg.Id++;
79
//          txMsg.Id++;
81
            Can_Send(&txMsg);
80
//          Can_Send(&txMsg);
82
        }
81
//      }
83
       
82
 
84
        /* check if any messages have been received */
83
        /* check if any messages have been received */
85
        while (Can_Receive(&rxMsg) == CAN_OK) {
84
        while (Can_Receive(&rxMsg) == CAN_OK) {
86
            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));
85
            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));
87
            printf("data={ ");
86
            printf("data={ ");
Line 89... Line 88...
89
            for (uint8_t i=0; i<rxMsg.DataLength; i++) {
88
            for (uint8_t i=0; i<rxMsg.DataLength; i++) {
90
                printf("%x ", rxMsg.Data.bytes[i]);
89
                printf("%x ", rxMsg.Data.bytes[i]);
91
            }
90
            }
92
            printf("}\n");
91
            printf("}\n");
93
 
92
 
94
            if( rxMsg.Id == 0x3 ){
-
 
95
//                lcd_gotoxy(0,1);
-
 
96
                lcd_clrscr();
-
 
97
 //               lcd_putc(0xdf);
-
 
98
                lcd_puts("Temperature data:\n");
-
 
99
 
93
 
-
 
94
            if( (rxMsg.Id & 0x1E000000)>>25 == FUNCT_SENSORS){ // if sensor data received
-
 
95
 
-
 
96
                /* which temperature sensor? */
-
 
97
                if( (rxMsg.Id & 0x01FF8000)>>15 == FUNCC_SENSORS_TEMPERATURE_INSIDE ){
-
 
98
                    /* Below 0 degrees celsius? */
-
 
99
                    if(rxMsg.Data.bytes[0]&0x80){
-
 
100
                        rxMsg.Data.bytes[0]= -rxMsg.Data.bytes[0];
-
 
101
                        subzero = 1;
-
 
102
                    }else{
-
 
103
                        subzero = 0;
-
 
104
                    }
-
 
105
                        snprintf( buffer, BUFFER_SIZE, (subzero)?"-%d,%d%cC":"%d,%d%cC", rxMsg.Data.bytes[0], rxMsg.Data.bytes[1], 0xdf );
-
 
106
                        lcd_gotoxy( LCD_LINE0_0 );
-
 
107
                        lcd_puts( LCD_SENSOR_TEMPERATURE_INSIDE );
-
 
108
                        lcd_gotoxy( LCD_LINE1_0 );
-
 
109
                        lcd_puts( buffer );
-
 
110
                }else if( (rxMsg.Id & 0x01FF8000)>>15 == FUNCC_SENSORS_TEMPERATURE_OUTSIDE ){
-
 
111
                    if(rxMsg.Data.bytes[0]&0x80){
-
 
112
                        rxMsg.Data.bytes[0]= -rxMsg.Data.bytes[0];
-
 
113
                        subzero = 1;
-
 
114
                    }else{
-
 
115
                        subzero = 0;
-
 
116
                    }
-
 
117
                        snprintf( buffer, BUFFER_SIZE, (subzero)?"-%d,%d%cC":"%d,%d%cC", rxMsg.Data.bytes[0], rxMsg.Data.bytes[1], 0xdf );
-
 
118
                        lcd_gotoxy( LCD_LINE2_0 );
-
 
119
                        lcd_puts( LCD_SENSOR_TEMPERATURE_OUTSIDE );
-
 
120
                        lcd_gotoxy( LCD_LINE3_0 );
-
 
121
                        lcd_puts( buffer );
-
 
122
                }else if( (rxMsg.Id & 0x01FF8000)>>15 == FUNCC_SENSORS_TEMPERATURE_FREEZER ){
-
 
123
                    if(rxMsg.Data.bytes[0]&0x80){
-
 
124
                        rxMsg.Data.bytes[0]= -rxMsg.Data.bytes[0];
-
 
125
                        subzero = 1;
-
 
126
                    }else{
-
 
127
                        subzero = 0;
-
 
128
                    }
-
 
129
                        snprintf( buffer, BUFFER_SIZE, (subzero)?"-%d,%d%cC":"%d,%d%cC", rxMsg.Data.bytes[0], rxMsg.Data.bytes[1], 0xdf );
-
 
130
                        lcd_gotoxy( LCD_LINE2_2 );
-
 
131
                        lcd_puts( LCD_SENSOR_TEMPERATURE_FREEZER );
-
 
132
                        lcd_gotoxy( LCD_LINE3_2 );
-
 
133
                        lcd_puts( buffer );
-
 
134
                }else{
-
 
135
                    lcd_clrscr();
-
 
136
                    lcd_puts("Sensors: No config.");
-
 
137
                }
-
 
138
/*
100
                for( uint8_t i=0; i<(rxMsg.DataLength/2); i++ ){
139
                for( uint8_t i=0; i<(rxMsg.DataLength/2); i++ ){
101
                        snprintf( buffer, BUFFER_SIZE, "Sensor %i: %d,%d%cC", i, rxMsg.Data.bytes[i*2], rxMsg.Data.bytes[i*2+1], 0xdf );
140
                        snprintf( buffer, BUFFER_SIZE, "Sensor %i: %d,%d%cC", i, rxMsg.Data.bytes[i*2], rxMsg.Data.bytes[i*2+1], 0xdf );
102
                        lcd_gotoxy(0,1+i);
141
                        lcd_gotoxy(0,1+i);
103
                        lcd_puts( buffer );
142
                        lcd_puts( buffer );
104
                }
143
                }*/
105
            }
144
            }
106
        }
145
        }
107
    }
146
    }
108
   
147
   
109
    return 0;
148
    return 0;