Commit 554a12ad76343e97f9eb0cfd7f03b4575ec4f701

Authored by Imanol-Mikel Barba Sabariego
1 parent c71d0ff5

--no commit message

Project/applications/smartcities/adc.c
... ... @@ -12,7 +12,7 @@ uint32_t adc_batt_process()
12 12  
13 13 adcRegisterValue = adc_batt_read();
14 14 analogValue = ADCbatt_VREF_MINUS + (((adcRegisterValue - ADCbatt_MIN_VALUE)*(ADCbatt_VREF_PLUS - ADCbatt_VREF_MINUS))/(ADCbatt_MAX_VALUE - ADCbatt_MIN_VALUE));
15   - printf("Register value is %4u [%4u milliVolts are currently given to gpio %s]",adcRegisterValue, analogValue, ADCbatt_GPIO_STR);
  15 + printf("Register value is %4u [%4u milliVolts are currently given to gpio %s]\r\n",adcRegisterValue, analogValue, ADCbatt_GPIO_STR);
16 16 return analogValue;
17 17 }
18 18  
... ... @@ -22,7 +22,7 @@ void adc_batt_peripheralInit()
22 22 ADC_InitTypeDef ADC_InitStructure;
23 23 RCC_APB2PeriphClockCmd(ADCbatt_GPIO_RCC, ENABLE);
24 24 GPIO_InitStructure.GPIO_Pin = ADCbatt_GPIO_PIN;
25   - GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
  25 + GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
26 26 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
27 27 GPIO_Init(ADCbatt_GPIO_PORT, &GPIO_InitStructure);
28 28  
... ... @@ -43,6 +43,7 @@ void adc_batt_peripheralInit()
43 43 /* Say how many channels would be used by the sequencer */
44 44 ADC_InitStructure.ADC_NbrOfChannel = 1;
45 45  
  46 + ADC_RegularChannelConfig(ADCbatt, ADCbatt_CHANNEL, 1, ADCbatt_SAMPLETIME);
46 47 ADC_Init(ADCbatt, &ADC_InitStructure);
47 48 ADC_Cmd(ADCbatt, ENABLE);
48 49  
... ... @@ -58,7 +59,6 @@ void adc_batt_peripheralInit()
58 59  
59 60 uint16_t adc_batt_read()
60 61 {
61   - ADC_RegularChannelConfig(ADCbatt, ADCbatt_CHANNEL, 1, ADCbatt_SAMPLETIME);
62 62 /* Start the conversion */
63 63 ADC_SoftwareStartConvCmd(ADCbatt, ENABLE);
64 64 /* Wait until conversion completion */
... ... @@ -79,7 +79,7 @@ uint32_t adc_sound_process()
79 79  
80 80 adcRegisterValue = adc_sound_read();
81 81 analogValue = ADCsound_VREF_MINUS + (((adcRegisterValue - ADCsound_MIN_VALUE)*(ADCsound_VREF_PLUS - ADCsound_VREF_MINUS))/(ADCsound_MAX_VALUE - ADCsound_MIN_VALUE));
82   - printf("Register value is %4u [%4u milliVolts are currently given to gpio %s]",adcRegisterValue, analogValue, ADCsound_GPIO_STR);
  82 + printf("Register value is %4u [%4u milliVolts are currently given to gpio %s]\r\n",adcRegisterValue, analogValue, ADCsound_GPIO_STR);
83 83 return analogValue;
84 84 }
85 85  
... ... @@ -89,7 +89,7 @@ void adc_sound_peripheralInit()
89 89 ADC_InitTypeDef ADC_InitStructure;
90 90 RCC_APB2PeriphClockCmd(ADCsound_GPIO_RCC, ENABLE);
91 91 GPIO_InitStructure.GPIO_Pin = ADCsound_GPIO_PIN;
92   - GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
  92 + GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
93 93 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
94 94 GPIO_Init(ADCsound_GPIO_PORT, &GPIO_InitStructure);
95 95  
... ... @@ -110,7 +110,8 @@ void adc_sound_peripheralInit()
110 110 ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
111 111 /* Say how many channels would be used by the sequencer */
112 112 ADC_InitStructure.ADC_NbrOfChannel = 1;
113   -
  113 +
  114 + ADC_RegularChannelConfig(ADCsound, ADCsound_CHANNEL, 1, ADCsound_SAMPLETIME);
