The last version programs
Dependencies: mbed TrapezoidControl Pulse QEI
Input/Switch/Switch.cpp@22:7d93f79a3686, 2019-09-17 (annotated)
- Committer:
- M_souta
- Date:
- Tue Sep 17 04:40:17 2019 +0000
- Revision:
- 22:7d93f79a3686
- Parent:
- 19:96a462583af9
kkk
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
t_yamamoto | 0:669ef71cba68 | 1 | #include "Switch.h" |
t_yamamoto | 0:669ef71cba68 | 2 | |
t_yamamoto | 0:669ef71cba68 | 3 | #include <stdint.h> |
t_yamamoto | 0:669ef71cba68 | 4 | #include "mbed.h" |
t_yamamoto | 0:669ef71cba68 | 5 | |
t_yamamoto | 0:669ef71cba68 | 6 | namespace SWITCH { |
t_yamamoto | 0:669ef71cba68 | 7 | DigitalIn dipSw[] = { |
t_yamamoto | 0:669ef71cba68 | 8 | DigitalIn(DIP0_PIN), |
t_yamamoto | 0:669ef71cba68 | 9 | DigitalIn(DIP1_PIN), |
t_yamamoto | 0:669ef71cba68 | 10 | DigitalIn(DIP2_PIN), |
t_yamamoto | 0:669ef71cba68 | 11 | DigitalIn(DIP3_PIN), |
t_yamamoto | 0:669ef71cba68 | 12 | }; |
t_yamamoto | 0:669ef71cba68 | 13 | |
t_yamamoto | 0:669ef71cba68 | 14 | DigitalIn limitSw(LS_PIN); |
7ka884 | 4:ba9df71868df | 15 | |
t_yamamoto | 0:669ef71cba68 | 16 | DigitalOut selectPin[] = { |
t_yamamoto | 0:669ef71cba68 | 17 | DigitalOut(SELECT0_PIN), |
t_yamamoto | 0:669ef71cba68 | 18 | DigitalOut(SELECT1_PIN), |
t_yamamoto | 0:669ef71cba68 | 19 | DigitalOut(SELECT2_PIN), |
t_yamamoto | 0:669ef71cba68 | 20 | DigitalOut(SELECT3_PIN), |
t_yamamoto | 0:669ef71cba68 | 21 | }; |
M_souta | 22:7d93f79a3686 | 22 | |
M_souta | 22:7d93f79a3686 | 23 | DigitalIn limitSw_N[] = { |
M_souta | 22:7d93f79a3686 | 24 | DigitalIn(LS_16), |
M_souta | 22:7d93f79a3686 | 25 | DigitalIn(LS_17), |
M_souta | 22:7d93f79a3686 | 26 | DigitalIn(LS_18), |
M_souta | 22:7d93f79a3686 | 27 | DigitalIn(LS_19), |
M_souta | 22:7d93f79a3686 | 28 | DigitalIn(LS_20), |
M_souta | 22:7d93f79a3686 | 29 | }; |
t_yamamoto | 0:669ef71cba68 | 30 | |
t_yamamoto | 0:669ef71cba68 | 31 | void DipSw::Initialize() { |
t_yamamoto | 0:669ef71cba68 | 32 | for(uint8_t i=0; i < sizeof(dipSw)/sizeof(dipSw[0]); i++) { |
t_yamamoto | 0:669ef71cba68 | 33 | dipSw[i].mode(PullUp); |
t_yamamoto | 0:669ef71cba68 | 34 | } |
t_yamamoto | 0:669ef71cba68 | 35 | } |
t_yamamoto | 0:669ef71cba68 | 36 | |
t_yamamoto | 0:669ef71cba68 | 37 | uint8_t DipSw::GetStatus() { |
t_yamamoto | 0:669ef71cba68 | 38 | if(DIP0 == SW_ON) return 0; |
t_yamamoto | 0:669ef71cba68 | 39 | else if(DIP1 == SW_ON) return 1; |
t_yamamoto | 0:669ef71cba68 | 40 | else if(DIP2 == SW_ON) return 2; |
t_yamamoto | 0:669ef71cba68 | 41 | else if(DIP3 == SW_ON) return 3; |
t_yamamoto | 0:669ef71cba68 | 42 | |
t_yamamoto | 0:669ef71cba68 | 43 | return 0; |
t_yamamoto | 0:669ef71cba68 | 44 | } |
t_yamamoto | 0:669ef71cba68 | 45 | |
t_yamamoto | 0:669ef71cba68 | 46 | void LimitSw::Initialize() { |
t_yamamoto | 0:669ef71cba68 | 47 | for(uint8_t i=0; i<4; i++) selectPin[i] = 0; |
t_yamamoto | 0:669ef71cba68 | 48 | limitSw.mode(PullUp); |
t_yamamoto | 0:669ef71cba68 | 49 | } |
t_yamamoto | 0:669ef71cba68 | 50 | |
t_yamamoto | 0:669ef71cba68 | 51 | bool LimitSw::IsPressed(int index) { |
t_yamamoto | 0:669ef71cba68 | 52 | |
t_yamamoto | 0:669ef71cba68 | 53 | MP_Channel ch; |
M_souta | 22:7d93f79a3686 | 54 | bool button; |
7ka884 | 1:b1219d8ca117 | 55 | |
7ka884 | 1:b1219d8ca117 | 56 | switch(index){ |
7ka884 | 1:b1219d8ca117 | 57 | case 0: |
kishibekairohan | 16:3f2c2d89372b | 58 | ch.all = 9; |
7ka884 | 1:b1219d8ca117 | 59 | break; |
M_souta | 22:7d93f79a3686 | 60 | case 1: |
kishibekairohan | 16:3f2c2d89372b | 61 | ch.all = 11; |
7ka884 | 1:b1219d8ca117 | 62 | break; |
M_souta | 22:7d93f79a3686 | 63 | case 2: |
M_souta | 22:7d93f79a3686 | 64 | ch.all = 13; |
M_souta | 22:7d93f79a3686 | 65 | break; |
M_souta | 22:7d93f79a3686 | 66 | case 3: |
M_souta | 22:7d93f79a3686 | 67 | ch.all = 15; |
M_souta | 22:7d93f79a3686 | 68 | break; |
7ka884 | 1:b1219d8ca117 | 69 | case 4: |
M_souta | 22:7d93f79a3686 | 70 | ch.all = 8; |
kishibekairohan | 16:3f2c2d89372b | 71 | break; |
kishibekairohan | 16:3f2c2d89372b | 72 | case 5: |
M_souta | 22:7d93f79a3686 | 73 | ch.all = 10; |
kishibekairohan | 16:3f2c2d89372b | 74 | break; |
kishibekairohan | 16:3f2c2d89372b | 75 | case 6: |
M_souta | 22:7d93f79a3686 | 76 | ch.all = 12; |
kishibekairohan | 16:3f2c2d89372b | 77 | break; |
kishibekairohan | 16:3f2c2d89372b | 78 | case 7: |
M_souta | 22:7d93f79a3686 | 79 | ch.all = 14; |
kishibekairohan | 16:3f2c2d89372b | 80 | break; |
kishibekairohan | 16:3f2c2d89372b | 81 | case 8: |
kishibekairohan | 16:3f2c2d89372b | 82 | ch.all = 7; |
kishibekairohan | 16:3f2c2d89372b | 83 | break; |
kishibekairohan | 16:3f2c2d89372b | 84 | case 9: |
M_souta | 22:7d93f79a3686 | 85 | ch.all = 4; |
7ka884 | 1:b1219d8ca117 | 86 | break; |
kishibekairohan | 16:3f2c2d89372b | 87 | case 10: |
M_souta | 22:7d93f79a3686 | 88 | ch.all = 2; |
7ka884 | 1:b1219d8ca117 | 89 | break; |
kishibekairohan | 16:3f2c2d89372b | 90 | case 11: |
M_souta | 22:7d93f79a3686 | 91 | ch.all = 0; |
7ka884 | 1:b1219d8ca117 | 92 | break; |
kishibekairohan | 16:3f2c2d89372b | 93 | case 12: |
M_souta | 22:7d93f79a3686 | 94 | ch.all = 6; |
7ka884 | 1:b1219d8ca117 | 95 | break; |
kishibekairohan | 16:3f2c2d89372b | 96 | case 13: |
M_souta | 22:7d93f79a3686 | 97 | ch.all = 5; |
7ka884 | 1:b1219d8ca117 | 98 | break; |
kishibekairohan | 16:3f2c2d89372b | 99 | case 14: |
M_souta | 22:7d93f79a3686 | 100 | ch.all = 3; |
kishibekairohan | 16:3f2c2d89372b | 101 | break; |
kishibekairohan | 16:3f2c2d89372b | 102 | case 15: |
M_souta | 22:7d93f79a3686 | 103 | ch.all = 1; |
M_souta | 22:7d93f79a3686 | 104 | break; |
M_souta | 22:7d93f79a3686 | 105 | case 16: |
M_souta | 22:7d93f79a3686 | 106 | button = limitSw_N[0]; |
M_souta | 22:7d93f79a3686 | 107 | break; |
M_souta | 22:7d93f79a3686 | 108 | case 17: |
M_souta | 22:7d93f79a3686 | 109 | button = limitSw_N[1]; |
M_souta | 22:7d93f79a3686 | 110 | break; |
M_souta | 22:7d93f79a3686 | 111 | case 18: |
M_souta | 22:7d93f79a3686 | 112 | button = limitSw_N[2]; |
M_souta | 22:7d93f79a3686 | 113 | break; |
M_souta | 22:7d93f79a3686 | 114 | case 19: |
M_souta | 22:7d93f79a3686 | 115 | button = limitSw_N[3]; |
M_souta | 22:7d93f79a3686 | 116 | break; |
M_souta | 22:7d93f79a3686 | 117 | case 20: |
M_souta | 22:7d93f79a3686 | 118 | button = limitSw_N[4]; |
kishibekairohan | 16:3f2c2d89372b | 119 | break; |
7ka884 | 1:b1219d8ca117 | 120 | } |
7ka884 | 1:b1219d8ca117 | 121 | |
t_yamamoto | 0:669ef71cba68 | 122 | |
t_yamamoto | 0:669ef71cba68 | 123 | selectPin[0] = ch.s0; |
t_yamamoto | 0:669ef71cba68 | 124 | selectPin[1] = ch.s1; |
t_yamamoto | 0:669ef71cba68 | 125 | selectPin[2] = ch.s2; |
t_yamamoto | 0:669ef71cba68 | 126 | selectPin[3] = ch.s3; |
7ka884 | 4:ba9df71868df | 127 | |
7ka884 | 1:b1219d8ca117 | 128 | wait_us(1); |
t_yamamoto | 0:669ef71cba68 | 129 | |
M_souta | 22:7d93f79a3686 | 130 | if(index < 16) return limitSw ? false : true; |
M_souta | 22:7d93f79a3686 | 131 | else return button ? false : true; |
t_yamamoto | 0:669ef71cba68 | 132 | } |
t_yamamoto | 0:669ef71cba68 | 133 | } |