da
Dependencies: mbed TrapezoidControl QEI
Input/Switch/Switch.cpp@0:669ef71cba68, 2018-09-08 (annotated)
- Committer:
- t_yamamoto
- Date:
- Sat Sep 08 06:05:22 2018 +0000
- Revision:
- 0:669ef71cba68
- Child:
- 1:b1219d8ca117
???????
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); |
t_yamamoto | 0:669ef71cba68 | 15 | DigitalOut selectPin[] = { |
t_yamamoto | 0:669ef71cba68 | 16 | DigitalOut(SELECT0_PIN), |
t_yamamoto | 0:669ef71cba68 | 17 | DigitalOut(SELECT1_PIN), |
t_yamamoto | 0:669ef71cba68 | 18 | DigitalOut(SELECT2_PIN), |
t_yamamoto | 0:669ef71cba68 | 19 | DigitalOut(SELECT3_PIN), |
t_yamamoto | 0:669ef71cba68 | 20 | }; |
t_yamamoto | 0:669ef71cba68 | 21 | |
t_yamamoto | 0:669ef71cba68 | 22 | void DipSw::Initialize() { |
t_yamamoto | 0:669ef71cba68 | 23 | for(uint8_t i=0; i < sizeof(dipSw)/sizeof(dipSw[0]); i++) { |
t_yamamoto | 0:669ef71cba68 | 24 | dipSw[i].mode(PullUp); |
t_yamamoto | 0:669ef71cba68 | 25 | } |
t_yamamoto | 0:669ef71cba68 | 26 | } |
t_yamamoto | 0:669ef71cba68 | 27 | |
t_yamamoto | 0:669ef71cba68 | 28 | uint8_t DipSw::GetStatus() { |
t_yamamoto | 0:669ef71cba68 | 29 | if(DIP0 == SW_ON) return 0; |
t_yamamoto | 0:669ef71cba68 | 30 | else if(DIP1 == SW_ON) return 1; |
t_yamamoto | 0:669ef71cba68 | 31 | else if(DIP2 == SW_ON) return 2; |
t_yamamoto | 0:669ef71cba68 | 32 | else if(DIP3 == SW_ON) return 3; |
t_yamamoto | 0:669ef71cba68 | 33 | |
t_yamamoto | 0:669ef71cba68 | 34 | return 0; |
t_yamamoto | 0:669ef71cba68 | 35 | } |
t_yamamoto | 0:669ef71cba68 | 36 | |
t_yamamoto | 0:669ef71cba68 | 37 | void LimitSw::Initialize() { |
t_yamamoto | 0:669ef71cba68 | 38 | for(uint8_t i=0; i<4; i++) selectPin[i] = 0; |
t_yamamoto | 0:669ef71cba68 | 39 | limitSw.mode(PullUp); |
t_yamamoto | 0:669ef71cba68 | 40 | } |
t_yamamoto | 0:669ef71cba68 | 41 | |
t_yamamoto | 0:669ef71cba68 | 42 | bool LimitSw::IsPressed(int index) { |
t_yamamoto | 0:669ef71cba68 | 43 | // if(index > 0x0f) return false; |
t_yamamoto | 0:669ef71cba68 | 44 | |
t_yamamoto | 0:669ef71cba68 | 45 | printf("%d\n", index); |
t_yamamoto | 0:669ef71cba68 | 46 | |
t_yamamoto | 0:669ef71cba68 | 47 | MP_Channel ch; |
t_yamamoto | 0:669ef71cba68 | 48 | ch.all = index; |
t_yamamoto | 0:669ef71cba68 | 49 | |
t_yamamoto | 0:669ef71cba68 | 50 | selectPin[0] = ch.s0; |
t_yamamoto | 0:669ef71cba68 | 51 | selectPin[1] = ch.s1; |
t_yamamoto | 0:669ef71cba68 | 52 | selectPin[2] = ch.s2; |
t_yamamoto | 0:669ef71cba68 | 53 | selectPin[3] = ch.s3; |
t_yamamoto | 0:669ef71cba68 | 54 | |
t_yamamoto | 0:669ef71cba68 | 55 | while(1); |
t_yamamoto | 0:669ef71cba68 | 56 | |
t_yamamoto | 0:669ef71cba68 | 57 | return limitSw ? false : true; |
t_yamamoto | 0:669ef71cba68 | 58 | } |
t_yamamoto | 0:669ef71cba68 | 59 | } |