for child

Fork of TRP105F_Spline by Akifumi Takahashi

Committer:
aktk
Date:
Wed Jun 01 05:38:46 2016 +0000
Revision:
3:b56e933bebc2
Parent:
2:40ae18445079
Child:
4:701f958d137a
??to SPI

Who changed what in which revision?

UserRevisionLine numberNew contents of line
aktk 0:e85788b14028 1 /**
aktk 0:e85788b14028 2 * TRP105F_Spline.h,.cpp
aktk 0:e85788b14028 3 *
aktk 2:40ae18445079 4 * Author: aktk, aktk.j.uec@gmail.com
aktk 2:40ae18445079 5 * Tokyo, Japan.
aktk 2:40ae18445079 6 *
aktk 2:40ae18445079 7 * - This library is for providing a distance from TRP105F, photo-reflect proximity sensor,
aktk 0:e85788b14028 8 * to whatever reflect the flash.
aktk 2:40ae18445079 9 * - Deistance is derived as a voltage signal of TRP105F.
aktk 0:e85788b14028 10 * - An object of TRPFS class has an array of sets of
aktk 0:e85788b14028 11 * distance(16 bit-value) and voltage(16bit-value) at the distance.
aktk 2:40ae18445079 12 * - The range of distances that an array has in sets is [0:255] by 1.
aktk 2:40ae18445079 13 * - an array is derived from a cubic spline curve model.
aktk 0:e85788b14028 14 * - In order to derive spline curve, some value sets should be got
aktk 0:e85788b14028 15 * at the first calibration.
aktk 0:e85788b14028 16 *
aktk 0:e85788b14028 17 * LOG:
aktk 0:e85788b14028 18 * ver.1 2015/10/19 - 2015/10/22
aktk 0:e85788b14028 19 * ver.2 2015/10/22 -
aktk 0:e85788b14028 20 * Distance data type has become unsigned short from int.
aktk 0:e85788b14028 21 * Distance data range : [2:20] by 1 -> [0:1024] by 1.
aktk 2:40ae18445079 22 * ver.2.1 2016/02.12 - 2016/02/16
aktk 1:2053662b1167 23 * Distance data range : [0:1024] -> [0:255].
aktk 0:e85788b14028 24 */
aktk 0:e85788b14028 25 #ifndef TRP105F_Spline_H
aktk 0:e85788b14028 26 #define TRP105F_Spline_H
aktk 0:e85788b14028 27
aktk 0:e85788b14028 28 #include "mbed.h"
aktk 0:e85788b14028 29
aktk 0:e85788b14028 30
aktk 3:b56e933bebc2 31 // For SPI
aktk 3:b56e933bebc2 32 //int DAread(int channel);
aktk 3:b56e933bebc2 33
aktk 0:e85788b14028 34 // Set of voltage-distance
aktk 0:e85788b14028 35 typedef struct {
aktk 3:b56e933bebc2 36 unsigned short x; // distance
aktk 3:b56e933bebc2 37 unsigned short y; // voltage
aktk 0:e85788b14028 38 } VDset;
aktk 0:e85788b14028 39
aktk 1:2053662b1167 40 // Type of modality to input data for calibration
aktk 3:b56e933bebc2 41 enum UseType {
aktk 3:b56e933bebc2 42 AsDEBUG,
aktk 3:b56e933bebc2 43 AsMODULE
aktk 0:e85788b14028 44 } ;
aktk 0:e85788b14028 45
aktk 0:e85788b14028 46 //
aktk 0:e85788b14028 47 // TRP105FS Class for get distance from voltage
aktk 2:40ae18445079 48 //
aktk 0:e85788b14028 49 class TRP105FS
aktk 0:e85788b14028 50 {
aktk 0:e85788b14028 51 public:
aktk 1:2053662b1167 52 // Constraction
aktk 0:e85788b14028 53 TRP105FS();
aktk 0:e85788b14028 54 TRP105FS(unsigned int);
aktk 3:b56e933bebc2 55 TRP105FS(unsigned int, UseType);
aktk 3:b56e933bebc2 56 TRP105FS(unsigned int, UseType, PinName);
aktk 3:b56e933bebc2 57 //TRP105FS(unsigned int arg_num, DataInType arg_dit, unsigned int channel);
aktk 1:2053662b1167 58 // Destraction
aktk 0:e85788b14028 59 ~TRP105FS();
aktk 1:2053662b1167 60 // Functions
aktk 3:b56e933bebc2 61 unsigned short getDistance(unsigned short); // alias of getX
aktk 3:b56e933bebc2 62 unsigned short getDistance(); // get voltage from PinName and getX()
aktk 3:b56e933bebc2 63 unsigned short getX(unsigned short); // the fuction to get distance.
aktk 3:b56e933bebc2 64 unsigned short getY(unsigned short);
aktk 0:e85788b14028 65 void calibrateSensor();
aktk 3:b56e933bebc2 66 //void calibrateSensor(VDset* arg_set, unsigned int arg_num);
aktk 3:b56e933bebc2 67 void calibrate();
aktk 3:b56e933bebc2 68 void setSample(unsigned short,unsigned short);
aktk 0:e85788b14028 69 void saveSetting();
aktk 1:2053662b1167 70 void saveSetting(const char *filename);
aktk 0:e85788b14028 71 void loadSetting();
aktk 1:2053662b1167 72 void loadSetting(const char *filename);
aktk 0:e85788b14028 73 void printOutData();
aktk 0:e85788b14028 74 void printThresholds();
aktk 0:e85788b14028 75
aktk 0:e85788b14028 76 private:
aktk 1:2053662b1167 77 //
aktk 1:2053662b1167 78 // Defining Constants
aktk 1:2053662b1167 79 //
aktk 0:e85788b14028 80 enum _SetConstant {
aktk 0:e85788b14028 81 _LIDX = 0,
aktk 1:2053662b1167 82 _RIDX = 255,
aktk 0:e85788b14028 83 _ENUM = _RIDX - _LIDX + 1
aktk 0:e85788b14028 84 };
aktk 1:2053662b1167 85 //
aktk 1:2053662b1167 86 // Variables
aktk 1:2053662b1167 87 //
aktk 3:b56e933bebc2 88 UseType _useType;
aktk 3:b56e933bebc2 89 unsigned int _Sample_Num; // the number of samples for derive spline
aktk 3:b56e933bebc2 90 VDset* _Sample_Set;
aktk 3:b56e933bebc2 91 VDset _Set[_ENUM];
aktk 3:b56e933bebc2 92 unsigned short _Threshold[_ENUM]; //_Threshold[18] is not used virtually.
aktk 3:b56e933bebc2 93 double* _u_spline;
aktk 3:b56e933bebc2 94 //
aktk 3:b56e933bebc2 95 // Variable for spi
aktk 3:b56e933bebc2 96 //
aktk 3:b56e933bebc2 97 //unsigned int _channel;
aktk 0:e85788b14028 98 //
aktk 0:e85788b14028 99 // For calibration
aktk 0:e85788b14028 100 //
aktk 0:e85788b14028 101 void _sampleData();
aktk 3:b56e933bebc2 102 void _setSample(unsigned short,unsigned short);
aktk 3:b56e933bebc2 103 void _setSamples(VDset* arg_set, unsigned int arg_num);
aktk 3:b56e933bebc2 104 unsigned short _getSplineYof(double arg_x);
aktk 0:e85788b14028 105 void _makeSpline(); // Cubic spline
aktk 0:e85788b14028 106 //
aktk 0:e85788b14028 107 // For get distance
aktk 0:e85788b14028 108 //
aktk 0:e85788b14028 109 int _getNearest(int, int, unsigned short);
aktk 0:e85788b14028 110 //
aktk 1:2053662b1167 111 // For debug
aktk 1:2053662b1167 112 //
aktk 0:e85788b14028 113 void _printOutData(unsigned short *arg, int num, char* name);
aktk 0:e85788b14028 114 void _printOutData(VDset *arg, int num, char* name);
aktk 0:e85788b14028 115 void _printOutData(double *arg, int num, char* name);
aktk 0:e85788b14028 116 };
aktk 0:e85788b14028 117 #endif