Toma de foto y descomprimir en HEX
Dependencies: JPEGCamera SDFileSystem mbed
Fork of SaibiCansat2014 by
main.cpp
- Committer:
- TakashiSasaki
- Date:
- 2014-07-18
- Revision:
- 11:3b13ec465f0f
- Parent:
- 9:3a2d25f4700b
- Child:
- 12:495d513bb022
File content as of revision 11:3b13ec465f0f:
#include "mbed.h" #include "SDFileSystem.h" #include "BMP085.h" #include "ADXL345_I2C.h" //#include "camera.h" #include "FastJpegCamera.h" SDFileSystem sd(p5, p6, p7, p8, "sd"); ADXL345_I2C accelerometer(p28, p27); BMP085 bmp085(p28, p27); Serial pc(USBTX, USBRX); Serial xbee(p13, p14); AnalogIn ain_CDS(p15); AnalogIn ain_Humedity(p16); AnalogIn ain_LM35DZ(p20); DigitalOut myled(LED1); int fileio() { mkdir("/sd/20014", 0777); FILE *fp = fopen("/sd/mydir/datalog.txt", "w"); if(fp == NULL) { error("Could not open file for write\n"); } fprintf(fp, "Hello fun SD Card World!"); fclose(fp); printf("Goodbye World!\n"); return(0); } int main() { pc.printf("main() started. pc.baud is 9600 at this time."); //pc.baud(9600); xbee.baud(115200); myled = 1; int readings[3] = {0, 0, 0}; pc.printf("Starting ADXL345 test...\n"); wait(.001); pc.printf("Device ID is: 0x%02x\n", accelerometer.getDeviceID()); wait(.001); // These are here to test whether any of the initialization fails. It will print the failure if (accelerometer.setPowerControl(0x00)){ pc.printf("didn't intitialize power control\n"); return 0; } //Full resolution, +/-16g, 4mg/LSB. wait(.001); if(accelerometer.setDataFormatControl(0x0B)){ pc.printf("didn't set data format\n"); return 0; } wait(.001); //3.2kHz data rate. if(accelerometer.setDataRate(ADXL345_3200HZ)){ pc.printf("didn't set data rate\n"); return 0; } wait(.001); FastJpegCamera fast_jpeg_camera(p9, p10, xbee); //Measurement mode. if(accelerometer.setPowerControl(MeasurementMode)) { pc.printf("didn't set the power control to measurement\n"); return 0; } myled = 0; int loop_count = 0; while (1) { FILE *fp = fopen("/sd/sensor.csv", "a"); loop_count += 1; //wait(1.5); //BOSH BMP085 Barometric pressure,temperature measurement accelerometer.getOutput(readings); //pc.printf("ADXL345 ------------------------\n"); char buf[100]; sprintf(buf, "X %+4.2f Y %+4.2f Z %+4.2f ", (float((int16_t)readings[0]+18)/256), (float((int16_t)readings[1]-4 )/256), (float((int16_t)readings[2]+22)/256)); pc.printf(buf); fwrite(buf, strlen(buf), 1, fp); xbee.printf(buf); bmp085.update(); //ADXL 345 Acceleration measurement //pc.printf("\nBOSH BMP085 --------------------\n"); sprintf(buf, "P %6.2f T %6.2f ", bmp085.get_pressure(), bmp085.get_temperature()); pc.printf(buf); fwrite(buf, strlen(buf), 1, fp); xbee.printf(buf); //CSDS Ambient light measurement P15 analog-in1 sprintf(buf, "L %f ",ain_CDS*100); pc.printf(buf); fwrite(buf, strlen(buf), 1, fp); xbee.printf(buf); //Humidity measurement P16 analog-in2 sprintf(buf, "H %f ",ain_Humedity*100); pc.printf(buf); fwrite(buf, strlen(buf), 1, fp); fwrite("\r\n", 2, 1, fp); fclose(fp); xbee.printf(buf); //LM35DZ Temperature measurement P20 analog-in6 //this sensor does not work for now. disabled. //pc.printf("Temperature :: %f\n",ain_LM35DZ*100); //take picture //main_camera(loop_count); fast_jpeg_camera.shoot(loop_count); } }