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@0:fa31f8461c63, 2015-04-18 (annotated)
- Committer:
- Waldek
- Date:
- Sat Apr 18 17:01:57 2015 +0000
- Revision:
- 0:fa31f8461c63
- Child:
- 1:5ad44a4edff9
working version, stop
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| Waldek | 0:fa31f8461c63 | 1 | #include "Acquisition.h" |
| Waldek | 0:fa31f8461c63 | 2 | |
| Waldek | 0:fa31f8461c63 | 3 | AnalogIn light(PTE22); |
| Waldek | 0:fa31f8461c63 | 4 | AnalogIn Ain0(PTE20); |
| Waldek | 0:fa31f8461c63 | 5 | AnalogOut Aout(PTE30); |
| Waldek | 0:fa31f8461c63 | 6 | MAG3110 mag(SDA, SCL); |
| Waldek | 0:fa31f8461c63 | 7 | MMA8451Q acc(SDA, SCL, MMA8451_I2C_ADDRESS); |
| Waldek | 0:fa31f8461c63 | 8 | |
| Waldek | 0:fa31f8461c63 | 9 | long int global_time = 0; |
| Waldek | 0:fa31f8461c63 | 10 | bool was_overflow = false; |
| Waldek | 0:fa31f8461c63 | 11 | struct row_type last_measurement; |
| Waldek | 0:fa31f8461c63 | 12 | |
| Waldek | 0:fa31f8461c63 | 13 | led_live aquisition_led(0.01, 0.5, 1.); |
| Waldek | 0:fa31f8461c63 | 14 | |
| Waldek | 0:fa31f8461c63 | 15 | void RunningTimer(const void *param) |
| Waldek | 0:fa31f8461c63 | 16 | { |
| Waldek | 0:fa31f8461c63 | 17 | if (operating_mode != Exiting) |
| Waldek | 0:fa31f8461c63 | 18 | { |
| Waldek | 0:fa31f8461c63 | 19 | ++global_time; |
| Waldek | 0:fa31f8461c63 | 20 | } |
| Waldek | 0:fa31f8461c63 | 21 | } |
| Waldek | 0:fa31f8461c63 | 22 | |
| Waldek | 0:fa31f8461c63 | 23 | void RunningAcquisition(const void *param) |
| Waldek | 0:fa31f8461c63 | 24 | { |
| Waldek | 0:fa31f8461c63 | 25 | osStatus put_result; |
| Waldek | 0:fa31f8461c63 | 26 | if (operating_mode == Collecting) |
| Waldek | 0:fa31f8461c63 | 27 | { |
| Waldek | 0:fa31f8461c63 | 28 | struct row_type *data_buffer = data_memory.alloc(); |
| Waldek | 0:fa31f8461c63 | 29 | |
| Waldek | 0:fa31f8461c63 | 30 | mag.getValues(&data_buffer->mag_x, &data_buffer->mag_y, &data_buffer->mag_z); |
| Waldek | 0:fa31f8461c63 | 31 | data_buffer->mag_x = (int)((int16_t)data_buffer->mag_x); |
| Waldek | 0:fa31f8461c63 | 32 | data_buffer->mag_y = (int)((int16_t)data_buffer->mag_y); |
| Waldek | 0:fa31f8461c63 | 33 | data_buffer->mag_z = (int)((int16_t)data_buffer->mag_z); |
| Waldek | 0:fa31f8461c63 | 34 | |
| Waldek | 0:fa31f8461c63 | 35 | data_buffer->giro_x = 0; |
| Waldek | 0:fa31f8461c63 | 36 | data_buffer->giro_y = 0; |
| Waldek | 0:fa31f8461c63 | 37 | data_buffer->giro_z = 0; |
| Waldek | 0:fa31f8461c63 | 38 | |
| Waldek | 0:fa31f8461c63 | 39 | data_buffer->acc_x = acc.getAccX_int(); |
| Waldek | 0:fa31f8461c63 | 40 | data_buffer->acc_y = acc.getAccY_int(); |
| Waldek | 0:fa31f8461c63 | 41 | data_buffer->acc_z = acc.getAccZ_int(); |
| Waldek | 0:fa31f8461c63 | 42 | |
| Waldek | 0:fa31f8461c63 | 43 | data_buffer->light = light.read(); |
| Waldek | 0:fa31f8461c63 | 44 | data_buffer->Ain0 = Ain0.read(); |
| Waldek | 0:fa31f8461c63 | 45 | |
| Waldek | 0:fa31f8461c63 | 46 | data_buffer->temperature = mag.getTemperature(); |
| Waldek | 0:fa31f8461c63 | 47 | |
| Waldek | 0:fa31f8461c63 | 48 | data_buffer->tsi = global_tsi; |
| Waldek | 0:fa31f8461c63 | 49 | |
| Waldek | 0:fa31f8461c63 | 50 | data_buffer->time = global_time; |
| Waldek | 0:fa31f8461c63 | 51 | data_buffer->was_overflow = was_overflow; |
| Waldek | 0:fa31f8461c63 | 52 | |
| Waldek | 0:fa31f8461c63 | 53 | put_result = data_queue.put(data_buffer, 10); |
| Waldek | 0:fa31f8461c63 | 54 | last_measurement = *data_buffer; |
| Waldek | 0:fa31f8461c63 | 55 | switch (put_result) |
| Waldek | 0:fa31f8461c63 | 56 | { |
| Waldek | 0:fa31f8461c63 | 57 | case osOK: |
| Waldek | 0:fa31f8461c63 | 58 | case osEventMessage: |
| Waldek | 0:fa31f8461c63 | 59 | was_overflow = false; |
| Waldek | 0:fa31f8461c63 | 60 | break; |
| Waldek | 0:fa31f8461c63 | 61 | case osEventTimeout: |
| Waldek | 0:fa31f8461c63 | 62 | was_overflow = true; |
| Waldek | 0:fa31f8461c63 | 63 | data_memory.free(data_buffer); |
| Waldek | 0:fa31f8461c63 | 64 | break; |
| Waldek | 0:fa31f8461c63 | 65 | } |
| Waldek | 0:fa31f8461c63 | 66 | aquisition_led.live(led_green); |
| Waldek | 0:fa31f8461c63 | 67 | } |
| Waldek | 0:fa31f8461c63 | 68 | } |
| Waldek | 0:fa31f8461c63 | 69 | |
| Waldek | 0:fa31f8461c63 | 70 | void ThreadAcquisition(const void *param) |
| Waldek | 0:fa31f8461c63 | 71 | { |
| Waldek | 0:fa31f8461c63 | 72 | led_green = 1.; |
| Waldek | 0:fa31f8461c63 | 73 | |
| Waldek | 0:fa31f8461c63 | 74 | rtos::RtosTimer timer(RunningTimer, osTimerPeriodic, NULL); |
| Waldek | 0:fa31f8461c63 | 75 | rtos::RtosTimer Acquisition(RunningAcquisition, osTimerPeriodic, NULL); |
| Waldek | 0:fa31f8461c63 | 76 | |
| Waldek | 0:fa31f8461c63 | 77 | timer.start(1); |
| Waldek | 0:fa31f8461c63 | 78 | Acquisition.start(100); |
| Waldek | 0:fa31f8461c63 | 79 | |
| Waldek | 0:fa31f8461c63 | 80 | while (operating_mode != Exiting) |
| Waldek | 0:fa31f8461c63 | 81 | { |
| Waldek | 0:fa31f8461c63 | 82 | rtos::Thread::wait(100); |
| Waldek | 0:fa31f8461c63 | 83 | } |
| Waldek | 0:fa31f8461c63 | 84 | |
| Waldek | 0:fa31f8461c63 | 85 | rtos::Thread::wait(200); // free the waif for buffer |
| Waldek | 0:fa31f8461c63 | 86 | Acquisition.stop(); |
| Waldek | 0:fa31f8461c63 | 87 | timer.stop(); |
| Waldek | 0:fa31f8461c63 | 88 | |
| Waldek | 0:fa31f8461c63 | 89 | for (int i=0; i<10; ++i) |
| Waldek | 0:fa31f8461c63 | 90 | { |
| Waldek | 0:fa31f8461c63 | 91 | led_green = 0.9; |
| Waldek | 0:fa31f8461c63 | 92 | rtos::Thread::wait(100); |
| Waldek | 0:fa31f8461c63 | 93 | led_green = 0.1; |
| Waldek | 0:fa31f8461c63 | 94 | rtos::Thread::wait(100); |
| Waldek | 0:fa31f8461c63 | 95 | } |
| Waldek | 0:fa31f8461c63 | 96 | led_green = 1.; |
| Waldek | 0:fa31f8461c63 | 97 | } |