Subversion Repositories HomeAutomation

Rev

Rev 317 | Rev 322 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed

Rev 317 Rev 320
Line 16... Line 16...
16
 * Includes
16
 * Includes
17
 *---------------------------------------------------------------------------*/
17
 *---------------------------------------------------------------------------*/
18
/* system files */
18
/* system files */
19
#include <avr/io.h>
19
#include <avr/io.h>
20
#include <avr/interrupt.h>
20
#include <avr/interrupt.h>
21
#include <avr/wdt.h>
-
 
22
#include <stdio.h>
21
#include <stdio.h>
23
/* lib files */
22
/* lib files */
24
#include <bios.h>
23
#include <bios.h>
25
#include <tc1047.h>
24
#include <tc1047.h>
26
#include <rc_servo.h>
25
#include <rc_servo.h>
27
 
26
 
28
#include <eqlazer_funcdefs.h>
27
#include <eqlazer_funcdefs.h>
29
 
28
 
30
/* defines */
29
/* defines */
31
#define NUMBER_OF_RCS 1
-
 
32
#define NODE_ID     0x03L // FIXME ändras för varje nod
30
#define NODE_ID     0x03L // FIXME ändras för varje nod
33
#define GROUP_ID    0x01L // ^
31
#define GROUP_ID    0x01L // ^
34
 
32
 
35
#define FAILSAFE_MODE       0x0F
33
#define FAILSAFE_MODE       0x0F
36
#define FAILSAFE_TRESHOLD   60  /* Degrees celcius when nodeBlinds goes into failsafe mode */
34
#define FAILSAFE_TRESHOLD   60  /* Degrees celcius when nodeBlinds goes into failsafe mode */
Line 46... Line 44...
46
#define BLINDS_TURN_LEFT    0x01
44
#define BLINDS_TURN_LEFT    0x01
47
#define BLINDS_TURN_RIGHT   0x02
45
#define BLINDS_TURN_RIGHT   0x02
48
 
46
 
49
#define STEPS_PER_TURN_PERIOD   10 /* number of steps for each adjustment */
47
#define STEPS_PER_TURN_PERIOD   10 /* number of steps for each adjustment */
50
#define TURN_PERIOD             100 /* ms */
48
#define TURN_PERIOD             100 /* ms */
51
#define STATUS_SEND_PERIOD      10000 /* ms */
49
#define STATUS_SEND_PERIOD      5000 /* ms */
52
#define FAILSAFE_SEND_PERIOD    10000 /* ms */
50
#define FAILSAFE_SEND_PERIOD    10000 /* ms */
53
#define BOUNCE_TIME             10 /* ms */
51
#define BOUNCE_TIME             10 /* ms */
54
#define SERVO_FEED_TIME         2000 /* ms */
52
#define SERVO_FEED_TIME         2000 /* ms */
55
#define BUTTON1                 1
53
#define BUTTON1                 1
56
#define BUTTON2                 2
54
#define BUTTON2                 2
Line 156... Line 154...
156
            servoToTurn,
154
            servoToTurn,
157
            turnDirection = BLINDS_TURN_STOP; /* Specifies direction to turn or stopped */
155
            turnDirection = BLINDS_TURN_STOP; /* Specifies direction to turn or stopped */
158
    uint32_t boardTemperature = 0;
156
    uint32_t boardTemperature = 0;
159
    uint32_t timeStamp = 0, timeStampTurn = 0, servoFeed_timeStamp = 0;
157
    uint32_t timeStamp = 0, timeStampTurn = 0, servoFeed_timeStamp = 0;
160
 
158
 
-
 
159
    sei();
161
    adcTemperatureInit();
160
    adcTemperatureInit();
162
    rcServoInit();
161
    rcServoInit();
163
 
162
 
164
#if defined(TWO_BUTTON_MODE)
163
#if defined(TWO_BUTTON_MODE)
165
    /*
164
    /*
166
     * Initialize buttons
165
     * Initialize buttons
167
     * It is possible to use ie. sensors instead
166
     * It is possible to use ie. sensors instead
168
     * but then change this
167
     * but then change this
Line 178... Line 177...
178
#endif
177
#endif
179
    /* Set output and turn off the servo current feed */
178
    /* Set output and turn off the servo current feed */
180
    DDRC |= (1<<DDC0);
179
    DDRC |= (1<<DDC0);
181
    PORTC &= ~(1<<PC0);
180
    PORTC &= ~(1<<PC0);
182
 
181
 
183
    sei();
182
//  sei();
184
 
183
 
185
    txMsg.RemoteFlag = 0;
184
    txMsg.RemoteFlag = 0;
186
    txMsg.ExtendedFlag = 1;
185
    txMsg.ExtendedFlag = 1;
187
    txMsg.Id = (CLASS_SNS << CLASS_MASK_BITS)|(SNS_ACT_STATUS_SERVO << TYPE_MASK_BITS)|(NODE_ID << SID_MASK_BITS);
186
    txMsg.Id = (CLASS_SNS << CLASS_MASK_BITS)|(SNS_ACT_STATUS_SERVO << TYPE_MASK_BITS)|(NODE_ID << SID_MASK_BITS);
188
 
187
 
Line 239... Line 238...
239
                    }
238
                    }
240
                }
239
                }
241
                msg_received = FALSE;
240
                msg_received = FALSE;
242
        }
241
        }
243
 
242
 
244
        if( bios->timebase_get() - timeStamp  >= STATUS_SEND_PERIOD ){
243
        if( (bios->timebase_get() - timeStamp)  >= STATUS_SEND_PERIOD ){
245
            timeStamp = bios->timebase_get();
244
            timeStamp = bios->timebase_get();
246
            /* Send blinds status to CAN */
245
            /* Send blinds status to CAN */
247
 
246
 
248
            boardTemperature = getTC1047temperature();
247
            boardTemperature = getTC1047temperature();
249
 
248