Subversion Repositories HomeAutomation

Rev

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

Rev 1978 Rev 2007
Line 2... Line 2...
2
#include "sns_DHT11.h"
2
#include "sns_DHT11.h"
3
uint8_t sendNewTemp = 0;
3
uint8_t sendNewTemp = 0;
4
uint8_t temperature = 0;
4
uint8_t temperature[DHT11_NUM_SENSORS];
5
uint8_t humidity = 0;
5
uint8_t humidity[DHT11_NUM_SENSORS];
-
 
6
uint8_t sns_DHT11_currentSensor = DHT11_NUM_SENSORS-1;
6
 
7
 
7
#if sns_DHT11_USEEEPROM==1
8
#if sns_DHT11_USEEEPROM==1
8
#include "sns_DHT11_eeprom.h"
9
#include "sns_DHT11_eeprom.h"
9
struct eeprom_sns_DHT11 EEMEM eeprom_sns_DHT11 =
10
struct eeprom_sns_DHT11 EEMEM eeprom_sns_DHT11 =
10
{
11
{
Line 21... Line 22...
21
void ConvertTemperature2_callback(uint8_t timer)
22
void ConvertTemperature2_callback(uint8_t timer)
22
{
23
{
23
    uint8_t word[5];
24
    uint8_t word[5];
24
    if (dht11_readData((uint8_t*) word)) {
25
    if (dht11_readData((uint8_t*) word)) {
25
        sendNewTemp = 1;
26
        sendNewTemp = 1;
26
        temperature = word[2];
27
        temperature[sns_DHT11_currentSensor] = word[2];
27
        humidity = word[0];
28
        humidity[sns_DHT11_currentSensor] = word[0];
28
    }
29
    }
29
}
30
}
30
 
31
 
31
void ConvertTemperature_callback_DHT11(uint8_t timer)
32
void ConvertTemperature_callback_DHT11(uint8_t timer)
32
{
33
{
-
 
34
#ifndef DHT11_ONE_BUS
-
 
35
    sns_DHT11_currentSensor++;
-
 
36
    if (sns_DHT11_currentSensor >= DHT11_NUM_SENSORS)
-
 
37
    {sns_DHT11_currentSensor = 0;}
-
 
38
 
-
 
39
    switch (sns_DHT11_currentSensor)
-
 
40
    {
-
 
41
        case 0:
-
 
42
            dht11_set_bus(DHT11_PIN_ch0);
-
 
43
            break;
-
 
44
        case 1:
-
 
45
            dht11_set_bus(DHT11_PIN_ch1);
-
 
46
            break;
-
 
47
    }
-
 
48
#endif
-
 
49
 
33
    dht11_start();
50
    dht11_start();
34
    Timer_SetTimeout(sns_DHT11_18MS_TIMER, 18, TimerTypeOneShot, &ConvertTemperature2_callback);
51
    Timer_SetTimeout(sns_DHT11_18MS_TIMER, 18, TimerTypeOneShot, &ConvertTemperature2_callback);
35
}
52
}
36
 
53
 
37
void sns_DHT11_Init(void)
54
void sns_DHT11_Init(void)
Line 49... Line 66...
49
      eeprom_write_word_crc(EEDATA16.y, 0x1234, WITHOUT_CRC);
66
      eeprom_write_word_crc(EEDATA16.y, 0x1234, WITHOUT_CRC);
50
      eeprom_write_dword_crc(EEDATA32.y, 0x12345678, WITHOUT_CRC);
67
      eeprom_write_dword_crc(EEDATA32.y, 0x12345678, WITHOUT_CRC);
51
      EEDATA_UPDATE_CRC;
68
      EEDATA_UPDATE_CRC;
52
    }
69
    }
53
#endif
70
#endif
54
    ///TODO: Initialize hardware etc here
-
 
55
 
-
 
56
    // to use PCINt lib, call this function: (the callback function look as a timer callback function)
-
 
57
    // Pcint_SetCallbackPin(sns_DHT11_PCINT, EXP_C , &sns_DHT11_pcint_callback);
-
 
58
    Timer_SetTimeout(sns_DHT11_TIMER, 5000, TimerTypeFreeRunning, &ConvertTemperature_callback_DHT11);
