Subversion Repositories HomeAutomation

Rev

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

Rev 189 Rev 191
Line 22... Line 22...
22
#include <timebase.h>
22
#include <timebase.h>
23
#include <ks0108.h>
23
#include <ks0108.h>
24
 
24
 
25
 
25
 
26
uint8_t encoderPosition; //Bara för interrupttest. +/-1 beroende på riktning.;
26
uint8_t encoderPosition; //Bara för interrupttest. +/-1 beroende på riktning.;
-
 
27
 
-
 
28
//variabler för visning
-
 
29
    Can_Message_t rxMsg;
-
 
30
 
-
 
31
void draw_lcd_screen(void){
-
 
32
 
-
 
33
    switch (encoderPosition) {
-
 
34
        case 0:
-
 
35
            glcdSetXY(0,0);
-
 
36
            char buffert[21];
-
 
37
            glcdPutStr("Latest CAN-message:");
-
 
38
            glcdSetXY(0,1);
-
 
39
            snprintf(buffert,21,"ID=%lx L=%u E=%u RT=%u", rxMsg.Id, (uint16_t)(rxMsg.DataLength), (uint16_t)(rxMsg.ExtendedFlag), (uint16_t)(rxMsg.RemoteFlag));
-
 
40
            glcdPutStr(buffert);
-
 
41
 
-
 
42
            glcdSetXY(0,2);
-
 
43
 
-
 
44
            for (uint8_t i=0; i<rxMsg.DataLength; i++) {
-
 
45
                    snprintf(buffert,21,"%x ", rxMsg.Data.bytes[i]);
-
 
46
                glcdPutStr(buffert);
-
 
47
                }
-
 
48
        return;
-
 
49
 
-
 
50
        case 1:
-
 
51
            glcdSetXY(0,0);
-
 
52
            glcdPutStr("Muahaha, Har har vi nummer tva. Och detta kanske funkar!");
-
 
53
        return;
-
 
54
        case 2:
-
 
55
            glcdSetXY(0,0);
-
 
56
            glcdPutStr("cparune :P");
-
 
57
        return;
-
 
58
 
-
 
59
    }
-
 
60
 
-
 
61
}
-
 
62
 
-
 
63
 
27
 
64
 
28
SIGNAL (SIG_INTERRUPT1)
65
SIGNAL (SIG_INTERRUPT1)
29
{
66
{
30
    if ((PINB&(0b10000000))==0){
67
    if ((PINB&(0b10000000))==0){
31
        encoderPosition = encoderPosition - 1;
68
        encoderPosition = encoderPosition - 1;
Line 34... Line 71...
34
    }
71
    }
35
   
72
   
36
 
73
 
37
    if (encoderPosition > 250) encoderPosition = 0;
74
    if (encoderPosition > 250) encoderPosition = 0;
38
    if (encoderPosition > 99) encoderPosition = 99;
75
    if (encoderPosition > 99) encoderPosition = 99;
-
 
76
    glcdClear(); //Nolla displayen
-
 
77
 
-
 
78
    draw_lcd_screen();
39
}
79
}
-
 
80
 
-
 
81
 
-
 
82
//Stöd för en massa olika sidor
-
 
83
 
40
 
84
 
41
 
85
 
42
 
86
 
43
/*-----------------------------------------------------------------------------
87
/*-----------------------------------------------------------------------------
44
 * Main Program
88
 * Main Program
Line 62... Line 106...
62
    PORTB=0x00;
106
    PORTB=0x00;
63
    DDRB |= (1<<0)|(1<<1);
107
    DDRB |= (1<<0)|(1<<1);
64
    DDRD &= ~(1<<3);
108
    DDRD &= ~(1<<3);
65
    DDRB &= ~(1<<7);
109
    DDRB &= ~(1<<7);
66
 
110
 
67
   
111
   
68
    glcdPowerOn();
112
    glcdPowerOn();
69
 
-
 
70
    Can_Message_t rxMsg;
-
 
71
    char buffert[21];   //Buffert för snprintf
-
 
72
 
-
 
73
 
113
 
74
    glcdSetXY(0,0);
114
    glcdSetXY(0,0);
75
    glcdPutStr("CanInit...");
115
    glcdPutStr("CanInit...");
76
    if (Can_Init() != CAN_OK) {
116
    if (Can_Init() != CAN_OK) {
77
        glcdPutStr("FAILED!");
117
        glcdPutStr("FAILED!");
Line 86... Line 126...
86
        /* service the CAN routines */
126
        /* service the CAN routines */
87
        Can_Service();
127
        Can_Service();
88
       
128
       
89
        /* check if any messages have been received */
129
        /* check if any messages have been received */
90
        while (Can_Receive(&rxMsg) == CAN_OK) {
130
        while (Can_Receive(&rxMsg) == CAN_OK) {
91
            glcdSetXY(0,1);
-
 
92
            glcdPutStr("MSG Recieved!");
-
 
93
            glcdSetXY(0,2);
-
 
94
            snprintf(buffert,21,"ID=%lx L=%u E=%u RT=%u", rxMsg.Id, (uint16_t)(rxMsg.DataLength), (uint16_t)(rxMsg.ExtendedFlag), (uint16_t)(rxMsg.RemoteFlag));
-
 
95
            glcdPutStr(buffert);
131
            if (encoderPosition == 0){
96
 
-
 
97
            glcdSetXY(0,3);
132
                draw_lcd_screen();
98
 
133
            }
99
            for (uint8_t i=0; i<rxMsg.DataLength; i++) {
-
 
100
                    snprintf(buffert,21,"%x ", rxMsg.Data.bytes[i]);
-
 
101
                glcdPutStr(buffert);
-
 
102
                }
134
        }
103
        }
-
 
104
       
135
       
105
        /* Här kollar vi klickvriden */    
136
        /* Här kollar vi klickvriden */    
106
        glcdSetXY(115,0);
137
//      glcdSetXY(115,0);
107
        snprintf(buffert,21,"%u ",encoderPosition);
138
//      snprintf(buffert,21,"%u ",encoderPosition);
108
        glcdPutStr(buffert);
139
//      glcdPutStr(buffert);
109
 
-
 
110
 
-
 
111
    }
140
    }
112
 
141
 
113
    return 0;
142
    return 0;
114
}
143
}