aa

Dependencies:   mbed TrapezoidControl QEI

Committer:
7ka884
Date:
Mon Oct 01 13:47:19 2018 +0000
Revision:
4:ba9df71868df
Parent:
2:c015739085d3
Child:
16:3f2c2d89372b
huhuhuh

Who changed what in which revision?

UserRevisionLine numberNew 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 // if(index > 0x0f) return false;
t_yamamoto 0:669ef71cba68 45
kishibekairohan 2:c015739085d3 46 //printf("%d\n", index);
t_yamamoto 0:669ef71cba68 47
t_yamamoto 0:669ef71cba68 48 MP_Channel ch;
7ka884 1:b1219d8ca117 49
7ka884 1:b1219d8ca117 50 switch(index){
7ka884 1:b1219d8ca117 51 case 0:
7ka884 1:b1219d8ca117 52 ch.all = 10;
7ka884 1:b1219d8ca117 53 break;
7ka884 1:b1219d8ca117 54 case 1:
7ka884 1:b1219d8ca117 55 ch.all = 11;
7ka884 1:b1219d8ca117 56 break;
7ka884 1:b1219d8ca117 57 case 2:
7ka884 1:b1219d8ca117 58 ch.all = 8;
7ka884 1:b1219d8ca117 59 break;
7ka884 1:b1219d8ca117 60 case 3:
7ka884 1:b1219d8ca117 61 ch.all = 9;
7ka884 1:b1219d8ca117 62 break;
7ka884 1:b1219d8ca117 63 case 4:
7ka884 1:b1219d8ca117 64 ch.all = 6;
7ka884 1:b1219d8ca117 65 break;
7ka884 1:b1219d8ca117 66 case 5:
7ka884 1:b1219d8ca117 67 ch.all = 7;
7ka884 1:b1219d8ca117 68 break;
7ka884 1:b1219d8ca117 69 case 6:
7ka884 1:b1219d8ca117 70 ch.all = 4;
7ka884 1:b1219d8ca117 71 break;
7ka884 1:b1219d8ca117 72 case 7:
7ka884 1:b1219d8ca117 73 ch.all = 5;
7ka884 1:b1219d8ca117 74 break;
7ka884 1:b1219d8ca117 75 case 8:
7ka884 1:b1219d8ca117 76 ch.all = 2;
7ka884 1:b1219d8ca117 77 break;
7ka884 1:b1219d8ca117 78 case 9:
7ka884 1:b1219d8ca117 79 ch.all = 3;
7ka884 1:b1219d8ca117 80 break;
7ka884 1:b1219d8ca117 81 }
7ka884 1:b1219d8ca117 82
t_yamamoto 0:669ef71cba68 83
t_yamamoto 0:669ef71cba68 84 selectPin[0] = ch.s0;
t_yamamoto 0:669ef71cba68 85 selectPin[1] = ch.s1;
t_yamamoto 0:669ef71cba68 86 selectPin[2] = ch.s2;
t_yamamoto 0:669ef71cba68 87 selectPin[3] = ch.s3;
7ka884 4:ba9df71868df 88
7ka884 1:b1219d8ca117 89 wait_us(1);
t_yamamoto 0:669ef71cba68 90
t_yamamoto 0:669ef71cba68 91 return limitSw ? false : true;
t_yamamoto 0:669ef71cba68 92 }
t_yamamoto 0:669ef71cba68 93 }