Felícito Manzano
/
DTK_Guaria2_ABInBev
Proyecto ABInBev para la tarjeta Guaria 1/2.
Input_Debounce/inputDebounce.cpp@19:5580a9a54ad5, 2022-07-07 (annotated)
- Committer:
- fmanzano_dtk
- Date:
- Thu Jul 07 16:17:25 2022 +0000
- Revision:
- 19:5580a9a54ad5
- Parent:
- 1:9e821e640117
Sincronizacion;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
fmanzano_dtk | 1:9e821e640117 | 1 | /** |
fmanzano_dtk | 1:9e821e640117 | 2 | * @file inputDebounce.cpp |
fmanzano_dtk | 1:9e821e640117 | 3 | * @author Felícito Manzano (felicito.manzano@detektor.com.sv) |
fmanzano_dtk | 1:9e821e640117 | 4 | * @brief |
fmanzano_dtk | 1:9e821e640117 | 5 | * @version 0.1 |
fmanzano_dtk | 1:9e821e640117 | 6 | * @date 2020-10-01 |
fmanzano_dtk | 1:9e821e640117 | 7 | * |
fmanzano_dtk | 1:9e821e640117 | 8 | * @copyright Copyright (c) 2020 |
fmanzano_dtk | 1:9e821e640117 | 9 | * |
fmanzano_dtk | 1:9e821e640117 | 10 | */ |
fmanzano_dtk | 1:9e821e640117 | 11 | |
fmanzano_dtk | 1:9e821e640117 | 12 | #include "mbed.h" |
fmanzano_dtk | 1:9e821e640117 | 13 | |
fmanzano_dtk | 1:9e821e640117 | 14 | |
fmanzano_dtk | 1:9e821e640117 | 15 | /** |
fmanzano_dtk | 1:9e821e640117 | 16 | * @brief |
fmanzano_dtk | 1:9e821e640117 | 17 | * |
fmanzano_dtk | 1:9e821e640117 | 18 | */ |
fmanzano_dtk | 1:9e821e640117 | 19 | const int SAMPLES_INPUT = 4; |
fmanzano_dtk | 1:9e821e640117 | 20 | const int SAMPLES_RAIN = 10; |
fmanzano_dtk | 1:9e821e640117 | 21 | |
fmanzano_dtk | 1:9e821e640117 | 22 | |
fmanzano_dtk | 1:9e821e640117 | 23 | |
fmanzano_dtk | 1:9e821e640117 | 24 | /** |
fmanzano_dtk | 1:9e821e640117 | 25 | * @brief |
fmanzano_dtk | 1:9e821e640117 | 26 | * |
fmanzano_dtk | 1:9e821e640117 | 27 | * @param Ign |
fmanzano_dtk | 1:9e821e640117 | 28 | * @param arrayIgn |
fmanzano_dtk | 1:9e821e640117 | 29 | * @param actIgn |
fmanzano_dtk | 1:9e821e640117 | 30 | * @param preIgn |
fmanzano_dtk | 1:9e821e640117 | 31 | * @param cont |
fmanzano_dtk | 1:9e821e640117 | 32 | * @return int |
fmanzano_dtk | 1:9e821e640117 | 33 | */ |
fmanzano_dtk | 1:9e821e640117 | 34 | int exeIgnition(DigitalIn *Ign, bool arrayIgn[], bool *actIgn, bool *preIgn, int *cont) { |
fmanzano_dtk | 1:9e821e640117 | 35 | bool are_equal = false; |
fmanzano_dtk | 1:9e821e640117 | 36 | int answer = 0; |
fmanzano_dtk | 1:9e821e640117 | 37 | int i; |
fmanzano_dtk | 1:9e821e640117 | 38 | |
fmanzano_dtk | 1:9e821e640117 | 39 | arrayIgn[*cont] = Ign -> read(); |
fmanzano_dtk | 1:9e821e640117 | 40 | *cont = *cont + 1; |
fmanzano_dtk | 1:9e821e640117 | 41 | |
fmanzano_dtk | 1:9e821e640117 | 42 | if (*cont == SAMPLES_INPUT) { |
fmanzano_dtk | 1:9e821e640117 | 43 | *cont = 0; |
fmanzano_dtk | 1:9e821e640117 | 44 | |
fmanzano_dtk | 1:9e821e640117 | 45 | //are_equal = (((arrayIgn[0] == arrayIgn[1]) == arrayIgn[2]) == arrayIgn[3]); |
fmanzano_dtk | 1:9e821e640117 | 46 | for (i = 0; i < SAMPLES_INPUT; i++) { |
fmanzano_dtk | 1:9e821e640117 | 47 | if (arrayIgn[i] != arrayIgn[0]) { |
fmanzano_dtk | 1:9e821e640117 | 48 | are_equal = false; |
fmanzano_dtk | 1:9e821e640117 | 49 | break; |
fmanzano_dtk | 1:9e821e640117 | 50 | } else { |
fmanzano_dtk | 1:9e821e640117 | 51 | are_equal = true; |
fmanzano_dtk | 1:9e821e640117 | 52 | } |
fmanzano_dtk | 1:9e821e640117 | 53 | } |
fmanzano_dtk | 1:9e821e640117 | 54 | if(are_equal) { |
fmanzano_dtk | 1:9e821e640117 | 55 | *actIgn = arrayIgn[0]; |
fmanzano_dtk | 1:9e821e640117 | 56 | if (*actIgn != *preIgn) { |
fmanzano_dtk | 1:9e821e640117 | 57 | *preIgn = *actIgn; |
fmanzano_dtk | 1:9e821e640117 | 58 | if (*actIgn) { |
fmanzano_dtk | 1:9e821e640117 | 59 | answer = 1; |
fmanzano_dtk | 1:9e821e640117 | 60 | } else { |
fmanzano_dtk | 1:9e821e640117 | 61 | answer = -1; |
fmanzano_dtk | 1:9e821e640117 | 62 | } |
fmanzano_dtk | 1:9e821e640117 | 63 | } else { |
fmanzano_dtk | 1:9e821e640117 | 64 | answer = 0; |
fmanzano_dtk | 1:9e821e640117 | 65 | } |
fmanzano_dtk | 1:9e821e640117 | 66 | } |
fmanzano_dtk | 1:9e821e640117 | 67 | } |
fmanzano_dtk | 1:9e821e640117 | 68 | return(answer); |
fmanzano_dtk | 1:9e821e640117 | 69 | } |
fmanzano_dtk | 1:9e821e640117 | 70 | |
fmanzano_dtk | 1:9e821e640117 | 71 | |
fmanzano_dtk | 1:9e821e640117 | 72 | |
fmanzano_dtk | 1:9e821e640117 | 73 | /** |
fmanzano_dtk | 1:9e821e640117 | 74 | * @brief |
fmanzano_dtk | 1:9e821e640117 | 75 | * |
fmanzano_dtk | 1:9e821e640117 | 76 | * @param my_Input |
fmanzano_dtk | 1:9e821e640117 | 77 | * @param my_arrayInput |
fmanzano_dtk | 1:9e821e640117 | 78 | * @param my_Input_read |
fmanzano_dtk | 1:9e821e640117 | 79 | * @param my_Input_previous |
fmanzano_dtk | 1:9e821e640117 | 80 | * @param cont |
fmanzano_dtk | 1:9e821e640117 | 81 | * @return int |
fmanzano_dtk | 1:9e821e640117 | 82 | */ |
fmanzano_dtk | 1:9e821e640117 | 83 | int exeDigInput(DigitalIn *my_Input, bool my_arrayInput[], bool *my_Input_read, bool *my_Input_previous, int *cont) { |
fmanzano_dtk | 1:9e821e640117 | 84 | bool are_equal = false; |
fmanzano_dtk | 1:9e821e640117 | 85 | int answer = 0; |
fmanzano_dtk | 1:9e821e640117 | 86 | int i; |
fmanzano_dtk | 1:9e821e640117 | 87 | |
fmanzano_dtk | 1:9e821e640117 | 88 | my_arrayInput[*cont] = my_Input -> read(); |
fmanzano_dtk | 1:9e821e640117 | 89 | *cont = *cont + 1; |
fmanzano_dtk | 1:9e821e640117 | 90 | |
fmanzano_dtk | 1:9e821e640117 | 91 | if (*cont == SAMPLES_INPUT) { |
fmanzano_dtk | 1:9e821e640117 | 92 | *cont = 0; |
fmanzano_dtk | 1:9e821e640117 | 93 | //are_equal = (((my_arrayInput[0] == my_arrayInput[1]) == my_arrayInput[2]) == my_arrayInput[3]); |
fmanzano_dtk | 1:9e821e640117 | 94 | for (i = 0; i < SAMPLES_INPUT; i++) { |
fmanzano_dtk | 1:9e821e640117 | 95 | if (my_arrayInput[i] != my_arrayInput[0]) { |
fmanzano_dtk | 1:9e821e640117 | 96 | are_equal = false; |
fmanzano_dtk | 1:9e821e640117 | 97 | break; |
fmanzano_dtk | 1:9e821e640117 | 98 | } else { |
fmanzano_dtk | 1:9e821e640117 | 99 | are_equal = true; |
fmanzano_dtk | 1:9e821e640117 | 100 | } |
fmanzano_dtk | 1:9e821e640117 | 101 | } |
fmanzano_dtk | 1:9e821e640117 | 102 | |
fmanzano_dtk | 1:9e821e640117 | 103 | |
fmanzano_dtk | 1:9e821e640117 | 104 | if (are_equal) { |
fmanzano_dtk | 1:9e821e640117 | 105 | *my_Input_read = my_arrayInput[0]; |
fmanzano_dtk | 1:9e821e640117 | 106 | if (*my_Input_read != *my_Input_previous) { |
fmanzano_dtk | 1:9e821e640117 | 107 | *my_Input_previous = *my_Input_read; |
fmanzano_dtk | 1:9e821e640117 | 108 | if (*my_Input_read) { |
fmanzano_dtk | 1:9e821e640117 | 109 | answer = 1; |
fmanzano_dtk | 1:9e821e640117 | 110 | } else { |
fmanzano_dtk | 1:9e821e640117 | 111 | answer = -1; |
fmanzano_dtk | 1:9e821e640117 | 112 | } |
fmanzano_dtk | 1:9e821e640117 | 113 | } |
fmanzano_dtk | 1:9e821e640117 | 114 | } else { |
fmanzano_dtk | 1:9e821e640117 | 115 | answer = 0; |
fmanzano_dtk | 1:9e821e640117 | 116 | } |
fmanzano_dtk | 1:9e821e640117 | 117 | } |
fmanzano_dtk | 1:9e821e640117 | 118 | return(answer); |
fmanzano_dtk | 1:9e821e640117 | 119 | } |
fmanzano_dtk | 1:9e821e640117 | 120 | |
fmanzano_dtk | 1:9e821e640117 | 121 | |
fmanzano_dtk | 1:9e821e640117 | 122 | /** |
fmanzano_dtk | 1:9e821e640117 | 123 | * @brief |
fmanzano_dtk | 1:9e821e640117 | 124 | * |
fmanzano_dtk | 1:9e821e640117 | 125 | * @param my_Input |
fmanzano_dtk | 1:9e821e640117 | 126 | * @param my_arrayInput |
fmanzano_dtk | 1:9e821e640117 | 127 | * @param my_Input_read |
fmanzano_dtk | 1:9e821e640117 | 128 | * @param my_Input_previous |
fmanzano_dtk | 1:9e821e640117 | 129 | * @param cont |
fmanzano_dtk | 1:9e821e640117 | 130 | * @return int |
fmanzano_dtk | 1:9e821e640117 | 131 | */ |
fmanzano_dtk | 1:9e821e640117 | 132 | int exeDigRain(DigitalIn *my_Input, bool my_arrayInput[], bool *my_Input_read, bool *my_Input_previous, int *cont) { |
fmanzano_dtk | 1:9e821e640117 | 133 | bool are_equal = false; |
fmanzano_dtk | 1:9e821e640117 | 134 | int answer = 0; |
fmanzano_dtk | 1:9e821e640117 | 135 | int i; |
fmanzano_dtk | 1:9e821e640117 | 136 | |
fmanzano_dtk | 1:9e821e640117 | 137 | my_arrayInput[*cont] = my_Input -> read(); |
fmanzano_dtk | 1:9e821e640117 | 138 | *cont = *cont + 1; |
fmanzano_dtk | 1:9e821e640117 | 139 | |
fmanzano_dtk | 1:9e821e640117 | 140 | if (*cont == SAMPLES_RAIN) { |
fmanzano_dtk | 1:9e821e640117 | 141 | *cont = 0; |
fmanzano_dtk | 1:9e821e640117 | 142 | //are_equal = (((my_arrayInput[0] == my_arrayInput[1]) == my_arrayInput[2]) == my_arrayInput[3]); |
fmanzano_dtk | 1:9e821e640117 | 143 | //are_equal = (((are_equal == my_arrayInput[4]) == my_arrayInput[5]) == my_arrayInput[6]); |
fmanzano_dtk | 1:9e821e640117 | 144 | //are_equal = (((are_equal == my_arrayInput[7]) == my_arrayInput[8]) == my_arrayInput[9]); |
fmanzano_dtk | 1:9e821e640117 | 145 | for (i = 0; i < SAMPLES_RAIN; i++) { |
fmanzano_dtk | 1:9e821e640117 | 146 | if (my_arrayInput[i] != my_arrayInput[0]) { |
fmanzano_dtk | 1:9e821e640117 | 147 | are_equal = false; |
fmanzano_dtk | 1:9e821e640117 | 148 | break; |
fmanzano_dtk | 1:9e821e640117 | 149 | } else { |
fmanzano_dtk | 1:9e821e640117 | 150 | are_equal = true; |
fmanzano_dtk | 1:9e821e640117 | 151 | } |
fmanzano_dtk | 1:9e821e640117 | 152 | } |
fmanzano_dtk | 1:9e821e640117 | 153 | |
fmanzano_dtk | 1:9e821e640117 | 154 | |
fmanzano_dtk | 1:9e821e640117 | 155 | if (are_equal) { |
fmanzano_dtk | 1:9e821e640117 | 156 | *my_Input_read = my_arrayInput[0]; |
fmanzano_dtk | 1:9e821e640117 | 157 | if (*my_Input_read != *my_Input_previous) { |
fmanzano_dtk | 1:9e821e640117 | 158 | *my_Input_previous = *my_Input_read; |
fmanzano_dtk | 1:9e821e640117 | 159 | if (*my_Input_read) { |
fmanzano_dtk | 1:9e821e640117 | 160 | answer = 1; |
fmanzano_dtk | 1:9e821e640117 | 161 | } else { |
fmanzano_dtk | 1:9e821e640117 | 162 | answer = -1; |
fmanzano_dtk | 1:9e821e640117 | 163 | } |
fmanzano_dtk | 1:9e821e640117 | 164 | } |
fmanzano_dtk | 1:9e821e640117 | 165 | } else { |
fmanzano_dtk | 1:9e821e640117 | 166 | answer = 0; |
fmanzano_dtk | 1:9e821e640117 | 167 | } |
fmanzano_dtk | 1:9e821e640117 | 168 | } |
fmanzano_dtk | 1:9e821e640117 | 169 | return(answer); |
fmanzano_dtk | 1:9e821e640117 | 170 | } |
fmanzano_dtk | 1:9e821e640117 | 171 |