Richard Hoekstra / Mbed 2 deprecated TLS2-Hoofdcontroller

Dependencies:   RPCInterface mbed

Committer:
RichardHoekstra
Date:
Thu Nov 17 18:25:06 2016 +0000
Revision:
5:846191af84ae
Parent:
4:02a2cfa49219
Child:
6:f609257cec0a
Gets sensor data, sends it to motor controller and/or keeps it around to send to Laptop.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
RichardHoekstra 0:bb1b87ed61e6 1 #include "mbed.h"
RichardHoekstra 1:f36fa4e37849 2 #include "mbed_rpc.h"
RichardHoekstra 0:bb1b87ed61e6 3 #include "SerialRPCInterface.h"
RichardHoekstra 1:f36fa4e37849 4
RichardHoekstra 4:02a2cfa49219 5 enum command_t{ //SENSORCONTROLLER COMMANDS
RichardHoekstra 4:02a2cfa49219 6 SET_MODE = 1,
RichardHoekstra 4:02a2cfa49219 7 SET_CONSTANT_PRESSURE,
RichardHoekstra 4:02a2cfa49219 8 SET_CONSTANT_FLOW,
RichardHoekstra 4:02a2cfa49219 9 SET_CONSTANT_SPEED,
RichardHoekstra 4:02a2cfa49219 10 SET_MIN,
RichardHoekstra 4:02a2cfa49219 11 SET_MAX,
RichardHoekstra 4:02a2cfa49219 12 SET_FREQUENCY,
RichardHoekstra 4:02a2cfa49219 13 RECEIVE_PRESSURE,
RichardHoekstra 4:02a2cfa49219 14 RECEIVE_FLOW,
RichardHoekstra 4:02a2cfa49219 15 //MOTORCONTROLLER COMMANDS
RichardHoekstra 4:02a2cfa49219 16 //Pressure sensor commands
RichardHoekstra 4:02a2cfa49219 17 SET_SENSOR_PRESSURE_1_SAMPLE_RATE = 13,
RichardHoekstra 4:02a2cfa49219 18 SET_SENSOR_PRESSURE_1_MVA,
RichardHoekstra 4:02a2cfa49219 19 SET_RESPONSE_SENSOR_PRESSURE_1,
RichardHoekstra 4:02a2cfa49219 20 SET_SENSOR_PRESSURE_2_SAMPLE_RATE,
RichardHoekstra 4:02a2cfa49219 21 SET_SENSOR_PRESSURE_2_MVA,
RichardHoekstra 4:02a2cfa49219 22 SET_RESPONSE_SENSOR_PRESSURE_2,
RichardHoekstra 4:02a2cfa49219 23 //Temperature sensor commands
RichardHoekstra 4:02a2cfa49219 24 SET_SENSOR_TEMPERATURE_1_SAMPLE_RATE,
RichardHoekstra 4:02a2cfa49219 25 SET_SENSOR_TEMPERATURE_1_MVA,
RichardHoekstra 4:02a2cfa49219 26 SET_RESPONSE_SENSOR_TEMPERATURE_1,
RichardHoekstra 4:02a2cfa49219 27 SET_SENSOR_TEMPERATURE_2_SAMPLE_RATE,
RichardHoekstra 4:02a2cfa49219 28 SET_SENSOR_TEMPERATURE_2_MVA,
RichardHoekstra 4:02a2cfa49219 29 SET_RESPONSE_SENSOR_TEMPERATURE_2,
RichardHoekstra 4:02a2cfa49219 30 //Flow sensor commands
RichardHoekstra 4:02a2cfa49219 31 SET_SENSOR_FLOW_SAMPLE_RATE,
RichardHoekstra 4:02a2cfa49219 32 SET_SENSOR_FLOW_MVA,
RichardHoekstra 4:02a2cfa49219 33 SET_RESPONSE_SENSOR_FLOW,
RichardHoekstra 4:02a2cfa49219 34 //Motor sensor
RichardHoekstra 4:02a2cfa49219 35 //Note: currently not used
RichardHoekstra 4:02a2cfa49219 36 SET_SENSOR_SPEED_SAMPLE_RATE,
RichardHoekstra 4:02a2cfa49219 37 SET_SENSOR_SPEED_MVA,
RichardHoekstra 4:02a2cfa49219 38 SET_RESPONSE_SENSOR_SPEED
RichardHoekstra 4:02a2cfa49219 39 } command;
RichardHoekstra 4:02a2cfa49219 40
RichardHoekstra 1:f36fa4e37849 41
RichardHoekstra 5:846191af84ae 42 //SENSOR OUTPUTS
RichardHoekstra 5:846191af84ae 43 float sensor_pressure_1 = 0;
RichardHoekstra 5:846191af84ae 44 float sensor_pressure_2 = 0;
RichardHoekstra 5:846191af84ae 45 float sensor_temperature_1 = 0;
RichardHoekstra 5:846191af84ae 46 float sensor_temperature_2 = 0;
RichardHoekstra 5:846191af84ae 47 float sensor_flow = 0;
RichardHoekstra 5:846191af84ae 48
RichardHoekstra 5:846191af84ae 49 RPCVariable<float> RPCsensor_pressure_1(&sensor_pressure_1, "sensor_pressure_1");
RichardHoekstra 5:846191af84ae 50 RPCVariable<float> RPCsensor_pressure_2(&sensor_pressure_2, "sensor_pressure_2");
RichardHoekstra 5:846191af84ae 51 RPCVariable<float> RPCsensor_temperature_1(&sensor_temperature_1, "sensor_temperature_1");
RichardHoekstra 5:846191af84ae 52 RPCVariable<float> RPCsensor_temperature_2(&sensor_temperature_2, "sensor_temperature_2");
RichardHoekstra 5:846191af84ae 53 RPCVariable<float> RPCsensor_flow(&sensor_flow, "sensor_flow");
RichardHoekstra 5:846191af84ae 54
RichardHoekstra 5:846191af84ae 55 //CONTROLLER SETTINGS
RichardHoekstra 5:846191af84ae 56 //SENSORCONTROLLER - MOVING AVERAGE
RichardHoekstra 5:846191af84ae 57 int druksensor1_mva_elements = 10,
RichardHoekstra 5:846191af84ae 58 druksensor2_mva_elements = 10,
RichardHoekstra 5:846191af84ae 59 tempsensor1_mva_elements = 10,
RichardHoekstra 5:846191af84ae 60 tempsensor2_mva_elements = 10,
RichardHoekstra 5:846191af84ae 61 flowsensor_mva_elements = 10;
RichardHoekstra 4:02a2cfa49219 62
RichardHoekstra 5:846191af84ae 63 RPCVariable<int> RPCdruksensor1_mva_elements(&druksensor1_mva_elements, "druksensor1_mva_elements");
RichardHoekstra 5:846191af84ae 64 RPCVariable<int> RPCdruksensor2_mva_elements(&druksensor2_mva_elements, "druksensor2_mva_elements");
RichardHoekstra 5:846191af84ae 65 RPCVariable<int> RPCtempsensor1_mva_elements(&tempsensor1_mva_elements, "tempsensor1_mva_elements");
RichardHoekstra 5:846191af84ae 66 RPCVariable<int> RPCtempsensor2_mva_elements(&tempsensor2_mva_elements, "tempsensor2_mva_elements");
RichardHoekstra 5:846191af84ae 67 RPCVariable<int> RPCflowsensor_mva_elements(&flowsensor_mva_elements, "flowsensor_mva_elements");
RichardHoekstra 5:846191af84ae 68 //MOTORCONTROLLER - SETTINGS
RichardHoekstra 5:846191af84ae 69 /*
RichardHoekstra 5:846191af84ae 70 SET_MODE:
RichardHoekstra 5:846191af84ae 71 SET_CONSTANT_PRESSURE:
RichardHoekstra 5:846191af84ae 72 SET_CONSTANT_FLOW:
RichardHoekstra 5:846191af84ae 73 SET_CONSTANT_SPEED:
RichardHoekstra 5:846191af84ae 74 SET_MIN:
RichardHoekstra 5:846191af84ae 75 SET_MAX:
RichardHoekstra 5:846191af84ae 76 SET_FREQUENCY:
RichardHoekstra 5:846191af84ae 77 RECEIVE_PRESSURE:
RichardHoekstra 5:846191af84ae 78 RECEIVE_FLOW:
RichardHoekstra 5:846191af84ae 79 */
RichardHoekstra 5:846191af84ae 80
RichardHoekstra 5:846191af84ae 81
RichardHoekstra 5:846191af84ae 82 //UPDATE PERIODS
RichardHoekstra 5:846191af84ae 83 float pressure1_update_period_s = 1;
RichardHoekstra 5:846191af84ae 84 float pressure2_update_period_s = 1;
RichardHoekstra 5:846191af84ae 85 float temperature1_update_period_s = 1;
RichardHoekstra 5:846191af84ae 86 float temperature2_update_period_s = 1;
RichardHoekstra 5:846191af84ae 87 float flow_update_period_s = 1;
RichardHoekstra 5:846191af84ae 88
RichardHoekstra 5:846191af84ae 89 RPCVariable<float> RPCpressure1_update_period_s(&pressure1_update_period_s, "pressure1_update_period_s");
RichardHoekstra 5:846191af84ae 90 RPCVariable<float> RPCpressure2_update_period_s(&pressure2_update_period_s, "pressure2_update_period_s");
RichardHoekstra 5:846191af84ae 91 RPCVariable<float> RPCtemperature1_update_period_s(&temperature1_update_period_s, "temperature1_update_period_s");
RichardHoekstra 5:846191af84ae 92 RPCVariable<float> RPCtemperature2_update_period_s(&temperature2_update_period_s, "temperature2_update_period_s");
RichardHoekstra 5:846191af84ae 93 RPCVariable<float> RPCflow_update_period_s(&flow_update_period_s, "flow_update_period_s");
RichardHoekstra 4:02a2cfa49219 94
RichardHoekstra 3:45e5d4a8a5f7 95 Serial pc(USBTX, USBRX); //Enable USB communication
RichardHoekstra 1:f36fa4e37849 96
RichardHoekstra 4:02a2cfa49219 97
RichardHoekstra 2:c3918fd40472 98 //I2C settings
RichardHoekstra 2:c3918fd40472 99 #define SDA D14
RichardHoekstra 2:c3918fd40472 100 #define SCL D15
RichardHoekstra 3:45e5d4a8a5f7 101 #define I2C_BUFFER_SIZE 10
RichardHoekstra 2:c3918fd40472 102 I2C master(SDA,SCL);
RichardHoekstra 1:f36fa4e37849 103
RichardHoekstra 2:c3918fd40472 104 //Controller addresses
RichardHoekstra 2:c3918fd40472 105 #define motor_addr 0x91
RichardHoekstra 2:c3918fd40472 106 #define interface_addr 0x92
RichardHoekstra 2:c3918fd40472 107 #define sensor_addr 0x93
RichardHoekstra 1:f36fa4e37849 108
RichardHoekstra 1:f36fa4e37849 109
RichardHoekstra 0:bb1b87ed61e6 110
RichardHoekstra 1:f36fa4e37849 111 //Handles all the RPC communication.
RichardHoekstra 1:f36fa4e37849 112 //Taken from the example at developer.mbed.org/cookbook
RichardHoekstra 2:c3918fd40472 113 void RPC_routine(){
RichardHoekstra 1:f36fa4e37849 114 static char buf[256], outbuf[256];
RichardHoekstra 1:f36fa4e37849 115 pc.gets(buf, 256);
RichardHoekstra 1:f36fa4e37849 116 //Call the static call method on the RPC class
RichardHoekstra 1:f36fa4e37849 117 RPC::call(buf, outbuf);
RichardHoekstra 1:f36fa4e37849 118 pc.printf("%s\n", outbuf);
RichardHoekstra 1:f36fa4e37849 119 }
RichardHoekstra 3:45e5d4a8a5f7 120 //Split an integer into two char
RichardHoekstra 4:02a2cfa49219 121 void int_to_2char(char* arr, int val, int first_element = 0){
RichardHoekstra 3:45e5d4a8a5f7 122 arr[first_element] = val>>8;
RichardHoekstra 3:45e5d4a8a5f7 123 arr[first_element+1] = val&255;
RichardHoekstra 3:45e5d4a8a5f7 124 }
RichardHoekstra 3:45e5d4a8a5f7 125 //Join two char to make an integer.
RichardHoekstra 4:02a2cfa49219 126 int char2_to_int(char* arr, int first_element = 0){
RichardHoekstra 3:45e5d4a8a5f7 127 return (arr[first_element]<<8)+arr[first_element+1];
RichardHoekstra 3:45e5d4a8a5f7 128 }
RichardHoekstra 0:bb1b87ed61e6 129
RichardHoekstra 4:02a2cfa49219 130 void updatePressure1(){
RichardHoekstra 4:02a2cfa49219 131 //Request data from sensor controller
RichardHoekstra 4:02a2cfa49219 132 //Immediately send it back to the motor controller
RichardHoekstra 4:02a2cfa49219 133 char buffer[3] = {0};
RichardHoekstra 4:02a2cfa49219 134 buffer[0] = SET_RESPONSE_SENSOR_PRESSURE_1;
RichardHoekstra 4:02a2cfa49219 135 master.write(sensor_addr,buffer,1);
RichardHoekstra 4:02a2cfa49219 136 buffer[0] = 0; //clear buffer again
RichardHoekstra 4:02a2cfa49219 137 master.read(sensor_addr,buffer,2);
RichardHoekstra 4:02a2cfa49219 138 //Update the pressure value for LabView
RichardHoekstra 4:02a2cfa49219 139 sensor_pressure_1 = char2_to_int(buffer,0);
RichardHoekstra 4:02a2cfa49219 140 //Move the received data over one spot to make place for a command byte
RichardHoekstra 4:02a2cfa49219 141 buffer[2] = buffer[1];
RichardHoekstra 4:02a2cfa49219 142 buffer[1] = buffer[0];
RichardHoekstra 4:02a2cfa49219 143 buffer[0] = RECEIVE_PRESSURE;
RichardHoekstra 4:02a2cfa49219 144 //Update motor controller
RichardHoekstra 4:02a2cfa49219 145 master.write(motor_addr,buffer,2);
RichardHoekstra 4:02a2cfa49219 146 }
RichardHoekstra 4:02a2cfa49219 147
RichardHoekstra 4:02a2cfa49219 148 void updatePressure2(){
RichardHoekstra 4:02a2cfa49219 149 //For comments see 'updatePressure1()'
RichardHoekstra 4:02a2cfa49219 150 char buffer[3] = {0};
RichardHoekstra 4:02a2cfa49219 151 buffer[0] = SET_RESPONSE_SENSOR_PRESSURE_2;
RichardHoekstra 4:02a2cfa49219 152 master.write(sensor_addr,buffer,1);
RichardHoekstra 4:02a2cfa49219 153 buffer[0] = 0;
RichardHoekstra 4:02a2cfa49219 154 master.read(sensor_addr,buffer,2);
RichardHoekstra 4:02a2cfa49219 155 sensor_pressure_2 = char2_to_int(buffer,0);
RichardHoekstra 4:02a2cfa49219 156 }
RichardHoekstra 4:02a2cfa49219 157
RichardHoekstra 4:02a2cfa49219 158
RichardHoekstra 4:02a2cfa49219 159 void updateTemperature1(){
RichardHoekstra 4:02a2cfa49219 160 //For comments see 'updatePressure1()'
RichardHoekstra 4:02a2cfa49219 161 char buffer[3] = {0};
RichardHoekstra 4:02a2cfa49219 162 buffer[0] = SET_RESPONSE_SENSOR_TEMPERATURE_1;
RichardHoekstra 4:02a2cfa49219 163 master.write(sensor_addr,buffer,1);
RichardHoekstra 4:02a2cfa49219 164 buffer[0] = 0;
RichardHoekstra 4:02a2cfa49219 165 master.read(sensor_addr,buffer,2);
RichardHoekstra 4:02a2cfa49219 166 sensor_temperature_1 = char2_to_int(buffer,0);
RichardHoekstra 4:02a2cfa49219 167 }
RichardHoekstra 4:02a2cfa49219 168
RichardHoekstra 4:02a2cfa49219 169 void updateTemperature2(){
RichardHoekstra 4:02a2cfa49219 170 //For comments see 'updatePressure1()'
RichardHoekstra 4:02a2cfa49219 171 char buffer[3] = {0};
RichardHoekstra 4:02a2cfa49219 172 buffer[0] = SET_RESPONSE_SENSOR_TEMPERATURE_2;
RichardHoekstra 4:02a2cfa49219 173 master.write(sensor_addr,buffer,1);
RichardHoekstra 4:02a2cfa49219 174 buffer[0] = 0;
RichardHoekstra 4:02a2cfa49219 175 master.read(sensor_addr,buffer,2);
RichardHoekstra 4:02a2cfa49219 176 sensor_temperature_2 = char2_to_int(buffer,0);
RichardHoekstra 4:02a2cfa49219 177 }
RichardHoekstra 4:02a2cfa49219 178
RichardHoekstra 4:02a2cfa49219 179 void updateFlow(){
RichardHoekstra 4:02a2cfa49219 180 //For comments see 'updatePressure1()'
RichardHoekstra 4:02a2cfa49219 181 char buffer[3] = {0};
RichardHoekstra 4:02a2cfa49219 182 buffer[0] = SET_RESPONSE_SENSOR_FLOW;
RichardHoekstra 4:02a2cfa49219 183 master.write(sensor_addr,buffer,1);
RichardHoekstra 4:02a2cfa49219 184 buffer[0] = 0;
RichardHoekstra 4:02a2cfa49219 185 master.read(sensor_addr,buffer,2);
RichardHoekstra 4:02a2cfa49219 186 sensor_flow = char2_to_int(buffer,0);
RichardHoekstra 4:02a2cfa49219 187 buffer[2] = buffer[1];
RichardHoekstra 4:02a2cfa49219 188 buffer[1] = buffer[0];
RichardHoekstra 4:02a2cfa49219 189 buffer[0] = RECEIVE_FLOW;
RichardHoekstra 4:02a2cfa49219 190 master.write(motor_addr,buffer,2);
RichardHoekstra 4:02a2cfa49219 191 }
RichardHoekstra 4:02a2cfa49219 192
RichardHoekstra 4:02a2cfa49219 193 Timer t;
RichardHoekstra 4:02a2cfa49219 194
RichardHoekstra 4:02a2cfa49219 195 Ticker tick_pressure1,
RichardHoekstra 4:02a2cfa49219 196 tick_pressure2,
RichardHoekstra 4:02a2cfa49219 197 tick_temperature1,
RichardHoekstra 4:02a2cfa49219 198 tick_temperature2,
RichardHoekstra 4:02a2cfa49219 199 tick_flow;
RichardHoekstra 4:02a2cfa49219 200
RichardHoekstra 4:02a2cfa49219 201 void updateI2Cstuff(){
RichardHoekstra 4:02a2cfa49219 202 //Only update when the variable has actually changed
RichardHoekstra 4:02a2cfa49219 203 static float old_pressure1_update_period_s,
RichardHoekstra 4:02a2cfa49219 204 old_pressure2_update_period_s,
RichardHoekstra 4:02a2cfa49219 205 old_temperature1_update_period_s,
RichardHoekstra 4:02a2cfa49219 206 old_temperature2_update_period_s,
RichardHoekstra 4:02a2cfa49219 207 old_flow_update_period_s;
RichardHoekstra 5:846191af84ae 208
RichardHoekstra 5:846191af84ae 209 static int old_druksensor1_mva_elements,
RichardHoekstra 5:846191af84ae 210 old_druksensor2_mva_elements,
RichardHoekstra 5:846191af84ae 211 old_tempsensor1_mva_elements,
RichardHoekstra 5:846191af84ae 212 old_tempsensor2_mva_elements,
RichardHoekstra 5:846191af84ae 213 old_flowsensor_mva_elements;
RichardHoekstra 5:846191af84ae 214
RichardHoekstra 4:02a2cfa49219 215 if(old_pressure1_update_period_s != pressure1_update_period_s){
RichardHoekstra 4:02a2cfa49219 216 tick_pressure1.attach(&updatePressure1,pressure1_update_period_s);
RichardHoekstra 4:02a2cfa49219 217 old_pressure1_update_period_s = pressure1_update_period_s;
RichardHoekstra 4:02a2cfa49219 218 }
RichardHoekstra 4:02a2cfa49219 219 if(old_pressure2_update_period_s != pressure2_update_period_s){
RichardHoekstra 4:02a2cfa49219 220 tick_pressure2.attach(&updatePressure2,pressure2_update_period_s);
RichardHoekstra 4:02a2cfa49219 221 old_pressure2_update_period_s = pressure2_update_period_s;
RichardHoekstra 4:02a2cfa49219 222 }
RichardHoekstra 4:02a2cfa49219 223 if(old_temperature1_update_period_s != temperature1_update_period_s){
RichardHoekstra 4:02a2cfa49219 224 tick_temperature1.attach(&updateTemperature1,temperature1_update_period_s);
RichardHoekstra 4:02a2cfa49219 225 old_temperature1_update_period_s = temperature1_update_period_s;
RichardHoekstra 4:02a2cfa49219 226 }
RichardHoekstra 4:02a2cfa49219 227 if(old_temperature2_update_period_s != temperature2_update_period_s){
RichardHoekstra 4:02a2cfa49219 228 tick_temperature2.attach(&updateTemperature2,temperature2_update_period_s);
RichardHoekstra 4:02a2cfa49219 229 old_temperature2_update_period_s = temperature2_update_period_s;
RichardHoekstra 4:02a2cfa49219 230 }
RichardHoekstra 4:02a2cfa49219 231 if(old_flow_update_period_s != flow_update_period_s){
RichardHoekstra 4:02a2cfa49219 232 tick_flow.attach(&updateFlow,flow_update_period_s);
RichardHoekstra 4:02a2cfa49219 233 old_flow_update_period_s = flow_update_period_s;
RichardHoekstra 4:02a2cfa49219 234 }
RichardHoekstra 5:846191af84ae 235 static int old_druksensor1_mva_elements,
RichardHoekstra 5:846191af84ae 236 old_druksensor2_mva_elements,
RichardHoekstra 5:846191af84ae 237 old_tempsensor1_mva_elements,
RichardHoekstra 5:846191af84ae 238 old_tempsensor2_mva_elements,
RichardHoekstra 5:846191af84ae 239 old_flowsensor_mva_elements;
RichardHoekstra 5:846191af84ae 240 //If LabView has changed variables for the motor or sensor settings
RichardHoekstra 5:846191af84ae 241 //then send an update over I2C
RichardHoekstra 5:846191af84ae 242 if(old_druksensor1_mva_elements != druksensor1_mva_elements){
RichardHoekstra 5:846191af84ae 243 char buffer[3] = {0};
RichardHoekstra 5:846191af84ae 244 buffer[0] = SET_SENSOR_PRESSURE_1_MVA;
RichardHoekstra 5:846191af84ae 245 int_to_2char(buffer, druksensor1_mva_elements, 1);
RichardHoekstra 5:846191af84ae 246 i2c.write(sensor_addr, buffer, 3);
RichardHoekstra 5:846191af84ae 247 old_druksensor1_mva_elements = druksensor1_mva_elements;
RichardHoekstra 5:846191af84ae 248 }
RichardHoekstra 5:846191af84ae 249 if(old_druksensor2_mva_elements != druksensor2_mva_elements){
RichardHoekstra 5:846191af84ae 250 char buffer[3] = {0};
RichardHoekstra 5:846191af84ae 251 buffer[0] = SET_SENSOR_PRESSURE_2_MVA;
RichardHoekstra 5:846191af84ae 252 int_to_2char(buffer, druksensor2_mva_elements, 1);
RichardHoekstra 5:846191af84ae 253 i2c.write(sensor_addr, buffer, 3);
RichardHoekstra 5:846191af84ae 254 old_druksensor2_mva_elements = druksensor2_mva_elements;
RichardHoekstra 5:846191af84ae 255 }
RichardHoekstra 5:846191af84ae 256 if(old_tempsensor1_mva_elements != tempsensor1_mva_elements){
RichardHoekstra 5:846191af84ae 257 char buffer[3] = {0};
RichardHoekstra 5:846191af84ae 258 buffer[0] = SET_SENSOR_TEMPERATURE_1_MVA;
RichardHoekstra 5:846191af84ae 259 int_to_2char(buffer, tempsensor1_mva_elements, 1);
RichardHoekstra 5:846191af84ae 260 i2c.write(sensor_addr, buffer, 3);
RichardHoekstra 5:846191af84ae 261 old_tempsensor1_mva_elements = tempsensor1_mva_elements;
RichardHoekstra 5:846191af84ae 262 }
RichardHoekstra 5:846191af84ae 263 if(old_tempsensor2_mva_elements != tempsensor2_mva_elements){
RichardHoekstra 5:846191af84ae 264 char buffer[3] = {0};
RichardHoekstra 5:846191af84ae 265 buffer[0] = SET_SENSOR_TEMPERATURE_2_MVA;
RichardHoekstra 5:846191af84ae 266 int_to_2char(buffer, tempsensor2_mva_elements, 1);
RichardHoekstra 5:846191af84ae 267 i2c.write(sensor_addr, buffer, 3);
RichardHoekstra 5:846191af84ae 268 old_tempsensor2_mva_elements = tempsensor2_mva_elements;
RichardHoekstra 5:846191af84ae 269 }
RichardHoekstra 5:846191af84ae 270 if(old_flowsensor_mva_elements != flowsensor_mva_elements){
RichardHoekstra 5:846191af84ae 271 char buffer[3] = {0};
RichardHoekstra 5:846191af84ae 272 buffer[0] = SET_SENSOR_FLOW_MVA;
RichardHoekstra 5:846191af84ae 273 int_to_2char(buffer, flowsensor_mva_elements, 1);
RichardHoekstra 5:846191af84ae 274 i2c.write(sensor_addr, buffer, 3);
RichardHoekstra 5:846191af84ae 275 old_flowsensor_mva_elements = flowsensor_mva_elements;
RichardHoekstra 5:846191af84ae 276 }
RichardHoekstra 4:02a2cfa49219 277 }
RichardHoekstra 4:02a2cfa49219 278
RichardHoekstra 2:c3918fd40472 279 int main() {
RichardHoekstra 4:02a2cfa49219 280 t.start();
RichardHoekstra 1:f36fa4e37849 281 while(1) {
RichardHoekstra 2:c3918fd40472 282 RPC_routine();
RichardHoekstra 4:02a2cfa49219 283 if(t.read() > 1){
RichardHoekstra 4:02a2cfa49219 284 //Only update the tickers every second
RichardHoekstra 4:02a2cfa49219 285 updateI2Cstuff();
RichardHoekstra 4:02a2cfa49219 286 }
RichardHoekstra 1:f36fa4e37849 287 wait_ms(1);
RichardHoekstra 1:f36fa4e37849 288 }
RichardHoekstra 1:f36fa4e37849 289 }