Subversion Repositories HomeAutomation

Rev

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

Rev 501 Rev 502
Line 41... Line 41...
41
 
41
 
42
#define BLINDS_TURN_STOP    0x00
42
#define BLINDS_TURN_STOP    0x00
43
#define BLINDS_TURN_CCW     0x01
43
#define BLINDS_TURN_CCW     0x01
44
#define BLINDS_TURN_CW      0x02
44
#define BLINDS_TURN_CW      0x02
45
 
45
 
46
#define STEPS_PER_TURN_PERIOD   10 // number of steps for each adjustment
-
 
47
#define TURN_PERIOD             100 // ms
-
 
48
#define STATUS_SEND_PERIOD      5000 // ms
46
#define STATUS_SEND_PERIOD      5000 // ms
49
#define FAILSAFE_SEND_PERIOD    10000 // ms
47
#define FAILSAFE_SEND_PERIOD    10000 // ms
50
#define BOUNCE_TIME             10 // ms
48
#define BOUNCE_TIME             10 // ms
51
#define BUTTON1                 1
49
#define BUTTON1                 1
52
#define BUTTON2                 2
50
#define BUTTON2                 2
53
 
51
 
54
#define SERVO_FEED_PORT         PORTD
52
#define SERVO_FEED_PORT         PORTC
55
#define SERVO_FEED_DDR          DDRD
53
#define SERVO_FEED_DDR          DDRC
56
#define SERVO_FEED_PIN          PD2
54
#define SERVO_FEED_PIN          PC0
57
 
55
 
58
#define APP_TYPE    CAN_APPTYPES_SERVO
56
#define APP_TYPE    CAN_APPTYPES_SERVO
59
#define APP_VERSION 0x0001
57
#define APP_VERSION 0x0001
60
 
58
 
61
 
59
 
Line 133... Line 131...
133
 
131
 
134
/*-----------------------------------------------------------------------------
132
/*-----------------------------------------------------------------------------
135
 * Main Program
133
 * Main Program
136
 *---------------------------------------------------------------------------*/
134
 *---------------------------------------------------------------------------*/
137
int main(void) {
135
int main(void) {
138
    uint8_t temp_id;
136
    uint8_t temp_id, servoid;
139
    uint16_t acttype, servoid;
137
    uint16_t acttype;
140
 
138
 
141
    uint8_t //blindsStatus, /* Position (-128 to 127) */
139
    uint8_t //blindsStatus, /* Position (-128 to 127) */
142
            servoToTurn,
140
            servoToTurn,
143
            turnDirection = BLINDS_TURN_STOP; /* Specifies direction to turn or stopped */
141
            turnDirection = BLINDS_TURN_STOP; /* Specifies direction to turn or stopped */
144
    uint32_t boardTemperature = 0;
142
    uint32_t boardTemperature = 0;
Line 169... Line 167...
169
    PCICR |= (1<<PCIE2);
167
    PCICR |= (1<<PCIE2);
170
    /* Unmask PD1 and SERVO_FEED_PIN */
168
    /* Unmask PD1 and SERVO_FEED_PIN */
171
    PCMSK2 |= (1<<PCINT16) | (1<<PCINT17);
169
    PCMSK2 |= (1<<PCINT16) | (1<<PCINT17);
172
#endif
170
#endif
173
    /* Set output and turn off the servo current feed */
171
    /* Set output and turn off the servo current feed */
174
    SERVO_FEED_DDR |= (1<<SERVO_FEED_PIN);
172
    //SERVO_FEED_DDR |= (1<<SERVO_FEED_PIN);
175
    SERVO_FEED_PORT &= ~(1<<SERVO_FEED_PIN);
173
    //SERVO_FEED_PORT &= ~(1<<SERVO_FEED_PIN);
176
 
174
 
177
    txMsg.Id = (CAN_NMT_APP_START << CAN_SHIFT_NMT_TYPE) | (NODE_ID << CAN_SHIFT_NMT_SID);
175
    txMsg.Id = (CAN_NMT_APP_START << CAN_SHIFT_NMT_TYPE) | (NODE_ID << CAN_SHIFT_NMT_SID);
178
    txMsg.RemoteFlag = 0;
176
    txMsg.RemoteFlag = 0;
179
    txMsg.ExtendedFlag = 1;
177
    txMsg.ExtendedFlag = 1;
180
    txMsg.DataLength = 4;
178
    txMsg.DataLength = 4;
Line 225... Line 223...
225
 
223
 
226
                            turnDirection = (rxMsg.Data.bytes[0]&0x80)?BLINDS_TURN_CW:BLINDS_TURN_CCW; // FIXME riktning beroende på positivt eller negativt tal?
224
                            turnDirection = (rxMsg.Data.bytes[0]&0x80)?BLINDS_TURN_CW:BLINDS_TURN_CCW; // FIXME riktning beroende på positivt eller negativt tal?
227
                            servoToTurn = temp_id;
225
                            servoToTurn = temp_id;
228
                            servoFeed_timeStamp = Timebase_CurrentTime();
226
                            servoFeed_timeStamp = Timebase_CurrentTime();
229
 
227
 
230
                        }else if(rxMsg.Data.bytes[0] == BLINDS_CMD_STOP ){
228
                        }else if(rxMsg.Data.bytes[1] == BLINDS_CMD_STOP ){
231
                            // Stop turning
229
                            // Stop turning
232
 
230
 
233
                            turnDirection = BLINDS_TURN_STOP;
231
                            turnDirection = BLINDS_TURN_STOP;
234
 
232
 
235
                        }/*else if(rxMsg.Data.bytes[0] == BLINDS_CMD_STATUS){
233
                        }/*else if(rxMsg.Data.bytes[0] == BLINDS_CMD_STATUS){