Subversion Repositories HomeAutomation

Rev

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

Rev 352 Rev 354
Line 51... Line 51...
51
 * Global variables
51
 * Global variables
52
 * -----------------------------------------------------------------------*/
52
 * -----------------------------------------------------------------------*/
53
#if TWO_BUTTON_MODE
53
#if TWO_BUTTON_MODE
54
Can_Message_t txMsg_Button;
54
Can_Message_t txMsg_Button;
55
#endif
55
#endif
-
 
56
 
56
 
57
 
57
uint8_t relayStatus, failsafe_flag = 0;
58
uint8_t relayStatus, failsafe_flag = 0;
58
uint32_t boardTemperature = 0;
59
uint32_t boardTemperature = 0;
59
Can_Message_t txMsg;
60
Can_Message_t txMsg;
60
 
61
 
Line 92... Line 93...
92
                    if(relayStatus == RELAY_OFF){
93
                    if(relayStatus == RELAY_OFF){
93
                        relayStatus = relayOn();
94
                        relayStatus = relayOn();
94
                    }else{
95
                    }else{
95
                        relayStatus = relayOff();
96
                        relayStatus = relayOff();
96
                        txMsg.Id = 0x8000113UL; // FIXME
97
                        txMsg.Id = 0x8000113UL; // FIXME
97
                        bios->can_send(&txMsg);
98
                        bios->can_send(&txMsg);
98
                    }
99
                    }
99
 
100
 
100
            }else if(msg->Data.bytes[0] == RELAY_CMD_STATUS && !failsafe_flag){
101
            }else if(msg->Data.bytes[0] == RELAY_CMD_STATUS && !failsafe_flag){
101
                // Send relay status to CAN
102
                // Send relay status to CAN
102
                boardTemperature = getTC1047temperature();
103
                boardTemperature = getTC1047temperature();
103
 
104
 
104
                if( (int32_t)boardTemperature >= FAILSAFE_TRESHOLD ){
105
                if( (int32_t)boardTemperature >= FAILSAFE_TRESHOLD ){
Line 113... Line 114...
113
                    txMsg.Id = ( CLASS_SNS<<CLASS_MASK_BITS )|( SNS_ACT_STATUS_RELAY<<TYPE_MASK_BITS )|(NODE_ID);
114
                    txMsg.Id = ( CLASS_SNS<<CLASS_MASK_BITS )|( SNS_ACT_STATUS_RELAY<<TYPE_MASK_BITS )|(NODE_ID);
114
                    bios->can_send( &txMsg );
115
                    bios->can_send( &txMsg );
115
                }
116
                }
116
            }else if(msg->Data.bytes[0] == RELAY_CMD_RESET){
117
            }else if(msg->Data.bytes[0] == RELAY_CMD_RESET){
117
                // Return to normal operation
118
                // Return to normal operation
118
                failsafe_flag = 0;
119
                failsafe_flag = 0;
119
            }
120
            }
120
        }
121
        }
121
    }
122
    }
122
}
123
}
123
 
124
 
124
/*----------------------------------------------------------------------------
125
/*----------------------------------------------------------------------------
Line 130... Line 131...
130
    /*
131
    /*
131
     * Auxiliary button pressed and released
132
     * Auxiliary button pressed and released
132
     * Check time between press and release to eliminate bounces
133
     * Check time between press and release to eliminate bounces
133
     */
134
     */
134
    static uint32_t buttonTime[2];
135
    static uint32_t buttonTime[2];
135
 
136
 
136
    txMsg_Button.RemoteFlag = 0;
137
    txMsg_Button.RemoteFlag = 0;
137
    txMsg_Button.ExtendedFlag = 1;
138
    txMsg_Button.ExtendedFlag = 1;
138
 
139
 
