Subversion Repositories HomeAutomation

Rev

Rev 631 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed

Rev 631 Rev 636
Line 54... Line 54...
54
 
54
 
55
void send_dimensions(void);
55
void send_dimensions(void);
56
void rotenc(void);
56
void rotenc(void);
57
void action(uint8_t type);
57
void action(uint8_t type);
58
void alarm(void);
58
void alarm(void);
-
 
59
void refreshDisplay(void);
59
 
60
 
60
uint32_t timeBase = 0;
61
uint32_t timeBase = 0;
61
uint16_t timerVar= 0;
-
 
62
uint8_t alarmTimer = 0;
-
 
63
 
62
 
64
char lcdBuffer[5];
63
char lcdBuffer[5];
-
 
64
 
-
 
65
//Struct for countdown
-
 
66
typedef struct
-
 
67
{
-
 
68
    uint16_t timerCnt;
-
 
69
    uint8_t alarmTimer;
-
 
70
    uint16_t timerMax;
-
 
71
} countDown;
-
 
72
 
-
 
73
countDown countTimer1;
-
 
74
 
65
 
75
 
66
// CAN message reception callback
76
// CAN message reception callback
67
// This function runs with interrupts disabled, keep it as short as possible
77
// This function runs with interrupts disabled, keep it as short as possible
68
void can_receive(Can_Message_t *msg){
78
void can_receive(Can_Message_t *msg){
69
    if(!rxMsgFull){
79
    if(!rxMsgFull){
Line 126... Line 136...
126
    Can_Message_t txMsg;
136
    Can_Message_t txMsg;
127
    txMsg.ExtendedFlag=1;
137
    txMsg.ExtendedFlag=1;
128
    txMsg.RemoteFlag=0;
138
    txMsg.RemoteFlag=0;
129
// FIXME skicka app startad
139
// FIXME skicka app startad
130
    BIOS_CanCallback = &can_receive;
140
    BIOS_CanCallback = &can_receive;
131
 
141
 
132
    lcd_init( LCD_DISP_ON );
142
    lcd_init( LCD_DISP_ON );
133
    lcd_clrscr();
143
    lcd_clrscr();
134
    lcd_puts("EggWatch\n");
144
    lcd_puts("CanEggWatch\n");
135
 
145
 
136
    send_dimensions();
146
    send_dimensions();
137
    lcd_puts("CAN Connected!\n");
147
    lcd_puts("CAN Connected!\n");
-
 
148
   
-
 
149
    lcd_clrscr();
-
 
150
   
138
 
151
 
139
    /* main loop */
152
    /* main loop */
140
    while(1){
153
    while(1){
141
       
154
       
142
       
155
       
143
        if( Timebase_PassedTimeMillis(timeBase) >= 1000 ){
156
        if( Timebase_PassedTimeMillis(timeBase) >= 1000 ){
144
            if (timerVar != 0){
157
            if (countTimer1.timerCnt != 0){
145
                timerVar--;
158
                countTimer1.timerCnt--;
146
                lcd_clrscr();
159
                refreshDisplay();
147
                itoa(timerVar/60,lcdBuffer,10);
-
 
148
                lcd_puts(lcdBuffer);
-
 
149
                lcd_puts(":");
-
 
150
                itoa(timerVar%60,lcdBuffer,10);
-
 
151
                lcd_puts(lcdBuffer);
-
 
152
            } else {
160
            } else {
153
                if (alarmTimer != 0){
161
                if (countTimer1.alarmTimer != 0){
154
                    alarm();
162
                    alarm();
155
                    alarmTimer--;
163
                    countTimer1.alarmTimer--;
156
                }
164
                }
157
            }
165
            }
158
            timeBase =  Timebase_CurrentTime();
166
            timeBase =  Timebase_CurrentTime();
159
        }
167
        }
160
       
168
       
Line 181... Line 189...
181
}
189
}
182
 
190
 
183
void rotenc(){
191
void rotenc(){
184
    uint8_t rot_data = 0;
192
    uint8_t rot_data = 0;
185
    static uint8_t rot_lastdir = 0, rot_laststate = 0, btn_laststate = 0;
193
    static uint8_t rot_lastdir = 0, rot_laststate = 0, btn_laststate = 0;
186
 
194
 
187
    Can_Message_t txMsg;
195
    Can_Message_t txMsg;
188
    txMsg.ExtendedFlag=1;
196
    txMsg.ExtendedFlag=1;
189
    txMsg.RemoteFlag=0;
197
    txMsg.RemoteFlag=0;
190
    //txMsg.Id = ( CLASS_SNS<<CLASS_MASK_BITS )|( SNS_ACT_BUTTON<<SNS_TYPE_BITS )|( 0x01<<SNS_ID_BITS )| NODE_ID;//FIXME: borttaget
198
    //txMsg.Id = ( CLASS_SNS<<CLASS_MASK_BITS )|( SNS_ACT_BUTTON<<SNS_TYPE_BITS )|( 0x01<<SNS_ID_BITS )| NODE_ID;//FIXME: borttaget
191
    txMsg.DataLength=2;
199
    txMsg.DataLength=2;
Line 234... Line 242...
234
 
242
 
235
void action(uint8_t type){
243
void action(uint8_t type){
236
    //Let's do something with something!
244
    //Let's do something with something!
237
    lcd_clrscr();
245
    lcd_clrscr();
238
    if (type == LEFT){
246
    if (type == LEFT){
239
        timerVar--;
247
        countTimer1.timerCnt--;
240
        lcd_clrscr();
248
        refreshDisplay();
241
        itoa(timerVar/60,lcdBuffer,10);
-
 
242
        lcd_puts(lcdBuffer);
-
 
243
        lcd_puts(":");
-
 
244
        itoa(timerVar%60,lcdBuffer,10);
-
 
245
        lcd_puts(lcdBuffer);
-
 
246
    }
249
    }
247
    if (type == RIGHT){
250
    if (type == RIGHT){
248
        timerVar++;
251
        countTimer1.timerCnt++;
249
        lcd_clrscr();
-
 
250
        itoa(timerVar/60,lcdBuffer,10);
252
        if  (countTimer1.timerCnt > countTimer1.timerMax){
251
        lcd_puts(lcdBuffer);
253
            countTimer1.timerMax = countTimer1.timerCnt;
252
        lcd_puts(":");
254
        }
253
        itoa(timerVar%60,lcdBuffer,10);
-
 
254
        lcd_puts(lcdBuffer);
255
        refreshDisplay();
255
    }
256
    }
256
    if (type == BUTTON_PUSH){
257
    if (type == BUTTON_PUSH){
257
        lcd_puts("Init!");
258
        lcd_puts("Init!");
258
    }
259
    }
259
    if (type == BUTTON_RELEASE){
260
    if (type == BUTTON_RELEASE){
260
        timeBase = Timebase_CurrentTime();
261
        timeBase = Timebase_CurrentTime();
-
 
262
        countTimer1.timerCnt = 10;
261
        timerVar = 10;
263
        countTimer1.timerMax = 10;
262
        alarmTimer = 1;
264
        countTimer1.alarmTimer = 1;
-
 
265
        refreshDisplay();
263
    }
266
    }
264
}
267
}
265
 
268
 
266
void alarm(void){
269
void alarm(void){
267
    lcd_puts("Riing!");
270
    lcd_puts("Riing!");
-
 
271
}
-
 
272
 
-
 
273
void refreshDisplay(void){
-
 
274
    lcd_clrscr();
-
 
275
    itoa(countTimer1.timerCnt/60,lcdBuffer,10);
-
 
276
    lcd_puts(lcdBuffer);
-
 
277
    lcd_puts(":");
-
 
278
    itoa(countTimer1.timerCnt%60,lcdBuffer,10);
-
 
279
    lcd_puts(lcdBuffer);
-
 
280
   
-
 
281
    lcd_gotoxy(0,1);
-
 
282
    lcdProgressBar(countTimer1.timerCnt,countTimer1.timerMax,16);  
268
}
283
}