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 PowerControl
Fork of Projet_S5 by
analyzer.cpp@11:9c0786fc06b4, 2014-04-08 (annotated)
- Committer:
- joGenie
- Date:
- Tue Apr 08 13:46:22 2014 +0000
- Revision:
- 11:9c0786fc06b4
- Parent:
- 10:61b4d6c67dd7
- Child:
- 12:16390cea4420
new version;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
joGenie | 9:40197c24ce2c | 1 | /*! |
joGenie | 9:40197c24ce2c | 2 | * \file analyzer.cpp |
joGenie | 9:40197c24ce2c | 3 | * \brief Class that analyzes the mouvement in C and C++ |
joGenie | 9:40197c24ce2c | 4 | * \author Equipe P02 |
joGenie | 9:40197c24ce2c | 5 | * \version 0.1 |
joGenie | 9:40197c24ce2c | 6 | * \date 02/04/2014 |
joGenie | 9:40197c24ce2c | 7 | */ |
joGenie | 9:40197c24ce2c | 8 | |
joGenie | 3:17a4ceb30535 | 9 | #include "analyzer.h" |
joGenie | 8:9bf215a760f5 | 10 | |
joGenie | 3:17a4ceb30535 | 11 | Analyzer::Analyzer() |
joGenie | 8:9bf215a760f5 | 12 | { |
joGenie | 8:9bf215a760f5 | 13 | } |
joGenie | 8:9bf215a760f5 | 14 | |
joGenie | 3:17a4ceb30535 | 15 | Analyzer::~Analyzer() |
joGenie | 8:9bf215a760f5 | 16 | { |
joGenie | 8:9bf215a760f5 | 17 | allMouvement.clear(); |
joGenie | 8:9bf215a760f5 | 18 | } |
joGenie | 11:9c0786fc06b4 | 19 | |
joGenie | 11:9c0786fc06b4 | 20 | void Analyzer::initialize() |
joGenie | 11:9c0786fc06b4 | 21 | { |
joGenie | 11:9c0786fc06b4 | 22 | string pan("ACE"); |
joGenie | 11:9c0786fc06b4 | 23 | |
joGenie | 11:9c0786fc06b4 | 24 | DigitalOut reset(p8); |
joGenie | 11:9c0786fc06b4 | 25 | reset = 0; |
joGenie | 11:9c0786fc06b4 | 26 | wait(0.4); |
joGenie | 11:9c0786fc06b4 | 27 | reset = 1; |
joGenie | 11:9c0786fc06b4 | 28 | |
joGenie | 11:9c0786fc06b4 | 29 | /*trame = new Trame(p13, p14); |
joGenie | 11:9c0786fc06b4 | 30 | trame->sendATCommand("ID", pan.c_str(), pan.length());// Set le PANID selon le fichier de config |
joGenie | 11:9c0786fc06b4 | 31 | trame->sendATCommand("WR", 0, 0); // Écrit la valeur du PANID en mémoire |
joGenie | 11:9c0786fc06b4 | 32 | trame->sendATCommand("AC", 0, 0); // Applique les changements effectués*/ |
joGenie | 11:9c0786fc06b4 | 33 | |
joGenie | 11:9c0786fc06b4 | 34 | //wait(1); |
joGenie | 11:9c0786fc06b4 | 35 | |
joGenie | 11:9c0786fc06b4 | 36 | allMouvement[0x0002] = new Mouvement(0x0002, 0x0002, "Z vertical, vers le ciel"); |
joGenie | 11:9c0786fc06b4 | 37 | allMouvement[0x0003] = new Mouvement(0x0003, 0x0003, "Z vertical, vers le ciel INVERSE"); |
joGenie | 11:9c0786fc06b4 | 38 | allMouvement[0x0004] = new Mouvement(0x0004, 0x0004, "Z vertical, vers le sol"); |
joGenie | 11:9c0786fc06b4 | 39 | allMouvement[0x0005] = new Mouvement(0x0005, 0x0005, "Z vertical, vers le sol INVERSE"); |
joGenie | 11:9c0786fc06b4 | 40 | allMouvement[0x0006] = new Mouvement(0x0006, 0x0006, "Z horizontal"); |
joGenie | 11:9c0786fc06b4 | 41 | allMouvement[0x0007] = new Mouvement(0x0007, 0x0007, "Z horizontal INVERSE"); |
joGenie | 11:9c0786fc06b4 | 42 | |
joGenie | 11:9c0786fc06b4 | 43 | allMouvement[0x0020] = new Mouvement(0x0020, 0x0020, "X vertical, vers le ciel"); |
joGenie | 11:9c0786fc06b4 | 44 | allMouvement[0x0030] = new Mouvement(0x0030, 0x0030, "X vertical, vers le ciel INVERSE"); |
joGenie | 11:9c0786fc06b4 | 45 | allMouvement[0x0040] = new Mouvement(0x0040, 0x0040, "X vertical, vers le sol"); |
joGenie | 11:9c0786fc06b4 | 46 | allMouvement[0x0050] = new Mouvement(0x0050, 0x0050, "X vertical, vers le sol INVERSE"); |
joGenie | 11:9c0786fc06b4 | 47 | allMouvement[0x0060] = new Mouvement(0x0060, 0x0060, "X horizontal"); |
joGenie | 11:9c0786fc06b4 | 48 | allMouvement[0x0070] = new Mouvement(0x0070, 0x0070, "X horizontal INVERSE"); |
joGenie | 11:9c0786fc06b4 | 49 | |
joGenie | 11:9c0786fc06b4 | 50 | allMouvement[0x0200] = new Mouvement(0x0200, 0x0200, "Y vertical, vers le ciel"); |
joGenie | 11:9c0786fc06b4 | 51 | allMouvement[0x0300] = new Mouvement(0x0300, 0x0300, "Y vertical, vers le ciel INVERSE"); |
joGenie | 11:9c0786fc06b4 | 52 | allMouvement[0x0400] = new Mouvement(0x0400, 0x0400, "Y vertical, vers le sol"); |
joGenie | 11:9c0786fc06b4 | 53 | allMouvement[0x0500] = new Mouvement(0x0500, 0x0500, "Y vertical, vers le sol INVERSE"); |
joGenie | 11:9c0786fc06b4 | 54 | allMouvement[0x0600] = new Mouvement(0x0600, 0x0600, "Y horizontal"); |
joGenie | 11:9c0786fc06b4 | 55 | allMouvement[0x0700] = new Mouvement(0x0700, 0x0700, "Y horizontal INVERSE"); |
joGenie | 11:9c0786fc06b4 | 56 | } |
joGenie | 8:9bf215a760f5 | 57 | |
joGenie | 6:ef8bfca9e69b | 58 | void Analyzer::setMinMax(signed char* values) |
joGenie | 3:17a4ceb30535 | 59 | { |
joGenie | 3:17a4ceb30535 | 60 | x.setMinMax(values[0]); |
joGenie | 3:17a4ceb30535 | 61 | y.setMinMax(values[1]); |
joGenie | 3:17a4ceb30535 | 62 | z.setMinMax(values[2]); |
joGenie | 3:17a4ceb30535 | 63 | } |
joGenie | 8:9bf215a760f5 | 64 | |
joGenie | 5:6313ddd0dfdd | 65 | void Analyzer::checkMouvement() |
joGenie | 5:6313ddd0dfdd | 66 | { |
joGenie | 8:9bf215a760f5 | 67 | bool deplacement[3] = {0}; |
joGenie | 8:9bf215a760f5 | 68 | int code_mouvement = 0; |
joGenie | 8:9bf215a760f5 | 69 | |
joGenie | 9:40197c24ce2c | 70 | deplacement[0] = x.isMouvement(); |
joGenie | 9:40197c24ce2c | 71 | deplacement[1] = y.isMouvement(); |
joGenie | 9:40197c24ce2c | 72 | deplacement[2] = z.isMouvement(); |
joGenie | 8:9bf215a760f5 | 73 | |
joGenie | 8:9bf215a760f5 | 74 | Serial pc(USBTX, USBRX); |
joGenie | 8:9bf215a760f5 | 75 | |
joGenie | 8:9bf215a760f5 | 76 | // Mouvement en x |
joGenie | 8:9bf215a760f5 | 77 | if(deplacement[0]) |
joGenie | 8:9bf215a760f5 | 78 | { |
joGenie | 8:9bf215a760f5 | 79 | if(x.initial > SEUIL_DETECTION) |
joGenie | 8:9bf215a760f5 | 80 | { |
joGenie | 11:9c0786fc06b4 | 81 | code_mouvement |= 0x1 << 9; // 0010 |
joGenie | 8:9bf215a760f5 | 82 | } |
joGenie | 8:9bf215a760f5 | 83 | else if(x.initial < -SEUIL_DETECTION) |
joGenie | 8:9bf215a760f5 | 84 | { |
joGenie | 11:9c0786fc06b4 | 85 | code_mouvement |= 0x2 << 9; // 0100 |
joGenie | 8:9bf215a760f5 | 86 | } |
joGenie | 8:9bf215a760f5 | 87 | else |
joGenie | 8:9bf215a760f5 | 88 | { |
joGenie | 11:9c0786fc06b4 | 89 | code_mouvement |= 0x3 << 9; // 0110 |
joGenie | 8:9bf215a760f5 | 90 | } |
joGenie | 8:9bf215a760f5 | 91 | |
joGenie | 8:9bf215a760f5 | 92 | if(!x.sens) |
joGenie | 8:9bf215a760f5 | 93 | { |
joGenie | 11:9c0786fc06b4 | 94 | code_mouvement |= 0x1 << 8; // 0xx1 |
joGenie | 8:9bf215a760f5 | 95 | } |
joGenie | 8:9bf215a760f5 | 96 | } |
joGenie | 5:6313ddd0dfdd | 97 | |
joGenie | 8:9bf215a760f5 | 98 | // Mouvement en y |
joGenie | 8:9bf215a760f5 | 99 | if(deplacement[1]) |
joGenie | 8:9bf215a760f5 | 100 | { |
joGenie | 8:9bf215a760f5 | 101 | if(y.initial > SEUIL_DETECTION) |
joGenie | 8:9bf215a760f5 | 102 | { |
joGenie | 11:9c0786fc06b4 | 103 | code_mouvement |= 0x1 << 5; // 0xxx 0010 |
joGenie | 8:9bf215a760f5 | 104 | } |
joGenie | 8:9bf215a760f5 | 105 | else if(y.initial < -SEUIL_DETECTION) |
joGenie | 8:9bf215a760f5 | 106 | { |
joGenie | 11:9c0786fc06b4 | 107 | code_mouvement |= 0x2 << 5; // 0xxx 0100 |
joGenie | 8:9bf215a760f5 | 108 | } |
joGenie | 8:9bf215a760f5 | 109 | else |
joGenie | 8:9bf215a760f5 | 110 | { |
joGenie | 11:9c0786fc06b4 | 111 | code_mouvement |= 0x3 << 5; // 0xxx 0110 |
joGenie | 8:9bf215a760f5 | 112 | } |
joGenie | 8:9bf215a760f5 | 113 | |
joGenie | 8:9bf215a760f5 | 114 | if(!y.sens) |
joGenie | 8:9bf215a760f5 | 115 | { |
joGenie | 11:9c0786fc06b4 | 116 | code_mouvement |= 0x1 << 4; // 0xxx 0yy1 |
joGenie | 8:9bf215a760f5 | 117 | } |
joGenie | 8:9bf215a760f5 | 118 | } |
joGenie | 8:9bf215a760f5 | 119 | |
joGenie | 8:9bf215a760f5 | 120 | // Mouvement en z |
joGenie | 8:9bf215a760f5 | 121 | if(deplacement[2]) |
joGenie | 8:9bf215a760f5 | 122 | { |
joGenie | 8:9bf215a760f5 | 123 | if(z.initial > SEUIL_DETECTION) |
joGenie | 8:9bf215a760f5 | 124 | { |
joGenie | 11:9c0786fc06b4 | 125 | code_mouvement |= 1 << 1; // 0xxx 0yyy 0010 |
joGenie | 8:9bf215a760f5 | 126 | } |
joGenie | 8:9bf215a760f5 | 127 | else if(z.initial < -SEUIL_DETECTION) |
joGenie | 8:9bf215a760f5 | 128 | { |
joGenie | 11:9c0786fc06b4 | 129 | code_mouvement |= 2 << 1; // 0xxx 0yyy 0100 |
joGenie | 8:9bf215a760f5 | 130 | } |
joGenie | 8:9bf215a760f5 | 131 | else |
joGenie | 8:9bf215a760f5 | 132 | { |
joGenie | 11:9c0786fc06b4 | 133 | code_mouvement |= 3 << 1; // 0xxx 0yyy 0110 |
joGenie | 8:9bf215a760f5 | 134 | } |
joGenie | 8:9bf215a760f5 | 135 | |
joGenie | 8:9bf215a760f5 | 136 | if(!z.sens) |
joGenie | 8:9bf215a760f5 | 137 | { |
joGenie | 11:9c0786fc06b4 | 138 | code_mouvement |= 1 << 0; // 0xxx 0yyy 0zz1 |
joGenie | 8:9bf215a760f5 | 139 | } |
joGenie | 8:9bf215a760f5 | 140 | } |
joGenie | 8:9bf215a760f5 | 141 | |
joGenie | 11:9c0786fc06b4 | 142 | map<int,Mouvement*>::iterator it; |
joGenie | 11:9c0786fc06b4 | 143 | it = allMouvement.find(code_mouvement); |
joGenie | 11:9c0786fc06b4 | 144 | pc.printf("\n\r code mouvement: %x", code_mouvement); |
joGenie | 11:9c0786fc06b4 | 145 | |
joGenie | 8:9bf215a760f5 | 146 | pc.printf("\n\r mouvement: %s, %s, %s", deplacement[0] ? "vrai" : "faux", |
joGenie | 8:9bf215a760f5 | 147 | deplacement[1] ? "vrai" : "faux", |
joGenie | 8:9bf215a760f5 | 148 | deplacement[2] ? "vrai" : "faux"); |
joGenie | 11:9c0786fc06b4 | 149 | |
joGenie | 8:9bf215a760f5 | 150 | // pc.printf("\n\rInit: %i, min: %i, max: %i, sens: %s", x.initial, x.min, x.max, x.sens ? "acceleration":"deceleration"); |
joGenie | 8:9bf215a760f5 | 151 | // pc.printf("\n\rInit: %i, min: %i, max: %i, sens: %s", y.initial, y.min, y.max, y.sens ? "acceleration":"deceleration"); |
joGenie | 8:9bf215a760f5 | 152 | // pc.printf("\n\rInit: %i, min: %i, max: %i, sens: %s", z.initial, z.min, z.max, z.sens ? "acceleration":"deceleration"); |
joGenie | 7:89be89aeed5a | 153 | } |
joGenie | 8:9bf215a760f5 | 154 | |
joGenie | 7:89be89aeed5a | 155 | void Analyzer::setInitial(signed char* init) |
joGenie | 7:89be89aeed5a | 156 | { |
joGenie | 7:89be89aeed5a | 157 | x.setInitial(init[0]); |
joGenie | 7:89be89aeed5a | 158 | y.setInitial(init[1]); |
joGenie | 7:89be89aeed5a | 159 | z.setInitial(init[2]); |
joGenie | 5:6313ddd0dfdd | 160 | } |
joGenie | 8:9bf215a760f5 | 161 | |
joGenie | 3:17a4ceb30535 | 162 | extern "C" void *Analyzer_C_new() |
joGenie | 3:17a4ceb30535 | 163 | { |
joGenie | 3:17a4ceb30535 | 164 | return new Analyzer(); |
joGenie | 3:17a4ceb30535 | 165 | } |
joGenie | 8:9bf215a760f5 | 166 | |
joGenie | 3:17a4ceb30535 | 167 | extern "C" void Analyzer_C_delete(void *analyzer) |
joGenie | 3:17a4ceb30535 | 168 | { |
joGenie | 3:17a4ceb30535 | 169 | Analyzer *an = (Analyzer*)analyzer; |
joGenie | 3:17a4ceb30535 | 170 | delete an; |
joGenie | 3:17a4ceb30535 | 171 | } |
joGenie | 11:9c0786fc06b4 | 172 | |
joGenie | 11:9c0786fc06b4 | 173 | extern "C" void Analyzer_C_Initialize(void *analyzer) |
joGenie | 11:9c0786fc06b4 | 174 | { |
joGenie | 11:9c0786fc06b4 | 175 | Analyzer *an = (Analyzer*)analyzer; |
joGenie | 11:9c0786fc06b4 | 176 | an->initialize(); |
joGenie | 11:9c0786fc06b4 | 177 | } |
joGenie | 8:9bf215a760f5 | 178 | |
joGenie | 6:ef8bfca9e69b | 179 | extern "C" void Analyzer_C_setMinMax(signed char* values, void *analyzer) |
joGenie | 3:17a4ceb30535 | 180 | { |
joGenie | 3:17a4ceb30535 | 181 | Analyzer *an = (Analyzer*)analyzer; |
joGenie | 3:17a4ceb30535 | 182 | an->setMinMax(values); |
joGenie | 5:6313ddd0dfdd | 183 | } |
joGenie | 8:9bf215a760f5 | 184 | |
joGenie | 7:89be89aeed5a | 185 | extern "C" void Analyzer_C_setInitial(signed char* init, void *analyzer) |
joGenie | 7:89be89aeed5a | 186 | { |
joGenie | 7:89be89aeed5a | 187 | Analyzer *an = (Analyzer*)analyzer; |
joGenie | 7:89be89aeed5a | 188 | an->setInitial(init); |
joGenie | 7:89be89aeed5a | 189 | } |
joGenie | 8:9bf215a760f5 | 190 | |
joGenie | 5:6313ddd0dfdd | 191 | extern "C" void Analyzer_C_checkMouvement(void *analyzer) |
joGenie | 5:6313ddd0dfdd | 192 | { |
joGenie | 5:6313ddd0dfdd | 193 | Analyzer *an = (Analyzer*)analyzer; |
joGenie | 5:6313ddd0dfdd | 194 | an->checkMouvement(); |
joGenie | 8:9bf215a760f5 | 195 | } |