Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed Rejestrator
Acquisition.cpp
00001 #include "Acquisition.h" 00002 00003 AnalogIn light(PTE22); 00004 AnalogIn Ain0(PTE20); 00005 AnalogOut Aout(PTE30); 00006 MAG3110 mag(SDA, SCL); 00007 MMA8451Q acc(SDA, SCL, MMA8451_I2C_ADDRESS); 00008 00009 long int global_time = 0; 00010 bool was_overflow = false; 00011 struct row_type last_measurement; 00012 00013 led_live aquisition_led(0.01, 0.5, 1.); 00014 00015 void RunningTimer(const void *param) 00016 { 00017 if (operating_mode != Exiting) 00018 { 00019 ++global_time; 00020 } 00021 } 00022 00023 void RunningAcquisition(const void *param) 00024 { 00025 osStatus put_result; 00026 if (operating_mode == Collecting) 00027 { 00028 struct row_type *data_buffer = data_memory.alloc(); 00029 00030 // mag.getValues(&data_buffer->mag_x, &data_buffer->mag_y, &data_buffer->mag_z); 00031 data_buffer->mag_x = (int)mag.readVal(MAG_OUT_X_MSB); 00032 // (int)((int16_t)data_buffer->mag_x); 00033 data_buffer->mag_y = (int)mag.readVal(MAG_OUT_Y_MSB); 00034 // (int)((int16_t)data_buffer->mag_y); 00035 data_buffer->mag_z = (int)mag.readVal(MAG_OUT_Z_MSB); 00036 // (int)((int16_t)data_buffer->mag_z); 00037 00038 data_buffer->giro_x = 0; 00039 data_buffer->giro_y = 0; 00040 data_buffer->giro_z = 0; 00041 00042 data_buffer->acc_x = acc.getAccX_int(); 00043 data_buffer->acc_y = acc.getAccY_int(); 00044 data_buffer->acc_z = acc.getAccZ_int(); 00045 00046 data_buffer->light = light.read(); 00047 data_buffer->Ain0 = Ain0.read(); 00048 00049 data_buffer->temperature = mag.getTemperature(); 00050 00051 data_buffer->tsi = global_tsi; 00052 00053 data_buffer->time = global_time; 00054 data_buffer->was_overflow = was_overflow; 00055 00056 put_result = data_queue.put(data_buffer, 10); 00057 last_measurement = *data_buffer; 00058 switch (put_result) 00059 { 00060 case osOK: 00061 case osEventMessage: 00062 was_overflow = false; 00063 break; 00064 case osEventTimeout: 00065 was_overflow = true; 00066 data_memory.free(data_buffer); 00067 break; 00068 } 00069 aquisition_led.live(led_green); 00070 } 00071 } 00072 00073 void ThreadAcquisition(const void *param) 00074 { 00075 led_green = 1.; 00076 00077 rtos::RtosTimer timer(RunningTimer, osTimerPeriodic, NULL); 00078 rtos::RtosTimer Acquisition(RunningAcquisition, osTimerPeriodic, NULL); 00079 /* 00080 // debug 00081 { 00082 extern Serial pc; 00083 pc.printf("\nMag regs: "); 00084 for (int i=0; i<20; ++i) 00085 { 00086 pc.printf("%02X ", mag.readReg(i)); 00087 } 00088 pc.printf(".\n"); 00089 for (int i=0; i<1000; ++i) 00090 { 00091 pc.printf("%d %d %d \n", mag.readVal(MAG_OUT_X_MSB), mag.readVal(MAG_OUT_Y_MSB), mag.readVal(MAG_OUT_Z_MSB)); 00092 } 00093 } 00094 */ 00095 timer.start(1); 00096 Acquisition.start(100); 00097 00098 while (operating_mode != Exiting) 00099 { 00100 rtos::Thread::wait(100); 00101 } 00102 00103 rtos::Thread::wait(200); // free the waif for buffer 00104 Acquisition.stop(); 00105 timer.stop(); 00106 00107 for (int i=0; i<10; ++i) 00108 { 00109 led_green = 0.9; 00110 rtos::Thread::wait(100); 00111 led_green = 0.1; 00112 rtos::Thread::wait(100); 00113 } 00114 led_green = 1.; 00115 } 00116
Generated on Sat Jul 30 2022 15:40:23 by