71
    Timer_SetTimeout(sns_DHT11_TIMER, 5000, TimerTypeFreeRunning, &ConvertTemperature_callback_DHT11);
59
}
72
}
60
 
73
 
61
void sns_DHT11_Process(void)
74
void sns_DHT11_Process(void)
62
{
75
{
63
    if (sendNewTemp) {
76
    if (sendNewTemp) {
64
        uint16_t temp;
77
        uint16_t temp;
65
        sendNewTemp = 0;
78
        sendNewTemp = 0;
66
 
79
 
67
        StdCan_Msg_t txMsg;
80
        StdCan_Msg_t txMsg;
68
 
81
 
69
        StdCan_Set_class(txMsg.Header, CAN_MODULE_CLASS_SNS);
82
        StdCan_Set_class(txMsg.Header, CAN_MODULE_CLASS_SNS);
70
        StdCan_Set_direction(txMsg.Header, DIRECTIONFLAG_FROM_OWNER);
83
        StdCan_Set_direction(txMsg.Header, DIRECTIONFLAG_FROM_OWNER);
71
        txMsg.Header.ModuleType = CAN_MODULE_TYPE_SNS_DHT11;
84
        txMsg.Header.ModuleType = CAN_MODULE_TYPE_SNS_DHT11;
72
        txMsg.Header.ModuleId = sns_DHT11_ID;
85
        txMsg.Header.ModuleId = sns_DHT11_ID;
73
        txMsg.Header.Command = CAN_MODULE_CMD_PHYSICAL_TEMPERATURE_CELSIUS;
86
        txMsg.Header.Command = CAN_MODULE_CMD_PHYSICAL_TEMPERATURE_CELSIUS;
74
        txMsg.Length = 3;
87
        txMsg.Length = 3;
75
 
88
 
76
        txMsg.Data[0] = 1;
89
        txMsg.Data[0] = 1;
77
        temp = temperature*64;
90
        temp = temperature[sns_DHT11_currentSensor]*64;
78
        txMsg.Data[1] = (uint8_t)(temp >> 8);
91
        txMsg.Data[1] = (uint8_t)(temp >> 8);
79
        txMsg.Data[2] = (uint8_t)(temp & 0xff);
92
        txMsg.Data[2] = (uint8_t)(temp & 0xff);
80
        while (StdCan_Put(&txMsg) != StdCan_Ret_OK);
93
        while (StdCan_Put(&txMsg) != StdCan_Ret_OK);
81
 
94
 
82
        StdCan_Set_class(txMsg.Header, CAN_MODULE_CLASS_SNS);
95
        StdCan_Set_class(txMsg.Header, CAN_MODULE_CLASS_SNS);
83
        StdCan_Set_direction(txMsg.Header, DIRECTIONFLAG_FROM_OWNER);
96
        StdCan_Set_direction(txMsg.Header, DIRECTIONFLAG_FROM_OWNER);
84
        txMsg.Header.ModuleType = CAN_MODULE_TYPE_SNS_DHT11;
97
        txMsg.Header.ModuleType = CAN_MODULE_TYPE_SNS_DHT11;
85
        txMsg.Header.ModuleId = sns_DHT11_ID;
98
        txMsg.Header.ModuleId = sns_DHT11_ID;
86
        txMsg.Header.Command = CAN_MODULE_CMD_PHYSICAL_HUMIDITY_PERCENT;
99
        txMsg.Header.Command = CAN_MODULE_CMD_PHYSICAL_HUMIDITY_PERCENT;
87
        txMsg.Length = 3;
100
        txMsg.Length = 3;
88
 
101
 
89
        txMsg.Data[0] = 1;
102
        txMsg.Data[0] = 1;
90
        temp = humidity*64;
103
        temp = humidity[sns_DHT11_currentSensor]*64;
91
        txMsg.Data[1] = (uint8_t)(temp >> 8);
104
        txMsg.Data[1] = (uint8_t)(temp >> 8);
92
        txMsg.Data[2] = (uint8_t)(temp & 0xff);
105
        txMsg.Data[2] = (uint8_t)(temp & 0xff);
93
        while (StdCan_Put(&txMsg) != StdCan_Ret_OK);
106
        while (StdCan_Put(&txMsg) != StdCan_Ret_OK);
94
 
107
 
95
    }
108
    }
96
 
-
 
97
    ///TODO: Stuff that needs doing is done here
-
 
98
}
109
}
99
 