139
    if( (PIND & (1<<PD6)) == 0){
140
    if( (PIND & (1<<PD6)) == 0){
140
        /* Button pressed */
141
        /* Button pressed */
141
        buttonTime[0] = Timebase_CurrentTime();
142
        buttonTime[0] = Timebase_CurrentTime();
142
    }else if( (PIND & (1<<PD6)) == 1){
143
    }else if( (PIND & (1<<PD6)) == 1){
143
        if( Timebase_PassedTimeMillis( buttonTime[0] ) >= BOUNCE_TIME ){
144
        if( Timebase_PassedTimeMillis( buttonTime[0] ) >= BOUNCE_TIME ){
Line 195... Line 196...
195
 
196
 
196
    // Control channel for relay
197
    // Control channel for relay
197
    DDRC |= (1<<DDC1);
198
    DDRC |= (1<<DDC1);
198
 
199
 
199
    // Set up callback for CAN messages
200
    // Set up callback for CAN messages
200
    bios->can_callback = &can_receive;
201
//  bios->can_callback = &can_receive;
201
 
202
 
202
    txMsg.RemoteFlag = 0;
203
    txMsg.RemoteFlag = 0;
203
    txMsg.ExtendedFlag = 1;
204
    txMsg.ExtendedFlag = 1;
204
    txMsg.DataLength = 4;
205
    txMsg.DataLength = 4;
205
 
206
 
Line 208... Line 209...
208
    // Turn relay off
209
    // Turn relay off
209
    relayStatus = relayOff();
210
    relayStatus = relayOff();
210
    txMsg.Id = 0x8000110UL; // FIXME
211
    txMsg.Id = 0x8000110UL; // FIXME
211
    bios->can_send(&txMsg);
212
    bios->can_send(&txMsg);
212
 
213
 
213
    uint32_t timeStamp = 0;
214
    uint32_t timeStamp = bios->timebase_get(), temp;
214
 
215
 
215
 
216
 
216
    // Main loop
217
    // Main loop
217
    while (1) {
218
    while (1) {
218
 
219
 
-
 
220
        temp = bios->timebase_get();
219
        if( bios->timebase_get() - timeStamp >= STATUS_SEND_PERIOD ){
221
        if( temp - timeStamp >= STATUS_SEND_PERIOD ){
220
            timeStamp = bios->timebase_get();
222
            timeStamp = temp;
221
            // Send relay status to CAN
223
            // Send relay status to CAN
222
 
224
 
223
            boardTemperature = getTC1047temperature();
225
//          boardTemperature = getTC1047temperature();
224
 
226
 
225
            if( (int32_t)boardTemperature >= FAILSAFE_TRESHOLD ){
227
//          if( (int32_t)boardTemperature >= FAILSAFE_TRESHOLD ){
226
                relayFailsafe();
228
//              relayFailsafe();
227
            }else{
229
//          }else{
228
                txMsg.Data.bytes[0] = boardTemperature & 0x00FF;
230
                txMsg.Data.bytes[0] = timeStamp & 0x000000FF; //boardTemperature & 0x00FF;
229
                txMsg.Data.bytes[1] = (boardTemperature & 0xFF00)>>8;
231
                txMsg.Data.bytes[1] = (timeStamp & 0x0000FF00)>>8; //(boardTemperature & 0xFF00)>>8;
230
                txMsg.Data.bytes[2] = relayStatus;
232
                txMsg.Data.bytes[2] = (timeStamp & 0x00FF0000)>>16; //relayStatus;
231
                txMsg.Data.bytes[3] = 0;
233
                txMsg.Data.bytes[3] = (timeStamp & 0xFF000000)>>24; //0;
232
                txMsg.Id = ( CLASS_SNS<<CLASS_MASK_BITS )|( SNS_ACT_STATUS_RELAY<<TYPE_MASK_BITS )|(NODE_ID);
234
                txMsg.Id = ( CLASS_SNS<<CLASS_MASK_BITS )|( SNS_ACT_STATUS_RELAY<<TYPE_MASK_BITS )|(NODE_ID);
233
                bios->can_send( &txMsg );
235
                bios->can_send( &txMsg );
234
            }
236
//          }
235
        }
237
        }
236
    }
238
    }
237
    return 0;
239
    return 0;
238
}
240
}
239
 
241