aa

Dependencies:   mbed TrapezoidControl QEI

Committer:
kishibekairohan
Date:
Mon Jul 01 13:00:20 2019 +0000
Revision:
16:3f2c2d89372b
Parent:
4:ba9df71868df
Child:
19:96a462583af9
aaa;

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
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:
kishibekairohan 16:3f2c2d89372b 61 ch.all = 12;
kishibekairohan 16:3f2c2d89372b 62 break;
kishibekairohan 16:3f2c2d89372b 63 case 5:
kishibekairohan 16:3f2c2d89372b 64 ch.all = 13;
kishibekairohan 16:3f2c2d89372b 65 break;
kishibekairohan 16:3f2c2d89372b 66 case 6:
kishibekairohan 16:3f2c2d89372b 67 ch.all = 14;
kishibekairohan 16:3f2c2d89372b 68 break;
kishibekairohan 16:3f2c2d89372b 69 case 7:
kishibekairohan 16:3f2c2d89372b 70 ch.all = 15;
kishibekairohan 16:3f2c2d89372b 71 break;
kishibekairohan 16:3f2c2d89372b 72 case 8:
kishibekairohan 16:3f2c2d89372b 73 ch.all = 7;
kishibekairohan 16:3f2c2d89372b 74 break;
kishibekairohan 16:3f2c2d89372b 75 case 9:
7ka884 1:b1219d8ca117 76 ch.all = 6;
7ka884 1:b1219d8ca117 77 break;
kishibekairohan 16:3f2c2d89372b 78 case 10:
7ka884 1:b1219d8ca117 79 ch.all = 4;
7ka884 1:b1219d8ca117 80 break;
kishibekairohan 16:3f2c2d89372b 81 case 11:
7ka884 1:b1219d8ca117 82 ch.all = 5;
7ka884 1:b1219d8ca117 83 break;
kishibekairohan 16:3f2c2d89372b 84 case 12:
7ka884 1:b1219d8ca117 85 ch.all = 2;
7ka884 1:b1219d8ca117 86 break;
kishibekairohan 16:3f2c2d89372b 87 case 13:
7ka884 1:b1219d8ca117 88 ch.all = 3;
7ka884 1:b1219d8ca117 89 break;
kishibekairohan 16:3f2c2d89372b 90 case 14:
kishibekairohan 16:3f2c2d89372b 91 ch.all = 0;
kishibekairohan 16:3f2c2d89372b 92 break;
kishibekairohan 16:3f2c2d89372b 93 case 15:
kishibekairohan 16:3f2c2d89372b 94 ch.all = 1;
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 }