skeleton code for resistivity method
Dependencies: mbed
main.cpp@0:5699c19ed14b, 2015-11-18 (annotated)
- Committer:
- jfields
- Date:
- Wed Nov 18 21:02:09 2015 +0000
- Revision:
- 0:5699c19ed14b
skeleton code for resistivity method;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jfields | 0:5699c19ed14b | 1 | #include "mbed.h" |
jfields | 0:5699c19ed14b | 2 | #include "rtos.h" |
jfields | 0:5699c19ed14b | 3 | |
jfields | 0:5699c19ed14b | 4 | Serial pc(USBTX,USBRX); |
jfields | 0:5699c19ed14b | 5 | |
jfields | 0:5699c19ed14b | 6 | // signals |
jfields | 0:5699c19ed14b | 7 | PwmOut entry_valve(p26); |
jfields | 0:5699c19ed14b | 8 | PwmOut exit_valve(p25); |
jfields | 0:5699c19ed14b | 9 | AnalogIn detectFill(p24); |
jfields | 0:5699c19ed14b | 10 | |
jfields | 0:5699c19ed14b | 11 | // global vars |
jfields | 0:5699c19ed14b | 12 | Timer t; |
jfields | 0:5699c19ed14b | 13 | const int container_volume_mL = 10; |
jfields | 0:5699c19ed14b | 14 | const int send_interval = 10000; // 10 seconds |
jfields | 0:5699c19ed14b | 15 | const double ml_per_ms2ml_per_hr = (1/1000)*(1/60)*(1/60); |
jfields | 0:5699c19ed14b | 16 | int UO_mL = 0; |
jfields | 0:5699c19ed14b | 17 | double hourly_UO = 0; |
jfields | 0:5699c19ed14b | 18 | bool updateReading = false; |
jfields | 0:5699c19ed14b | 19 | |
jfields | 0:5699c19ed14b | 20 | // threads |
jfields | 0:5699c19ed14b | 21 | void sense_container(void const *args); |
jfields | 0:5699c19ed14b | 22 | Thread * sense_container_thread; |
jfields | 0:5699c19ed14b | 23 | void send_readings(void const *args); |
jfields | 0:5699c19ed14b | 24 | RtosTimer * send_readings_thread; |
jfields | 0:5699c19ed14b | 25 | |
jfields | 0:5699c19ed14b | 26 | int main() { |
jfields | 0:5699c19ed14b | 27 | |
jfields | 0:5699c19ed14b | 28 | // init threads |
jfields | 0:5699c19ed14b | 29 | sense_container_thread = new Thread(sense_container); |
jfields | 0:5699c19ed14b | 30 | send_readings_thread = new RtosTimer(send_readings, osTimerPeriodic, (void *)0); |
jfields | 0:5699c19ed14b | 31 | send_readings_thread.start(send_interval); |
jfields | 0:5699c19ed14b | 32 | |
jfields | 0:5699c19ed14b | 33 | // start timer |
jfields | 0:5699c19ed14b | 34 | t.start(); |
jfields | 0:5699c19ed14b | 35 | |
jfields | 0:5699c19ed14b | 36 | // record results |
jfields | 0:5699c19ed14b | 37 | while(1) { |
jfields | 0:5699c19ed14b | 38 | if (updateReading) { |
jfields | 0:5699c19ed14b | 39 | UO_mL += container_volume_mL; |
jfields | 0:5699c19ed14b | 40 | hourly_UO = (double) UO_mL/t.read_ms()*ml_per_ms2ml_per_hr; |
jfields | 0:5699c19ed14b | 41 | updateReading = false; |
jfields | 0:5699c19ed14b | 42 | } |
jfields | 0:5699c19ed14b | 43 | } |
jfields | 0:5699c19ed14b | 44 | } |
jfields | 0:5699c19ed14b | 45 | |
jfields | 0:5699c19ed14b | 46 | void sense_container(void const *args) { |
jfields | 0:5699c19ed14b | 47 | while (1) { |
jfields | 0:5699c19ed14b | 48 | // close exit and open entry |
jfields | 0:5699c19ed14b | 49 | if (!updateReadings) { |
jfields | 0:5699c19ed14b | 50 | // detect overflow code |
jfields | 0:5699c19ed14b | 51 | updateReadings = true; |
jfields | 0:5699c19ed14b | 52 | // OPEN EXIT CLOSE ENTRY |
jfields | 0:5699c19ed14b | 53 | } |
jfields | 0:5699c19ed14b | 54 | } |
jfields | 0:5699c19ed14b | 55 | } |
jfields | 0:5699c19ed14b | 56 | |
jfields | 0:5699c19ed14b | 57 | void send_readings(void const *args) { |
jfields | 0:5699c19ed14b | 58 | while (1) { |
jfields | 0:5699c19ed14b | 59 | Thread::signal_wait(RUN,osWaitForever); |
jfields | 0:5699c19ed14b | 60 | // send data via zigby code |
jfields | 0:5699c19ed14b | 61 | } |
jfields | 0:5699c19ed14b | 62 | } |