aa
Dependencies: mbed TrapezoidControl QEI
Input/Switch/Switch.cpp@47:b6e5a6bfe7ab, 2019-10-05 (annotated)
- Committer:
- yabahiro
- Date:
- Sat Oct 05 21:53:35 2019 +0000
- Revision:
- 47:b6e5a6bfe7ab
- Parent:
- 31:45f97698857b
aa;
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 | }; |
t_yamamoto | 0:669ef71cba68 | 22 | |
t_yamamoto | 0:669ef71cba68 | 23 | void DipSw::Initialize() { |
t_yamamoto | 0:669ef71cba68 | 24 | for(uint8_t i=0; i < sizeof(dipSw)/sizeof(dipSw[0]); i++) { |
t_yamamoto | 0:669ef71cba68 | 25 | dipSw[i].mode(PullUp); |
t_yamamoto | 0:669ef71cba68 | 26 | } |
t_yamamoto | 0:669ef71cba68 | 27 | } |
t_yamamoto | 0:669ef71cba68 | 28 | |
t_yamamoto | 0:669ef71cba68 | 29 | uint8_t DipSw::GetStatus() { |
t_yamamoto | 0:669ef71cba68 | 30 | if(DIP0 == SW_ON) return 0; |
t_yamamoto | 0:669ef71cba68 | 31 | else if(DIP1 == SW_ON) return 1; |
t_yamamoto | 0:669ef71cba68 | 32 | else if(DIP2 == SW_ON) return 2; |
t_yamamoto | 0:669ef71cba68 | 33 | else if(DIP3 == SW_ON) return 3; |
t_yamamoto | 0:669ef71cba68 | 34 | |
t_yamamoto | 0:669ef71cba68 | 35 | return 0; |
t_yamamoto | 0:669ef71cba68 | 36 | } |
t_yamamoto | 0:669ef71cba68 | 37 | |
t_yamamoto | 0:669ef71cba68 | 38 | void LimitSw::Initialize() { |
t_yamamoto | 0:669ef71cba68 | 39 | for(uint8_t i=0; i<4; i++) selectPin[i] = 0; |
t_yamamoto | 0:669ef71cba68 | 40 | limitSw.mode(PullUp); |
t_yamamoto | 0:669ef71cba68 | 41 | } |
t_yamamoto | 0:669ef71cba68 | 42 | |
t_yamamoto | 0:669ef71cba68 | 43 | bool LimitSw::IsPressed(int index) { |
t_yamamoto | 0:669ef71cba68 | 44 | |
t_yamamoto | 0:669ef71cba68 | 45 | MP_Channel ch; |
7ka884 | 1:b1219d8ca117 | 46 | |
7ka884 | 1:b1219d8ca117 | 47 | switch(index){ |
7ka884 | 1:b1219d8ca117 | 48 | case 0: |
kishibekairohan | 16:3f2c2d89372b | 49 | ch.all = 8; |
7ka884 | 1:b1219d8ca117 | 50 | break; |
7ka884 | 1:b1219d8ca117 | 51 | case 1: |
kishibekairohan | 16:3f2c2d89372b | 52 | ch.all = 9; |
7ka884 | 1:b1219d8ca117 | 53 | break; |
7ka884 | 1:b1219d8ca117 | 54 | case 2: |
kishibekairohan | 16:3f2c2d89372b | 55 | ch.all = 10; |
7ka884 | 1:b1219d8ca117 | 56 | break; |
7ka884 | 1:b1219d8ca117 | 57 | case 3: |
kishibekairohan | 16:3f2c2d89372b | 58 | ch.all = 11; |
7ka884 | 1:b1219d8ca117 | 59 | break; |
7ka884 | 1:b1219d8ca117 | 60 | case 4: |
yabahiro | 31:45f97698857b | 61 | ch.all = 7; |
kishibekairohan | 16:3f2c2d89372b | 62 | break; |
kishibekairohan | 16:3f2c2d89372b | 63 | case 5: |
M_souta | 19:96a462583af9 | 64 | ch.all = 4; |
kishibekairohan | 16:3f2c2d89372b | 65 | break; |
kishibekairohan | 16:3f2c2d89372b | 66 | case 6: |
M_souta | 19:96a462583af9 | 67 | ch.all = 2; |
kishibekairohan | 16:3f2c2d89372b | 68 | break; |
kishibekairohan | 16:3f2c2d89372b | 69 | case 7: |
M_souta | 19:96a462583af9 | 70 | ch.all = 0; |
kishibekairohan | 16:3f2c2d89372b | 71 | break; |
kishibekairohan | 16:3f2c2d89372b | 72 | case 8: |
yabahiro | 31:45f97698857b | 73 | ch.all = 6; |
kishibekairohan | 16:3f2c2d89372b | 74 | break; |
kishibekairohan | 16:3f2c2d89372b | 75 | case 9: |
M_souta | 19:96a462583af9 | 76 | ch.all = 5; |
7ka884 | 1:b1219d8ca117 | 77 | break; |
kishibekairohan | 16:3f2c2d89372b | 78 | case 10: |
M_souta | 19:96a462583af9 | 79 | ch.all = 3; |
7ka884 | 1:b1219d8ca117 | 80 | break; |
kishibekairohan | 16:3f2c2d89372b | 81 | case 11: |
M_souta | 19:96a462583af9 | 82 | ch.all = 1; |
7ka884 | 1:b1219d8ca117 | 83 | break; |
kishibekairohan | 16:3f2c2d89372b | 84 | case 12: |
M_souta | 19:96a462583af9 | 85 | ch.all = 12; |
7ka884 | 1:b1219d8ca117 | 86 | break; |
kishibekairohan | 16:3f2c2d89372b | 87 | case 13: |
M_souta | 19:96a462583af9 | 88 | ch.all = 13; |
7ka884 | 1:b1219d8ca117 | 89 | break; |
kishibekairohan | 16:3f2c2d89372b | 90 | case 14: |
M_souta | 19:96a462583af9 | 91 | ch.all = 14; |
kishibekairohan | 16:3f2c2d89372b | 92 | break; |
kishibekairohan | 16:3f2c2d89372b | 93 | case 15: |
M_souta | 19:96a462583af9 | 94 | ch.all = 15; |
kishibekairohan | 16:3f2c2d89372b | 95 | break; |
7ka884 | 1:b1219d8ca117 | 96 | } |
7ka884 | 1:b1219d8ca117 | 97 | |
t_yamamoto | 0:669ef71cba68 | 98 | |
t_yamamoto | 0:669ef71cba68 | 99 | selectPin[0] = ch.s0; |
t_yamamoto | 0:669ef71cba68 | 100 | selectPin[1] = ch.s1; |
t_yamamoto | 0:669ef71cba68 | 101 | selectPin[2] = ch.s2; |
t_yamamoto | 0:669ef71cba68 | 102 | selectPin[3] = ch.s3; |
7ka884 | 4:ba9df71868df | 103 | |
7ka884 | 1:b1219d8ca117 | 104 | wait_us(1); |
t_yamamoto | 0:669ef71cba68 | 105 | |
t_yamamoto | 0:669ef71cba68 | 106 | return limitSw ? false : true; |
t_yamamoto | 0:669ef71cba68 | 107 | } |
t_yamamoto | 0:669ef71cba68 | 108 | } |