Subversion Repositories HomeAutomation

Rev

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

Rev 2009 Rev 2010
Line 42... Line 42...
42
            dht11_set_bus(DHT11_PIN_ch0);
42
            dht11_set_bus(DHT11_PIN_ch0);
43
            break;
43
            break;
44
        case 1:
44
        case 1:
45
            dht11_set_bus(DHT11_PIN_ch1);
45
            dht11_set_bus(DHT11_PIN_ch1);
46
            break;
46
            break;
-
 
47
#ifdef DHT11_PIN_ch2
47
        case 2:
48
        case 2:
48
            dht11_set_bus(DHT11_PIN_ch2);
49
            dht11_set_bus(DHT11_PIN_ch2);
49
            break;
50
            break;
-
 
51
#endif
-
 
52
#ifdef DHT11_PIN_ch3
50
        case 3:
53
        case 3:
51
            dht11_set_bus(DHT11_PIN_ch3);
54
            dht11_set_bus(DHT11_PIN_ch3);
52
            break;
55
            break;
-
 
56
#endif
-
 
57
#ifdef DHT11_PIN_ch4
53
        case 4:
58
        case 4:
54
            dht11_set_bus(DHT11_PIN_ch4);
59
            dht11_set_bus(DHT11_PIN_ch4);
55
            break;
60
            break;
-
 
61
#endif
-
 
62
#ifdef DHT11_PIN_ch5
56
        case 5:
63
        case 5:
57
            dht11_set_bus(DHT11_PIN_ch5);
64
            dht11_set_bus(DHT11_PIN_ch5);
58
            break;
65
            break;
59
    }
-
 
60
#endif
66
#endif
-
 
67
    }
-
 
68
#endif
61
 
69
 
62
    dht11_start();
70
    dht11_start();
63
    Timer_SetTimeout(sns_DHT11_18MS_TIMER, 18, TimerTypeOneShot, &ConvertTemperature2_callback);
71
    Timer_SetTimeout(sns_DHT11_18MS_TIMER, 18, TimerTypeOneShot, &ConvertTemperature2_callback);
64
}
72
}
65
 
73
 
