![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
Xbee-Smart-Home-Inside RX Test
Dependencies: Si7021 mbed-rtos JPEGCamera mbed
Fork of Xbee-Smart-Home-Inside by
main.cpp@2:21031e885513, 2017-04-17 (annotated)
- Committer:
- pkoirala3
- Date:
- Mon Apr 17 18:36:03 2017 +0000
- Revision:
- 2:21031e885513
- Parent:
- 1:e9068d048f58
- Child:
- 3:415ccd1f7ae1
v1.2
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
pkoirala3 | 1:e9068d048f58 | 1 | #include "mbed.h" |
pkoirala3 | 1:e9068d048f58 | 2 | #include "rtos.h" |
pkoirala3 | 1:e9068d048f58 | 3 | #include "JPEGCamera.h" |
pkoirala3 | 0:5b1386641010 | 4 | |
pkoirala3 | 1:e9068d048f58 | 5 | AnalogIn ambient(p15); |
pkoirala3 | 1:e9068d048f58 | 6 | Mutex getMutex; |
pkoirala3 | 1:e9068d048f58 | 7 | Mutex putMutex; |
pkoirala3 | 1:e9068d048f58 | 8 | |
pkoirala3 | 1:e9068d048f58 | 9 | Thread t1; |
pkoirala3 | 1:e9068d048f58 | 10 | Thread t2; |
pkoirala3 | 0:5b1386641010 | 11 | |
pkoirala3 | 0:5b1386641010 | 12 | Serial xbee1(p9, p10); //Creates a variable for serial comunication through pin 9 and 10 |
pkoirala3 | 2:21031e885513 | 13 | JPEGCamera camera(p13, p14); // Camera serial TX, RX |
pkoirala3 | 0:5b1386641010 | 14 | |
pkoirala3 | 0:5b1386641010 | 15 | DigitalOut rst1(p8); //Digital reset for the XBee, 200ns for reset |
pkoirala3 | 0:5b1386641010 | 16 | |
pkoirala3 | 0:5b1386641010 | 17 | Serial pc(USBTX, USBRX);//Opens up serial communication through the USB port via the computer |
pkoirala3 | 0:5b1386641010 | 18 | |
pkoirala3 | 0:5b1386641010 | 19 | int main() { |
pkoirala3 | 0:5b1386641010 | 20 | rst1 = 0; //Set reset pin to 0 |
pkoirala3 | 0:5b1386641010 | 21 | wait_ms(1);//Wait at least one millisecond |
pkoirala3 | 0:5b1386641010 | 22 | rst1 = 1;//Set reset pin to 1 |
pkoirala3 | 0:5b1386641010 | 23 | wait_ms(1);//Wait another millisecond |
pkoirala3 | 1:e9068d048f58 | 24 | |
pkoirala3 | 2:21031e885513 | 25 | t1.start(callback(ambient_sensor())); |
pkoirala3 | 2:21031e885513 | 26 | t2.start(callback(cameraThread())); |
pkoirala3 | 1:e9068d048f58 | 27 | } |
pkoirala3 | 1:e9068d048f58 | 28 | |
pkoirala3 | 1:e9068d048f58 | 29 | void ambinet_sensor(){ |
pkoirala3 | 1:e9068d048f58 | 30 | float amb_val = ambient(); |
pkoirala3 | 1:e9068d048f58 | 31 | // Scale to proper unit |
pkoirala3 | 1:e9068d048f58 | 32 | putMutex.lock(); |
pkoirala3 | 1:e9068d048f58 | 33 | xbee.puts(amb_val); |
pkoirala3 | 1:e9068d048f58 | 34 | putMutex.unlock(); |
pkoirala3 | 1:e9068d048f58 | 35 | } |
pkoirala3 | 1:e9068d048f58 | 36 | |
pkoirala3 | 1:e9068d048f58 | 37 | void cameraThread(){ |
pkoirala3 | 1:e9068d048f58 | 38 | LocalFileSystem local("local"); //save images on mbed |
pkoirala3 | 1:e9068d048f58 | 39 | camera.setPictureSize(JPEGCamera::SIZE160x120); |
pkoirala3 | 1:e9068d048f58 | 40 | while(1){ |
pkoirala3 | 1:e9068d048f58 | 41 | if (camera.isReady()){ |
pkoirala3 | 1:e9068d048f58 | 42 | char filename[32]; |
pkoirala3 | 1:e9068d048f58 | 43 | sprintf(filename, "/local/pict.jpg"); |
pkoirala3 | 1:e9068d048f58 | 44 | printf("Picture: %s ", filename); |
pkoirala3 | 2:21031e885513 | 45 | if (camera.takePicture(filename)){ |
pkoirala3 | 2:21031e885513 | 46 | while (camera.isProcessing()){ |
pkoirala3 | 1:e9068d048f58 | 47 | camera.processPicture(); |
pkoirala3 | 1:e9068d048f58 | 48 | } |
pkoirala3 | 2:21031e885513 | 49 | putMutex.lock(); |
pkoirala3 | 2:21031e885513 | 50 | // xbee.putc(filename()); // Send image from xbee |
pkoirala3 | 2:21031e885513 | 51 | putMutex.unlock(); |
pkoirala3 | 1:e9068d048f58 | 52 | break; |
pkoirala3 | 1:e9068d048f58 | 53 | } |
pkoirala3 | 1:e9068d048f58 | 54 | } |
pkoirala3 | 1:e9068d048f58 | 55 | } |
pkoirala3 | 0:5b1386641010 | 56 | } |