aa

Dependencies:   mbed TrapezoidControl QEI

Committer:
7ka884
Date:
Mon Sep 10 01:39:15 2018 +0000
Revision:
1:b1219d8ca117
Parent:
0:669ef71cba68
Child:
2:c015739085d3
A

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