Radar_RTOS

Dependencies:   mbed

Dependents:   Radar_RTOS_Kart

Fork of Nucleo_radar_buz by Contest IOT GSE5

Committer:
Alex_Hochart
Date:
Wed Dec 02 16:09:22 2015 +0000
Revision:
2:97cbf2a5ec78
RTOS

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Alex_Hochart 2:97cbf2a5ec78 1 #ifndef BUZZER_H
Alex_Hochart 2:97cbf2a5ec78 2 #define BUZZER_H
Alex_Hochart 2:97cbf2a5ec78 3
Alex_Hochart 2:97cbf2a5ec78 4 #include "mbed.h"
Alex_Hochart 2:97cbf2a5ec78 5
Alex_Hochart 2:97cbf2a5ec78 6 DigitalOut buzz(PB_8);
Alex_Hochart 2:97cbf2a5ec78 7
Alex_Hochart 2:97cbf2a5ec78 8 class Buzzer{
Alex_Hochart 2:97cbf2a5ec78 9 public :
Alex_Hochart 2:97cbf2a5ec78 10 Buzzer(){
Alex_Hochart 2:97cbf2a5ec78 11 TsilenceMs=100;
Alex_Hochart 2:97cbf2a5ec78 12 etat = BipInit;
Alex_Hochart 2:97cbf2a5ec78 13 t.reset();
Alex_Hochart 2:97cbf2a5ec78 14 i=0;
Alex_Hochart 2:97cbf2a5ec78 15 }
Alex_Hochart 2:97cbf2a5ec78 16 int TsilenceMs;
Alex_Hochart 2:97cbf2a5ec78 17
Alex_Hochart 2:97cbf2a5ec78 18 typedef enum {BipInit, BipUp, BipDown, Silent} defetat;
Alex_Hochart 2:97cbf2a5ec78 19 defetat etat;
Alex_Hochart 2:97cbf2a5ec78 20 Timer t;
Alex_Hochart 2:97cbf2a5ec78 21 int i;
Alex_Hochart 2:97cbf2a5ec78 22
Alex_Hochart 2:97cbf2a5ec78 23 void changeMode(int value);
Alex_Hochart 2:97cbf2a5ec78 24 void run();
Alex_Hochart 2:97cbf2a5ec78 25 };
Alex_Hochart 2:97cbf2a5ec78 26
Alex_Hochart 2:97cbf2a5ec78 27 /*
Alex_Hochart 2:97cbf2a5ec78 28 Buzzer::Buzzer(){
Alex_Hochart 2:97cbf2a5ec78 29 TsilenceMs=100;
Alex_Hochart 2:97cbf2a5ec78 30 etat = BipInit;
Alex_Hochart 2:97cbf2a5ec78 31 t.reset();
Alex_Hochart 2:97cbf2a5ec78 32 i=0;
Alex_Hochart 2:97cbf2a5ec78 33 }
Alex_Hochart 2:97cbf2a5ec78 34 */
Alex_Hochart 2:97cbf2a5ec78 35
Alex_Hochart 2:97cbf2a5ec78 36 /*
Alex_Hochart 2:97cbf2a5ec78 37 * Initialisation des différents modes de fonctionnement :
Alex_Hochart 2:97cbf2a5ec78 38 *
Alex_Hochart 2:97cbf2a5ec78 39 * 0 < d < 25 --> 0 : 5 b/s
Alex_Hochart 2:97cbf2a5ec78 40 * 25 < d < 50 --> 1 : 4 b/s
Alex_Hochart 2:97cbf2a5ec78 41 * 50 < d < 100 --> 2 : 3 b/s
Alex_Hochart 2:97cbf2a5ec78 42 * 100 < d < 150 --> 3 : 2 b/s
Alex_Hochart 2:97cbf2a5ec78 43 * 150 < d < 200 --> 4 : 1 b/s
Alex_Hochart 2:97cbf2a5ec78 44 * 200 < d --> 5 : 0 b/s
Alex_Hochart 2:97cbf2a5ec78 45
Alex_Hochart 2:97cbf2a5ec78 46 fonction bip : (400µs+400µs)*50 = 40ms
Alex_Hochart 2:97cbf2a5ec78 47 -> timer sur interruption en fonction du temps à attendre avant le prochain bip
Alex_Hochart 2:97cbf2a5ec78 48 0 --> 5 b/s --> TsilenceMs 0,16s
Alex_Hochart 2:97cbf2a5ec78 49 1 --> 4 b/s --> TsilenceMs 0,21s
Alex_Hochart 2:97cbf2a5ec78 50 2 --> 3 b/s --> TsilenceMs 0,29s
Alex_Hochart 2:97cbf2a5ec78 51 3 --> 2 b/s --> TsilenceMs 0,46s
Alex_Hochart 2:97cbf2a5ec78 52 4 --> 1 b/s --> TsilenceMs 0,96s
Alex_Hochart 2:97cbf2a5ec78 53 5 --> TsilenceMs 1s
Alex_Hochart 2:97cbf2a5ec78 54
Alex_Hochart 2:97cbf2a5ec78 55 */
Alex_Hochart 2:97cbf2a5ec78 56
Alex_Hochart 2:97cbf2a5ec78 57
Alex_Hochart 2:97cbf2a5ec78 58 //Modifie la valeur du temps de silence entre 2 bips en fonction de la distance
Alex_Hochart 2:97cbf2a5ec78 59 void Buzzer::changeMode(int value){
Alex_Hochart 2:97cbf2a5ec78 60 if(value<=25){ //0
Alex_Hochart 2:97cbf2a5ec78 61 TsilenceMs=160;
Alex_Hochart 2:97cbf2a5ec78 62 }else if(value>25 && value<=50){ //1
Alex_Hochart 2:97cbf2a5ec78 63 TsilenceMs=210;
Alex_Hochart 2:97cbf2a5ec78 64 }else if(value>50 && value<=100){ //2
Alex_Hochart 2:97cbf2a5ec78 65 TsilenceMs=290;
Alex_Hochart 2:97cbf2a5ec78 66 }else if(value>100 && value<=150){ //3
Alex_Hochart 2:97cbf2a5ec78 67 TsilenceMs=460;
Alex_Hochart 2:97cbf2a5ec78 68 }else if(value>150 && value<=200){ //4
Alex_Hochart 2:97cbf2a5ec78 69 TsilenceMs=960;
Alex_Hochart 2:97cbf2a5ec78 70 }else{ //5
Alex_Hochart 2:97cbf2a5ec78 71 TsilenceMs=1000000000;
Alex_Hochart 2:97cbf2a5ec78 72 }
Alex_Hochart 2:97cbf2a5ec78 73 }
Alex_Hochart 2:97cbf2a5ec78 74
Alex_Hochart 2:97cbf2a5ec78 75 /*
Alex_Hochart 2:97cbf2a5ec78 76 Si la valeur sort de son intervalle de fonctionnement,
Alex_Hochart 2:97cbf2a5ec78 77 on modifie le mode de fonctionnement courant.
Alex_Hochart 2:97cbf2a5ec78 78
Alex_Hochart 2:97cbf2a5ec78 79 fonction bip : (400µs+400µs)*50 = 40ms
Alex_Hochart 2:97cbf2a5ec78 80 -> timer sur interruption en fonction du temps à attendre avant le prochain bip
Alex_Hochart 2:97cbf2a5ec78 81 0 --> 5 b/s --> silence 0,16s
Alex_Hochart 2:97cbf2a5ec78 82 1 --> 4 b/s --> silence 0,21s
Alex_Hochart 2:97cbf2a5ec78 83 2 --> 3 b/s --> silence 0,29s
Alex_Hochart 2:97cbf2a5ec78 84 3 --> 2 b/s --> silence 0,46s
Alex_Hochart 2:97cbf2a5ec78 85 4 --> 1 b/s --> silence 0,96s
Alex_Hochart 2:97cbf2a5ec78 86 5 --> silence 1s
Alex_Hochart 2:97cbf2a5ec78 87
Alex_Hochart 2:97cbf2a5ec78 88 Etat : BipInit
Alex_Hochart 2:97cbf2a5ec78 89 Timer t Start
Alex_Hochart 2:97cbf2a5ec78 90 Bip=0
Alex_Hochart 2:97cbf2a5ec78 91 i=0
Alex_Hochart 2:97cbf2a5ec78 92 Etat = BipUp
Alex_Hochart 2:97cbf2a5ec78 93 Etat : BipUp
Alex_Hochart 2:97cbf2a5ec78 94 si (t>=400µs && i<50)
Alex_Hochart 2:97cbf2a5ec78 95 bipCarreUp
Alex_Hochart 2:97cbf2a5ec78 96 i++
Alex_Hochart 2:97cbf2a5ec78 97 Etat = BipDown
Alex_Hochart 2:97cbf2a5ec78 98 t Restart
Alex_Hochart 2:97cbf2a5ec78 99 si (i>=50) Etat = Silence;
Alex_Hochart 2:97cbf2a5ec78 100 t Restart
Alex_Hochart 2:97cbf2a5ec78 101 Etat : BipDown
Alex_Hochart 2:97cbf2a5ec78 102 si (t>=400µs && i<50)
Alex_Hochart 2:97cbf2a5ec78 103 bipCarreUp
Alex_Hochart 2:97cbf2a5ec78 104 i++
Alex_Hochart 2:97cbf2a5ec78 105 Etat = BipUp
Alex_Hochart 2:97cbf2a5ec78 106 t Restart
Alex_Hochart 2:97cbf2a5ec78 107 si (i>=50) Etat = Silence;
Alex_Hochart 2:97cbf2a5ec78 108 t Restart
Alex_Hochart 2:97cbf2a5ec78 109 Etat : Silence
Alex_Hochart 2:97cbf2a5ec78 110 si (t>=Tsilence)
Alex_Hochart 2:97cbf2a5ec78 111 Etat=BipInit
Alex_Hochart 2:97cbf2a5ec78 112
Alex_Hochart 2:97cbf2a5ec78 113 */
Alex_Hochart 2:97cbf2a5ec78 114
Alex_Hochart 2:97cbf2a5ec78 115 void Buzzer::run(){ // paramètre : t (Timer), i, etat
Alex_Hochart 2:97cbf2a5ec78 116 switch(etat){
Alex_Hochart 2:97cbf2a5ec78 117
Alex_Hochart 2:97cbf2a5ec78 118 case BipInit :
Alex_Hochart 2:97cbf2a5ec78 119 buzz=0;
Alex_Hochart 2:97cbf2a5ec78 120 i=0;
Alex_Hochart 2:97cbf2a5ec78 121 etat = BipUp;
Alex_Hochart 2:97cbf2a5ec78 122 t.start();
Alex_Hochart 2:97cbf2a5ec78 123 break;
Alex_Hochart 2:97cbf2a5ec78 124
Alex_Hochart 2:97cbf2a5ec78 125 case BipUp :
Alex_Hochart 2:97cbf2a5ec78 126 if(t.read_us()>=400 && i<50){
Alex_Hochart 2:97cbf2a5ec78 127 buzz=1;
Alex_Hochart 2:97cbf2a5ec78 128 i++;
Alex_Hochart 2:97cbf2a5ec78 129 etat = BipDown;
Alex_Hochart 2:97cbf2a5ec78 130 t.reset();
Alex_Hochart 2:97cbf2a5ec78 131 t.start();
Alex_Hochart 2:97cbf2a5ec78 132 }
Alex_Hochart 2:97cbf2a5ec78 133 if(i>=50){
Alex_Hochart 2:97cbf2a5ec78 134 etat = Silent;
Alex_Hochart 2:97cbf2a5ec78 135 t.reset();
Alex_Hochart 2:97cbf2a5ec78 136 t.start();
Alex_Hochart 2:97cbf2a5ec78 137 }
Alex_Hochart 2:97cbf2a5ec78 138 break;
Alex_Hochart 2:97cbf2a5ec78 139
Alex_Hochart 2:97cbf2a5ec78 140 case BipDown :
Alex_Hochart 2:97cbf2a5ec78 141 if(t.read_us()>=400 && i<50){
Alex_Hochart 2:97cbf2a5ec78 142 buzz=0;
Alex_Hochart 2:97cbf2a5ec78 143 i++;
Alex_Hochart 2:97cbf2a5ec78 144 etat = BipUp;
Alex_Hochart 2:97cbf2a5ec78 145 t.reset();
Alex_Hochart 2:97cbf2a5ec78 146 t.start();
Alex_Hochart 2:97cbf2a5ec78 147 }
Alex_Hochart 2:97cbf2a5ec78 148 if(i>=50){
Alex_Hochart 2:97cbf2a5ec78 149 etat = Silent;
Alex_Hochart 2:97cbf2a5ec78 150 t.reset();
Alex_Hochart 2:97cbf2a5ec78 151 t.start();
Alex_Hochart 2:97cbf2a5ec78 152 }
Alex_Hochart 2:97cbf2a5ec78 153 break;
Alex_Hochart 2:97cbf2a5ec78 154
Alex_Hochart 2:97cbf2a5ec78 155 case Silent :
Alex_Hochart 2:97cbf2a5ec78 156 if(t.read_ms()>=TsilenceMs){
Alex_Hochart 2:97cbf2a5ec78 157 etat=BipInit;
Alex_Hochart 2:97cbf2a5ec78 158 }
Alex_Hochart 2:97cbf2a5ec78 159 break;
Alex_Hochart 2:97cbf2a5ec78 160
Alex_Hochart 2:97cbf2a5ec78 161 default :
Alex_Hochart 2:97cbf2a5ec78 162 etat = BipInit;
Alex_Hochart 2:97cbf2a5ec78 163 break;
Alex_Hochart 2:97cbf2a5ec78 164 }
Alex_Hochart 2:97cbf2a5ec78 165 }
Alex_Hochart 2:97cbf2a5ec78 166
Alex_Hochart 2:97cbf2a5ec78 167
Alex_Hochart 2:97cbf2a5ec78 168 #endif