66
void sns_DHT11_Init(void)
74
void sns_DHT11_Init(void)
67
{
75
{
68
#if sns_DHT11_USEEEPROM==1
76
#if sns_DHT11_USEEEPROM==1
69
    if (EEDATA_OK)
77
    if (EEDATA_OK)
70
    {
78
    {
Line 76... Line 84...
76
    {   //The CRC of the EEPROM is not correct, store default values and update CRC
84
    {   //The CRC of the EEPROM is not correct, store default values and update CRC
77
      eeprom_write_byte_crc(EEDATA.x, 0xAB, WITHOUT_CRC);
85
      eeprom_write_byte_crc(EEDATA.x, 0xAB, WITHOUT_CRC);
78
      eeprom_write_word_crc(EEDATA16.y, 0x1234, WITHOUT_CRC);
86
      eeprom_write_word_crc(EEDATA16.y, 0x1234, WITHOUT_CRC);
79
      eeprom_write_dword_crc(EEDATA32.y, 0x12345678, WITHOUT_CRC);
87
      eeprom_write_dword_crc(EEDATA32.y, 0x12345678, WITHOUT_CRC);
80
      EEDATA_UPDATE_CRC;
88
      EEDATA_UPDATE_CRC;
81
    }
89
    }
82
#endif
90
#endif
83
    Timer_SetTimeout(sns_DHT11_TIMER, 5000, TimerTypeFreeRunning, &ConvertTemperature_callback_DHT11);
91
    Timer_SetTimeout(sns_DHT11_TIMER, 5000, TimerTypeFreeRunning, &ConvertTemperature_callback_DHT11);
84
}
92
}
85
 
93
 
86
void sns_DHT11_Process(void)
94
void sns_DHT11_Process(void)
Line 88... Line 96...
88
    if (sendNewTemp) {
96
    if (sendNewTemp) {
89
        uint16_t temp;
97
        uint16_t temp;
90
        sendNewTemp = 0;
98
        sendNewTemp = 0;
91
 
99
 
92
        StdCan_Msg_t txMsg;
100
        StdCan_Msg_t txMsg;
93
 
101
 
94
        StdCan_Set_class(txMsg.Header, CAN_MODULE_CLASS_SNS);
102
        StdCan_Set_class(txMsg.Header, CAN_MODULE_CLASS_SNS);
95
        StdCan_Set_direction(txMsg.Header, DIRECTIONFLAG_FROM_OWNER);
103
        StdCan_Set_direction(txMsg.Header, DIRECTIONFLAG_FROM_OWNER);
96
        txMsg.Header.ModuleType = CAN_MODULE_TYPE_SNS_DHT11;
104
        txMsg.Header.ModuleType = CAN_MODULE_TYPE_SNS_DHT11;
97
        txMsg.Header.ModuleId = sns_DHT11_ID;
105
        txMsg.Header.ModuleId = sns_DHT11_ID;
98
        txMsg.Header.Command = CAN_MODULE_CMD_PHYSICAL_TEMPERATURE_CELSIUS;
106
        txMsg.Header.Command = CAN_MODULE_CMD_PHYSICAL_TEMPERATURE_CELSIUS;
99
        txMsg.Length = 3;
107
        txMsg.Length = 3;
100
 
108
 
101
        txMsg.Data[0] = sns_DHT11_currentSensor;
109
        txMsg.Data[0] = sns_DHT11_currentSensor;
102
        temp = temperature[sns_DHT11_currentSensor]*64;
110
        temp = temperature[sns_DHT11_currentSensor]*64;
103
        txMsg.Data[1] = (uint8_t)(temp >> 8);
111
        txMsg.Data[1] = (uint8_t)(temp >> 8);
104
        txMsg.Data[2] = (uint8_t)(temp & 0xff);
112
        txMsg.Data[2] = (uint8_t)(temp & 0xff);
105
        while (StdCan_Put(&txMsg) != StdCan_Ret_OK);
113
        while (StdCan_Put(&txMsg) != StdCan_Ret_OK);
106
 
114
 
107
        StdCan_Set_class(txMsg.Header, CAN_MODULE_CLASS_SNS);
115
        StdCan_Set_class(txMsg.Header, CAN_MODULE_CLASS_SNS);
108
        StdCan_Set_direction(txMsg.Header, DIRECTIONFLAG_FROM_OWNER);
116
        StdCan_Set_direction(txMsg.Header, DIRECTIONFLAG_FROM_OWNER);
109
        txMsg.Header.ModuleType = CAN_MODULE_TYPE_SNS_DHT11;
117
        txMsg.Header.ModuleType = CAN_MODULE_TYPE_SNS_DHT11;
110
        txMsg.Header.ModuleId = sns_DHT11_ID;
118
        txMsg.Header.ModuleId = sns_DHT11_ID;
111
        txMsg.Header.Command = CAN_MODULE_CMD_PHYSICAL_HUMIDITY_PERCENT;
119
        txMsg.Header.Command = CAN_MODULE_CMD_PHYSICAL_HUMIDITY_PERCENT;
112
        txMsg.Length = 3;
120
        txMsg.Length = 3;
113
 
121
 
114
        txMsg.Data[0] = 1;
122
        txMsg.Data[0] = sns_DHT11_currentSensor;
115
        temp = humidity[sns_DHT11_currentSensor]*64;
123
        temp = humidity[sns_DHT11_currentSensor]*64;
116
        txMsg.Data[1] = (uint8_t)(temp >> 8);
124
        txMsg.Data[1] = (uint8_t)(temp >> 8);
117
        txMsg.Data[2] = (uint8_t)(temp & 0xff);
125
        txMsg.Data[2] = (uint8_t)(temp & 0xff);
118
        while (StdCan_Put(&txMsg) != StdCan_Ret_OK);
126
        while (StdCan_Put(&txMsg) != StdCan_Ret_OK);
119
 
127