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 ds3_si by
ds3_si.cpp
00001 #include "mbed.h" 00002 #include "ds3_si.h" 00003 00004 ds3_si::ds3_si(PinName tx, PinName rx, int baudrate):serial(tx, rx) 00005 { 00006 in[0] = 128; 00007 in[1] = 0; 00008 in[2] = 0; 00009 in[3] = 64; 00010 in[4] = 64; 00011 in[5] = 64; 00012 in[6] = 64; 00013 in[7] = 0; 00014 00015 serial.baud(baudrate); 00016 serial.attach(callback(this, &ds3_si::serialin), Serial::RxIrq); 00017 } 00018 00019 void ds3_si::serialin() 00020 {__disable_irq(); 00021 NVIC_ClearPendingIRQ(UART0_IRQn); 00022 NVIC_ClearPendingIRQ(UART1_IRQn); 00023 NVIC_ClearPendingIRQ(UART2_IRQn); 00024 NVIC_ClearPendingIRQ(UART3_IRQn); 00025 if(serial.readable()) 00026 { 00027 while(serial.getc() != 128) {} 00028 for(short i = 1; i < 8; i++) 00029 { 00030 *(in + i) = serial.getc(); 00031 } 00032 } 00033 __enable_irq(); 00034 } 00035 00036 bool ds3_si::buttonstate(short order) 00037 { 00038 return in[(order >> 7) + 1] & order; 00039 } 00040 00041 int ds3_si::analogstate(short order) 00042 { 00043 return (order % 2) ? in[order] - 64 : 64 - in[order]; 00044 } 00045 00046 int ds3_si::getinputdata(short order) 00047 { 00048 return in[order]; 00049 } 00050 00051 double ds3_si::getangle(short order) 00052 { 00053 int x = analogstate(order * 2 + 1); 00054 int y = analogstate(order * 2 + 2); 00055 if(x || y) return atan2(double(y), double(x)); 00056 else return NONE_angle; 00057 }
Generated on Fri Jul 15 2022 09:53:26 by
1.7.2
