ese519 / Mbed 2 deprecated aUtO

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "rtos.h"
00003 
00004 Serial pc(USBTX,USBRX);
00005 
00006 // signals
00007 PwmOut entry_valve(p26);
00008 PwmOut exit_valve(p25);
00009 AnalogIn detectFill(p24);
00010 
00011 // global vars
00012 Timer t;
00013 const int container_volume_mL = 10;
00014 const int send_interval = 10000; // 10 seconds
00015 const double ml_per_ms2ml_per_hr = (1/1000)*(1/60)*(1/60);
00016 int UO_mL = 0;
00017 double hourly_UO = 0;
00018 bool updateReading = false;
00019 
00020 // threads
00021 void sense_container(void const *args);
00022 Thread * sense_container_thread;
00023 void send_readings(void const *args);
00024 RtosTimer * send_readings_thread;
00025 
00026 int main() {
00027     
00028     // init threads
00029     sense_container_thread = new Thread(sense_container);
00030     send_readings_thread = new RtosTimer(send_readings, osTimerPeriodic, (void *)0);
00031     send_readings_thread.start(send_interval);
00032     
00033     // start timer
00034     t.start();
00035     
00036     // record results
00037     while(1) {
00038         if (updateReading) {
00039             UO_mL += container_volume_mL;
00040             hourly_UO = (double) UO_mL/t.read_ms()*ml_per_ms2ml_per_hr;
00041             updateReading = false;
00042         }
00043     }
00044 }
00045 
00046 void sense_container(void const *args) {
00047     while (1) {
00048         // close exit and open entry
00049         if (!updateReadings) {
00050             // detect overflow code
00051             updateReadings = true;
00052             // OPEN EXIT CLOSE ENTRY
00053         }
00054     }
00055 }
00056 
00057 void send_readings(void const *args) {
00058     while (1) {
00059         Thread::signal_wait(RUN,osWaitForever);    
00060         // send data via zigby code
00061     }
00062 }