3 #include <system_def.h>
12 // OBJECT INTERFACE VARIABLES
14 unsigned int oi_cid_temp;
16 unsigned int oi_cid_hum;
17 unsigned int oi_period;
19 // OBJECT INTERFACE FUNCTIONS
20 int oi_cid_temp_wrfnc(ULOI_PARAM_coninfo void *context){
21 uloi_uint_wrfnc(ULOI_ARG_coninfo &oi_cid_temp);
25 int oi_cid_hum_wrfnc(ULOI_PARAM_coninfo void *context){
26 uloi_uint_wrfnc(ULOI_ARG_coninfo &oi_cid_hum);
30 int oi_period_wrfnc(ULOI_PARAM_coninfo void *context){
31 uloi_uint_wrfnc(ULOI_ARG_coninfo context);
39 static const int MAX_CID_CNT = 3;
40 cid_data_t cids[MAX_CID_CNT];
42 if (oi_period == HEART_PERIOD){
43 cids[cid_cnt].cid = HEART_CID;
44 cids[cid_cnt].value = status_val;
48 cids[cid_cnt].cid = oi_cid_temp;
49 cids[cid_cnt].value = oi_temperature;
53 cids[cid_cnt].cid = oi_cid_hum;
54 cids[cid_cnt].value = oi_humidity;
62 for (i=0; i<=CNT; i++) read_ADC(&adcst);
65 uchar buf[cid_cnt * 6 + 3];
66 for (buff_len = 0; buff_len < 3; buff_len++) buf[buff_len] = 0;
68 for(i=0; i<cid_cnt; i++) {
69 int2buf(buf + buff_len, cids[i].cid);
71 int2buf(buf + buff_len, 2);
73 int2buf(buf + buff_len, cids[i].value);
77 msgsend = ul_send_command(ul_fd, 0, UL_CMD_PDO, UL_BFL_NORE, (void*) buf, buff_len);
84 // oi_temperature = 25;
85 // // printf("temperature: %i\n",adcst.temp);
87 // // printf("humidity: %i\n",adcst.hum);
91 double tmp_temp, tmp_hum;
93 tmp_temp = (adcst.temp*ADres*100)/Aoz;
94 tmp_temp = ((int)(tmp_temp*10))/10.0;
96 tmp_hum = (adcst.hum*ADres)*20;
98 oi_temperature = tmp_temp * 10;
99 printf("temperature: %4.1f\n",tmp_temp);
100 oi_humidity = tmp_hum * 10;
101 printf("humidity: %4.1f\n",tmp_hum);
111 void check_PDO(int cid, int data){}
112 void regulate(void){}
114 void work_with(void){
116 led1_time = current_time();
117 led2_time = current_time();
120 // adcst.temp_tmp = 0;
122 // adcst.hum_tmp = 0;
125 time = current_time();
128 tmp_temp = (adcst.temp*ADres*100)/Aoz;
129 printf("temperature: %f\n",tmp_temp);
134 // // read_ADC(&adcst);
136 // if((current_time()-time) > 1000){
137 // printf("AD0.1 %i\n", adcst.temp);
138 // // printf("AD0.2 %i\n", adcst.hum);
139 // time = current_time();
144 void init_ADC (int selected){
147 PINSEL1|= 0x05000000; // P0.28 and P0.29 set for AD0.1 and AD0.2 inputs
148 AD0CR &= 0x00000000; // Clear All Bit Control
150 case 1: AD0CR |= 0x00000002; // Select ADC = AIN1, CLKDive => Pclk/(x+1)< 4.5Mhz
152 case 2: AD0CR |= 0x00000004; // Select ADC = AIN2
155 AD0CR |= 0x0000FF00; // ADC Clock = VBP(PCLK) / 7 1.55us
156 AD0CR &= 0xFFF1FFFF; // CLKS 11 ciclos de reloj Res Máx
157 AD0CR |= 0x00200000; // PDN = 1 = Active ADC Module
158 // AD0CR |= 0x00010000; // Burst = 1 = Continuing conversion
159 // AD0CR &= 0xFF3FFFFF; // TEST[1:0] = 00 = Modo normal
160 // AD0CR &= 0xF7FFFFFF; // EDGE = 0 = Flanco de bajada
161 // AD0STAT = 0x00000110;
165 int read_ADC (adc_stat_t *adcst){
169 AD0CR |= 0x01000000; // start conversion
170 while (!(AD0GDR & (ADGDR_DONE))); // wait for DONE to go high
172 adcst->read = AD0DR1; // get ADC data
173 adcst->read = ((adcst->read >>6) & 0x03FF); // extraction of result
174 adcst->temp_tmp += adcst->read;
177 AD0CR |= 0x01000000; // start conversion
178 while (!(AD0GDR & (ADGDR_DONE))); // wait for DONE to go high
180 adcst->read = AD0DR2;
181 adcst->read = ((adcst->read >>6) & 0x03FF); // extraction of result
182 adcst->hum_tmp += adcst->read;
185 if (adcst->cnt == CNT){
187 adcst->temp = adcst->temp_tmp/CNT;
188 adcst->hum = adcst->hum_tmp/CNT;