Xbee-Smart-Home-Inside RX Test

Dependencies:   Si7021 mbed-rtos JPEGCamera mbed

Fork of Xbee-Smart-Home-Inside by prana koirala

main.cpp

Committer:
pkoirala3
Date:
2017-04-17
Revision:
2:21031e885513
Parent:
1:e9068d048f58
Child:
3:415ccd1f7ae1

File content as of revision 2:21031e885513:

#include "mbed.h"
#include "rtos.h"
#include "JPEGCamera.h"

AnalogIn ambient(p15);
Mutex getMutex;
Mutex putMutex;

Thread t1;
Thread t2;

Serial xbee1(p9, p10); //Creates a variable for serial comunication through pin 9 and 10
JPEGCamera camera(p13, p14); // Camera serial TX, RX

DigitalOut rst1(p8); //Digital reset for the XBee, 200ns for reset

Serial pc(USBTX, USBRX);//Opens up serial communication through the USB port via the computer

int main() {
    rst1 = 0; //Set reset pin to 0
    wait_ms(1);//Wait at least one millisecond
    rst1 = 1;//Set reset pin to 1
    wait_ms(1);//Wait another millisecond
    
    t1.start(callback(ambient_sensor()));
    t2.start(callback(cameraThread()));
}

void ambinet_sensor(){
    float amb_val = ambient(); 
    // Scale to proper unit
    putMutex.lock();
    xbee.puts(amb_val);
    putMutex.unlock();
}

void cameraThread(){
    LocalFileSystem local("local"); //save images on mbed
    camera.setPictureSize(JPEGCamera::SIZE160x120);
    while(1){
        if (camera.isReady()){
            char filename[32];
            sprintf(filename, "/local/pict.jpg");
            printf("Picture: %s ", filename);
            if (camera.takePicture(filename)){
                while (camera.isProcessing()){
                    camera.processPicture();
                }
                putMutex.lock();
                // xbee.putc(filename()); // Send image from xbee
                putMutex.unlock();
                break;
            }
        }
    }
}