110
 
100
void sns_DHT11_HandleMessage(StdCan_Msg_t *rxMsg)
111
void sns_DHT11_HandleMessage(StdCan_Msg_t *rxMsg)
101
{
112
{
102
    if (    StdCan_Ret_class(rxMsg->Header) == CAN_MODULE_CLASS_SNS && ///TODO: Change this to the actual class type
113
    if (    StdCan_Ret_class(rxMsg->Header) == CAN_MODULE_CLASS_SNS &&
103
        StdCan_Ret_direction(rxMsg->Header) == DIRECTIONFLAG_FROM_OWNER &&
114
        StdCan_Ret_direction(rxMsg->Header) == DIRECTIONFLAG_FROM_OWNER &&
104
        rxMsg->Header.ModuleType == CAN_MODULE_TYPE_SNS_DHT11 && ///TODO: Change this to the actual module type
115
        rxMsg->Header.ModuleType == CAN_MODULE_TYPE_SNS_DHT11 &&
105
        rxMsg->Header.ModuleId == sns_DHT11_ID)
116
        rxMsg->Header.ModuleId == sns_DHT11_ID)
106
    {
117
    {
107
        StdCan_Msg_t txMsg;
118
        StdCan_Msg_t txMsg;
108
        switch (rxMsg->Header.Command)
119
        switch (rxMsg->Header.Command)
109
        {
120
        {
Line 118... Line 129...
118
                txMsg.Header.ModuleId = sns_DHT11_ID;
129
                txMsg.Header.ModuleId = sns_DHT11_ID;
119
                txMsg.Header.Command = CAN_MODULE_CMD_GLOBAL_REPORT_INTERVAL;
130
                txMsg.Header.Command = CAN_MODULE_CMD_GLOBAL_REPORT_INTERVAL;
120
                txMsg.Length = 1;
131
                txMsg.Length = 1;
121
 
132
 
122
                //txMsg.Data[0] = sns_ds18x20_ReportInterval;
133
                //txMsg.Data[0] = sns_ds18x20_ReportInterval;
123
 
134
 
124
                StdCan_Put(&txMsg);
135
                StdCan_Put(&txMsg);
125
                break;
136
                break;
126
        }
137
        }
127
    }
138
    }
128
}
139
}
129
 
140
 
130
void sns_DHT11_List(uint8_t ModuleSequenceNumber)
141
void sns_DHT11_List(uint8_t ModuleSequenceNumber)
131
{
142
{
132
    StdCan_Msg_t txMsg;
143
    StdCan_Msg_t txMsg;
133
 
144
 
134
    StdCan_Set_class(txMsg.Header, CAN_MODULE_CLASS_SNS); ///TODO: Change this to the actual class type
145
    StdCan_Set_class(txMsg.Header, CAN_MODULE_CLASS_SNS);
135
    StdCan_Set_direction(txMsg.Header, DIRECTIONFLAG_FROM_OWNER);
146
    StdCan_Set_direction(txMsg.Header, DIRECTIONFLAG_FROM_OWNER);
136
    txMsg.Header.ModuleType = CAN_MODULE_TYPE_SNS_DHT11; ///TODO: Change this to the actual module type
147
    txMsg.Header.ModuleType = CAN_MODULE_TYPE_SNS_DHT11;
137
    txMsg.Header.ModuleId = sns_DHT11_ID;
148
    txMsg.Header.ModuleId = sns_DHT11_ID;
138
    txMsg.Header.Command = CAN_MODULE_CMD_GLOBAL_LIST;
149
    txMsg.Header.Command = CAN_MODULE_CMD_GLOBAL_LIST;
139
    txMsg.Length = 6;
150
    txMsg.Length = 6;
140
 
151
 
141
    uint32_t HwId=BIOS_GetHwId();
152
    uint32_t HwId=BIOS_GetHwId();