Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of MainBoard2018_Auto_Master_A by
Switch.cpp
00001 #include "Switch.h" 00002 00003 #include <stdint.h> 00004 #include "mbed.h" 00005 00006 namespace SWITCH { 00007 DigitalIn dipSw[] = { 00008 DigitalIn(DIP0_PIN), 00009 DigitalIn(DIP1_PIN), 00010 DigitalIn(DIP2_PIN), 00011 DigitalIn(DIP3_PIN), 00012 }; 00013 00014 DigitalIn limitSw(LS_PIN); 00015 DigitalOut selectPin[] = { 00016 DigitalOut(SELECT0_PIN), 00017 DigitalOut(SELECT1_PIN), 00018 DigitalOut(SELECT2_PIN), 00019 DigitalOut(SELECT3_PIN), 00020 }; 00021 00022 void DipSw::Initialize() { 00023 for(uint8_t i=0; i < sizeof(dipSw)/sizeof(dipSw[0]); i++) { 00024 dipSw[i].mode(PullUp); 00025 } 00026 } 00027 00028 uint8_t DipSw::GetStatus() { 00029 if(DIP0 == SW_ON) return 0; 00030 else if(DIP1 == SW_ON) return 1; 00031 else if(DIP2 == SW_ON) return 2; 00032 else if(DIP3 == SW_ON) return 3; 00033 00034 return 0; 00035 } 00036 00037 void LimitSw::Initialize() { 00038 for(uint8_t i=0; i<4; i++) selectPin[i] = 0; 00039 limitSw.mode(PullUp); 00040 } 00041 00042 bool LimitSw::IsPressed(int index) { 00043 // if(index > 0x0f) return false; 00044 00045 //printf("%d\n", index); 00046 00047 MP_Channel ch; 00048 00049 switch(index){ 00050 case 0: 00051 ch.all = 10; 00052 break; 00053 case 1: 00054 ch.all = 11; 00055 break; 00056 case 2: 00057 ch.all = 8; 00058 break; 00059 case 3: 00060 ch.all = 9; 00061 break; 00062 case 4: 00063 ch.all = 6; 00064 break; 00065 case 5: 00066 ch.all = 7; 00067 break; 00068 case 6: 00069 ch.all = 4; 00070 break; 00071 case 7: 00072 ch.all = 5; 00073 break; 00074 case 8: 00075 ch.all = 2; 00076 break; 00077 case 9: 00078 ch.all = 3; 00079 break; 00080 } 00081 00082 00083 selectPin[0] = ch.s0; 00084 selectPin[1] = ch.s1; 00085 selectPin[2] = ch.s2; 00086 selectPin[3] = ch.s3; 00087 00088 wait_us(1); 00089 00090 return limitSw ? false : true; 00091 } 00092 }
Generated on Tue Jul 12 2022 19:08:04 by
1.7.2
