![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
This is the vcdMaker demo project. See http://vcdmaker.org for details. vcdMaker is supposed to help engineers to debug their applications and systems. It transforms text log files into the VCD format which can be easily displayed as a waveform. Use the mbed serial logger at 115200 baud rate.
Dependencies: BSP_DISCO_L476VG COMPASS_DISCO_L476VG mbed vcdLogger vcdSignal
main.cpp@0:936379a8793e, 2016-03-05 (annotated)
- Committer:
- ketjow
- Date:
- Sat Mar 05 21:16:10 2016 +0000
- Revision:
- 0:936379a8793e
- Child:
- 1:297d1bcaa432
Initial
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ketjow | 0:936379a8793e | 1 | /*! |
ketjow | 0:936379a8793e | 2 | @file main.cpp |
ketjow | 0:936379a8793e | 3 | |
ketjow | 0:936379a8793e | 4 | The main vcdMaker demo file. |
ketjow | 0:936379a8793e | 5 | |
ketjow | 0:936379a8793e | 6 | @par Full Description |
ketjow | 0:936379a8793e | 7 | The vcdMaker demo. See http://vcdmaker.org for details. |
ketjow | 0:936379a8793e | 8 | |
ketjow | 0:936379a8793e | 9 | @if REVISION_HISTORY_INCLUDED |
ketjow | 0:936379a8793e | 10 | @par Edit History |
ketjow | 0:936379a8793e | 11 | @li [1] wojciech.rynczuk@wp.pl 04-MAR-2016 Initial file revision. |
ketjow | 0:936379a8793e | 12 | @endif |
ketjow | 0:936379a8793e | 13 | |
ketjow | 0:936379a8793e | 14 | @ingroup vcdMakerDemo |
ketjow | 0:936379a8793e | 15 | |
ketjow | 0:936379a8793e | 16 | The MIT License (MIT) |
ketjow | 0:936379a8793e | 17 | Copyright (c) 2016 Wojciech Rynczuk |
ketjow | 0:936379a8793e | 18 | |
ketjow | 0:936379a8793e | 19 | */ |
ketjow | 0:936379a8793e | 20 | |
ketjow | 0:936379a8793e | 21 | #include "mbed.h" |
ketjow | 0:936379a8793e | 22 | #include "serialLogger.hpp" |
ketjow | 0:936379a8793e | 23 | #include "magnetometer.hpp" |
ketjow | 0:936379a8793e | 24 | #include "accelerometer.hpp" |
ketjow | 0:936379a8793e | 25 | #include "button.hpp" |
ketjow | 0:936379a8793e | 26 | #include "COMPASS_DISCO_L476VG.h" |
ketjow | 0:936379a8793e | 27 | |
ketjow | 0:936379a8793e | 28 | #define NO_OF_LINES ((uint32_t)75) |
ketjow | 0:936379a8793e | 29 | #define NO_OF_CHARACTERS ((uint32_t)100) |
ketjow | 0:936379a8793e | 30 | |
ketjow | 0:936379a8793e | 31 | // Periodic timers |
ketjow | 0:936379a8793e | 32 | Ticker timer1; |
ketjow | 0:936379a8793e | 33 | Ticker timer2; |
ketjow | 0:936379a8793e | 34 | |
ketjow | 0:936379a8793e | 35 | // Time reference |
ketjow | 0:936379a8793e | 36 | uint32_t time_ref = 0; |
ketjow | 0:936379a8793e | 37 | |
ketjow | 0:936379a8793e | 38 | // Logger |
ketjow | 0:936379a8793e | 39 | SerialLogger slogger(NO_OF_LINES,NO_OF_CHARACTERS); |
ketjow | 0:936379a8793e | 40 | Logger* uniLogger; |
ketjow | 0:936379a8793e | 41 | |
ketjow | 0:936379a8793e | 42 | // Compass |
ketjow | 0:936379a8793e | 43 | COMPASS_DISCO_L476VG compass; |
ketjow | 0:936379a8793e | 44 | |
ketjow | 0:936379a8793e | 45 | // Signals |
ketjow | 0:936379a8793e | 46 | Magnetometer magnetometer("Disco.Sensors.Magnetometer.", compass, slogger); |
ketjow | 0:936379a8793e | 47 | Accelerometer accelerometer("Disco.Sensors.Accelerometer.", compass, slogger); |
ketjow | 0:936379a8793e | 48 | |
ketjow | 0:936379a8793e | 49 | // Buttons |
ketjow | 0:936379a8793e | 50 | Button button_center("Disco.Buttons.Center", slogger); |
ketjow | 0:936379a8793e | 51 | Button button_left("Disco.Buttons.Left", slogger); |
ketjow | 0:936379a8793e | 52 | Button button_up("Disco.Buttons.Up", slogger); |
ketjow | 0:936379a8793e | 53 | Button button_right("Disco.Buttons.Right", slogger); |
ketjow | 0:936379a8793e | 54 | Button button_down("Disco.Buttons.Down", slogger); |
ketjow | 0:936379a8793e | 55 | |
ketjow | 0:936379a8793e | 56 | // Joystick button |
ketjow | 0:936379a8793e | 57 | InterruptIn center(JOYSTICK_CENTER); |
ketjow | 0:936379a8793e | 58 | InterruptIn left(JOYSTICK_LEFT); |
ketjow | 0:936379a8793e | 59 | InterruptIn right(JOYSTICK_RIGHT); |
ketjow | 0:936379a8793e | 60 | InterruptIn up(JOYSTICK_UP); |
ketjow | 0:936379a8793e | 61 | InterruptIn down(JOYSTICK_DOWN); |
ketjow | 0:936379a8793e | 62 | |
ketjow | 0:936379a8793e | 63 | // Interrupt handlers |
ketjow | 0:936379a8793e | 64 | void center_released() { |
ketjow | 0:936379a8793e | 65 | button_center = 0; |
ketjow | 0:936379a8793e | 66 | button_center.PrintState(); |
ketjow | 0:936379a8793e | 67 | if ((uniLogger->GetTime() - time_ref) > 3000000) |
ketjow | 0:936379a8793e | 68 | { |
ketjow | 0:936379a8793e | 69 | if (uniLogger->IsRecording()) |
ketjow | 0:936379a8793e | 70 | { |
ketjow | 0:936379a8793e | 71 | uniLogger->StopRecording(); |
ketjow | 0:936379a8793e | 72 | } |
ketjow | 0:936379a8793e | 73 | else |
ketjow | 0:936379a8793e | 74 | { |
ketjow | 0:936379a8793e | 75 | uniLogger->StartRecording(); |
ketjow | 0:936379a8793e | 76 | } |
ketjow | 0:936379a8793e | 77 | } |
ketjow | 0:936379a8793e | 78 | } |
ketjow | 0:936379a8793e | 79 | |
ketjow | 0:936379a8793e | 80 | void center_pressed() { |
ketjow | 0:936379a8793e | 81 | button_center = 1; |
ketjow | 0:936379a8793e | 82 | button_center.PrintState(); |
ketjow | 0:936379a8793e | 83 | time_ref = uniLogger->GetTime(); |
ketjow | 0:936379a8793e | 84 | } |
ketjow | 0:936379a8793e | 85 | |
ketjow | 0:936379a8793e | 86 | void left_released() { |
ketjow | 0:936379a8793e | 87 | button_left = 0; |
ketjow | 0:936379a8793e | 88 | button_left.PrintState(); |
ketjow | 0:936379a8793e | 89 | } |
ketjow | 0:936379a8793e | 90 | |
ketjow | 0:936379a8793e | 91 | void left_pressed() { |
ketjow | 0:936379a8793e | 92 | button_left = 1; |
ketjow | 0:936379a8793e | 93 | button_left.PrintState(); |
ketjow | 0:936379a8793e | 94 | } |
ketjow | 0:936379a8793e | 95 | |
ketjow | 0:936379a8793e | 96 | void right_released() { |
ketjow | 0:936379a8793e | 97 | button_right = 0; |
ketjow | 0:936379a8793e | 98 | button_right.PrintState(); |
ketjow | 0:936379a8793e | 99 | } |
ketjow | 0:936379a8793e | 100 | |
ketjow | 0:936379a8793e | 101 | void right_pressed() { |
ketjow | 0:936379a8793e | 102 | button_right = 1; |
ketjow | 0:936379a8793e | 103 | button_right.PrintState(); |
ketjow | 0:936379a8793e | 104 | } |
ketjow | 0:936379a8793e | 105 | |
ketjow | 0:936379a8793e | 106 | void up_released() { |
ketjow | 0:936379a8793e | 107 | button_up = 0; |
ketjow | 0:936379a8793e | 108 | button_up.PrintState(); |
ketjow | 0:936379a8793e | 109 | } |
ketjow | 0:936379a8793e | 110 | |
ketjow | 0:936379a8793e | 111 | void up_pressed() { |
ketjow | 0:936379a8793e | 112 | button_up = 1; |
ketjow | 0:936379a8793e | 113 | button_up.PrintState(); |
ketjow | 0:936379a8793e | 114 | } |
ketjow | 0:936379a8793e | 115 | |
ketjow | 0:936379a8793e | 116 | void down_released() { |
ketjow | 0:936379a8793e | 117 | button_down = 0; |
ketjow | 0:936379a8793e | 118 | button_down.PrintState(); |
ketjow | 0:936379a8793e | 119 | } |
ketjow | 0:936379a8793e | 120 | |
ketjow | 0:936379a8793e | 121 | void down_pressed() { |
ketjow | 0:936379a8793e | 122 | button_down = 1; |
ketjow | 0:936379a8793e | 123 | button_down.PrintState(); |
ketjow | 0:936379a8793e | 124 | } |
ketjow | 0:936379a8793e | 125 | |
ketjow | 0:936379a8793e | 126 | void accelerometer_tick() |
ketjow | 0:936379a8793e | 127 | { |
ketjow | 0:936379a8793e | 128 | accelerometer.PrintState(); |
ketjow | 0:936379a8793e | 129 | } |
ketjow | 0:936379a8793e | 130 | |
ketjow | 0:936379a8793e | 131 | void magnetometer_tick() |
ketjow | 0:936379a8793e | 132 | { |
ketjow | 0:936379a8793e | 133 | magnetometer.PrintState(); |
ketjow | 0:936379a8793e | 134 | } |
ketjow | 0:936379a8793e | 135 | |
ketjow | 0:936379a8793e | 136 | int main() |
ketjow | 0:936379a8793e | 137 | { |
ketjow | 0:936379a8793e | 138 | uniLogger = &slogger; |
ketjow | 0:936379a8793e | 139 | |
ketjow | 0:936379a8793e | 140 | // Both rise and fall edges generate an interrupt |
ketjow | 0:936379a8793e | 141 | center.fall(¢er_released); |
ketjow | 0:936379a8793e | 142 | center.rise(¢er_pressed); |
ketjow | 0:936379a8793e | 143 | left.fall(&left_released); |
ketjow | 0:936379a8793e | 144 | left.rise(&left_pressed); |
ketjow | 0:936379a8793e | 145 | right.fall(&right_released); |
ketjow | 0:936379a8793e | 146 | right.rise(&right_pressed); |
ketjow | 0:936379a8793e | 147 | up.fall(&up_released); |
ketjow | 0:936379a8793e | 148 | up.rise(&up_pressed); |
ketjow | 0:936379a8793e | 149 | down.fall(&down_released); |
ketjow | 0:936379a8793e | 150 | down.rise(&down_pressed); |
ketjow | 0:936379a8793e | 151 | |
ketjow | 0:936379a8793e | 152 | // Add pull-down on these pins |
ketjow | 0:936379a8793e | 153 | // Warning: must be done AFTER edges setting |
ketjow | 0:936379a8793e | 154 | left.mode(PullDown); |
ketjow | 0:936379a8793e | 155 | right.mode(PullDown); |
ketjow | 0:936379a8793e | 156 | up.mode(PullDown); |
ketjow | 0:936379a8793e | 157 | down.mode(PullDown); |
ketjow | 0:936379a8793e | 158 | |
ketjow | 0:936379a8793e | 159 | timer1.attach_us(&magnetometer_tick, 50000); |
ketjow | 0:936379a8793e | 160 | timer2.attach_us(&accelerometer_tick, 40000); |
ketjow | 0:936379a8793e | 161 | |
ketjow | 0:936379a8793e | 162 | printf("Press joystick pressed for more than 3 seconds to start/stop logging.\n\r"); |
ketjow | 0:936379a8793e | 163 | |
ketjow | 0:936379a8793e | 164 | while(true) { |
ketjow | 0:936379a8793e | 165 | uniLogger->Print(); |
ketjow | 0:936379a8793e | 166 | }; |
ketjow | 0:936379a8793e | 167 | } |