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.
Dependencies: DmTouch_UniGraphic UniGraphic-forLdelaney17FinalProject mbed
acc.cpp
00001 #include "acc.h" 00002 00003 00004 void acc_init(float duration, float threshold, float gap, float window){ 00005 //acc = &connection; 00006 char durationByte, thresholdByte, gapByte, windowByte; 00007 00008 //convert the function parameters from their respective units to the appropriate byte values 00009 durationByte = duration / 0.625; 00010 thresholdByte = threshold / 0.00625; 00011 gapByte = gap / 1.25; 00012 windowByte = window / 1.25; 00013 00014 //set the config constants 00015 char acc_config_dataFormat[2] = {0x31,0x0b}; //measurement range 00016 char acc_config_powerControl[2] = {0x2d,0x08}; 00017 char acc_config_tapThreshold[2] = {0x1d,thresholdByte}; 00018 char acc_config_tapDuration[2] = {0x21,durationByte}; 00019 char acc_config_latentGap[2] = {0x22,gapByte}; 00020 char acc_config_window[2] = {0x23,windowByte}; 00021 char acc_config_enableAxis[2] = {0x2a,0x07}; 00022 char acc_config_intEnable[2] = {0x2e,0x60}; 00023 char acc_config_intMap[2] = {0x2f,0x60}; 00024 00025 //set the configuration 00026 connection.write(addr_acc, acc_config_dataFormat, 2); //full measurement range 00027 wait(.05); 00028 connection.write(addr_acc, acc_config_tapDuration, 2); 00029 wait(.05); 00030 connection.write(addr_acc, acc_config_tapThreshold, 2); 00031 wait(.05); 00032 connection.write(addr_acc, acc_config_latentGap, 2); 00033 wait(.05); 00034 connection.write(addr_acc, acc_config_window, 2); 00035 wait(.05); 00036 connection.write(addr_acc, acc_config_enableAxis, 2); 00037 wait(.05); 00038 connection.write(addr_acc, acc_config_intEnable, 2); 00039 wait(.05); 00040 connection.write(addr_acc, acc_config_intMap, 2); 00041 wait(.05); 00042 connection.write(addr_acc, acc_config_powerControl, 2); // measure mode 00043 wait(.05); 00044 } 00045 00046 char get_int_type(){ 00047 char int_source_arr[2] = {0x30|0x80, 0x00}; 00048 connection.write(addr_acc, int_source_arr, 1); //set up the connection for reading from int_source 00049 char acc_data[1]; 00050 connection.read(addr_acc, acc_data, 1); //read the int_source byte 00051 //pc.printf("%x\t",acc_data[0]&0x60); //this was used for debugging 00052 if(acc_data[0] & 0x20) //if a double tap, return 2 00053 return 2; 00054 else if (acc_data[0] & 0x40) //if a single tap, return 1 00055 return 1; 00056 //this code should never be reached, but is included so that there is an appropriate exit path 00057 return 0; 00058 }
Generated on Wed Jul 27 2022 04:00:21 by