114 115 ADC_Init(ADCsound, &ADC_InitStructure);
115 116 ADC_Cmd(ADCsound, ENABLE);
116 117  
... ... @@ -126,7 +127,6 @@ void adc_sound_peripheralInit()
126 127  
127 128 uint16_t adc_sound_read()
128 129 {
129   - ADC_RegularChannelConfig(ADCsound, ADCsound_CHANNEL, 1, ADCsound_SAMPLETIME);
130 130 /* Start the conversion */
131 131 ADC_SoftwareStartConvCmd(ADCsound, ENABLE);
132 132 /* Wait until conversion completion */
... ...
Project/applications/smartcities/include/adc.h
... ... @@ -22,17 +22,17 @@
22 22 #define ADCbatt ADC1
23 23 #define ADCbatt_RCC RCC_APB2Periph_ADC1 /* */
24 24 #define ADCbatt_DIVIDER RCC_PCLK2_Div4 /* Can be 2/4/6/8. PCLK2 runs at 32Mhz, and max ADC clock is 14Mhz */
25   -#define ADCbatt_CHANNEL ADC_Channel_12 /* 0/17 */
  25 +#define ADCbatt_CHANNEL ADC_Channel_1 /* 0/17 */
26 26 #define ADCbatt_SAMPLETIME ADC_SampleTime_239Cycles5
27   -#define ADCbatt_GPIO_PIN GPIO_Pin_2
28   -#define ADCbatt_GPIO_PORT GPIOC
29   -#define ADCbatt_GPIO_RCC RCC_APB2Periph_GPIOC
30   -#define ADCbatt_GPIO_STR "PC2"
  27 +#define ADCbatt_GPIO_PIN GPIO_Pin_1
  28 +#define ADCbatt_GPIO_PORT GPIOA
  29 +#define ADCbatt_GPIO_RCC RCC_APB2Periph_GPIOA
  30 +#define ADCbatt_GPIO_STR "PA1"
31 31  
32 32 #define ADCsound ADC2
33 33 #define ADCsound_RCC RCC_APB2Periph_ADC2 /* */
34 34 #define ADCsound_DIVIDER RCC_PCLK2_Div4 /* Can be 2/4/6/8. PCLK2 runs at 32Mhz, and max ADC clock is 14Mhz */
35   -#define ADCsound_CHANNEL ADC_Channel_11 /* 0/17 */
  35 +#define ADCsound_CHANNEL ADC_Channel_2 /* 0/17 */
36 36 #define ADCsound_SAMPLETIME ADC_SampleTime_239Cycles5
37 37 #define ADCsound_GPIO_PIN GPIO_Pin_2
38 38 #define ADCsound_GPIO_PORT GPIOA
... ...
Project/applications/smartcities/json.c
... ... @@ -96,7 +96,20 @@ char* prepare_json_register_statement(module mod, sensor sens, char *additional_
96 96 char* prepare_observation(char* observation, uint32_t length)
97 97 {
98 98 char *json_data, *str_aux, *str_aux2;
99   - int value_length = find_next_index(observation,length,','); //EXPECTS FORMATTING!!!
  99 + int value_length = find_next_index(observation,length,',');
  100 + while(1)
  101 + {
  102 + printf("value_length = %d\r\n",value_length);
  103 + if(find_next_index(observation+value_length+1,length,','))
  104 + {
  105 + value_length += find_next_index(observation+value_length+1,length,',')+1;
  106 + }
  107 + else
  108 + {
  109 + printf("Comma in %d\r\n",value_length);
  110 + break;
  111 + }
  112 + }
100 113 int timestamp_length = length - (value_length + 1);
101 114 char *value = (char*) chHeapAlloc(NULL,value_length+1);
102 115 char *timestamp = (char*) chHeapAlloc(NULL,timestamp_length+1);
... ... @@ -181,7 +194,7 @@ uint32_t find_next_index(char* string, uint32_t length, char delimiter)
181 194 return i;
182 195 }
183 196 }
184   - return -1;
  197 + return 0;
185 198 }
186 199  
187 200 char* join_strings(char* str1, char* str2, uint32_t len1, uint32_t len2, uint8_t free_mem)
... ...