Rev 1957 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed
| Rev 1957 | Rev 2032 | ||
|---|---|---|---|
| Line 4... | Line 4... | ||
| 4 | #include "../chn_ChnMaster/chn_ChnMaster.h" |
4 | #include "../chn_ChnMaster/chn_ChnMaster.h" |
| - | 5 | ||
| - | 6 | uint16_t sns_ds18s20_sensorids[DS18x20_MAXSENSORS] = {sns_ds18x20_chn_sensors}; |
|
| 5 | #endif |
7 | #endif |
| 6 | 8 | ||
| 7 | void ConvertTemperature(void); |
9 | void ConvertTemperature(void); |
| 8 | void ConvertTemperature_callback(uint8_t timer); |
10 | void ConvertTemperature_callback(uint8_t timer); |
| 9 | void ReadTemperature(void); |
11 | void ReadTemperature(void); |
| 10 | void ReadTemperature_callback(uint8_t timer); |
12 | void ReadTemperature_callback(uint8_t timer); |
| 11 | 13 | ||
| 12 | uint8_t sns_ds18x20_ReportInterval = (uint8_t)sns_ds18x20_SEND_PERIOD; |
14 | uint8_t sns_ds18x20_ReportInterval = (uint8_t)sns_ds18x20_SEND_PERIOD; |
| 13 | uint8_t NumberOfSensors = 0; |
15 | uint8_t NumberOfSensors = 0; |
| 14 | uint16_t SensorIds[DS18x20_MAXSENSORS]; |
16 | uint16_t SensorIds[DS18x20_MAXSENSORS]; |
| 15 | uint8_t FlagReadTemperature = 0, FlagConvertTemperature = 0, FlagSearchSensors = 0; |
17 | uint8_t FlagReadTemperature = 0, FlagConvertTemperature = 0, FlagSearchSensors = 0; |
| 16 | 18 | ||
| Line 19... | Line 21... | ||
| 19 | FlagReadTemperature = 1; |
21 | FlagReadTemperature = 1; |
| 20 | } |
22 | } |
| 21 | 23 | ||
| 22 | 24 | ||
| 23 | void ReadTemperature(void) |
25 | void ReadTemperature(void) |
| 24 | { |
26 | { |
| 25 | static uint8_t SearchSensorsTimeout = sns_ds18x20_SEARCH_TIMEOUT; |
27 | static uint8_t SearchSensorsTimeout = sns_ds18x20_SEARCH_TIMEOUT; |
| 26 | static uint8_t CurrentSensor = 0; |
28 | static uint8_t CurrentSensor = 0; |
| 27 | uint8_t subzero, cel, cel_frac_bits = 0; |
29 | uint8_t subzero, cel, cel_frac_bits = 0; |
| 28 | StdCan_Msg_t txMsg; |
30 | StdCan_Msg_t txMsg; |
| 29 | 31 | ||
| Line 31... | Line 33... | ||
| 31 | StdCan_Set_direction(txMsg.Header, DIRECTIONFLAG_FROM_OWNER); |
33 | StdCan_Set_direction(txMsg.Header, DIRECTIONFLAG_FROM_OWNER); |
| 32 | txMsg.Header.ModuleType = CAN_MODULE_TYPE_SNS_DS18X20; |
34 | txMsg.Header.ModuleType = CAN_MODULE_TYPE_SNS_DS18X20; |
| 33 | txMsg.Header.ModuleId = sns_ds18x20_ID; |
35 | txMsg.Header.ModuleId = sns_ds18x20_ID; |
| 34 | txMsg.Header.Command = CAN_MODULE_CMD_PHYSICAL_TEMPERATURE_CELSIUS; |
36 | txMsg.Header.Command = CAN_MODULE_CMD_PHYSICAL_TEMPERATURE_CELSIUS; |
| 35 | txMsg.Length = 3; |
37 | txMsg.Length = 3; |
| 36 | 38 | ||
| 37 | txMsg.Data[0] = SensorIds[CurrentSensor]; |
39 | txMsg.Data[0] = SensorIds[CurrentSensor]; |
| 38 | 40 | ||
| 39 | if (DS18X20_read_meas(&gSensorIDs[CurrentSensor][0], &subzero, &cel, &cel_frac_bits) == DS18X20_OK) |
41 | if (DS18X20_read_meas(&gSensorIDs[CurrentSensor][0], &subzero, &cel, &cel_frac_bits) == DS18X20_OK) |
| 40 | { |
42 | { |
| 41 | int16_t temp = cel; |
43 | int16_t temp = cel; |
| Line 51... | Line 53... | ||
| 51 | 53 | ||
| 52 | txMsg.Data[1] = (uint8_t)(temp >> 8); |
54 | txMsg.Data[1] = (uint8_t)(temp >> 8); |
| 53 | txMsg.Data[2] = (uint8_t)(temp & 0xff); |
55 | txMsg.Data[2] = (uint8_t)(temp & 0xff); |
| 54 | 56 | ||
| 55 | #ifdef CHN_LOADED |
57 | #ifdef CHN_LOADED |
| - | 58 | for( uint8_t i=0; i<DS18x20_MAXSENSORS; i++) { |
|
| - | 59 | if( sns_ds18s20_sensorids[i] == SensorIds[CurrentSensor] ) { |
|
| 56 | chn_ChnMaster_UpdateChannel |
60 | chn_ChnMaster_UpdateChannel( sns_ds18x20_CHN_CHANNEL + i, (temp<<2) + 25600 ); |
| - | 61 | } |
|
| - | 62 | } |
|
| 57 | #endif |
63 | #endif |
| 58 | } |
64 | } |
| 59 | 65 | ||
| 60 | StdCan_Put(&txMsg); |
66 | StdCan_Put(&txMsg); |
| 61 | 67 | ||