just a test

Dependencies:   mbed

Fork of scoreLight_Advanced by Alvaro Cassinelli

Committer:
mbedalvaro
Date:
Tue Dec 02 04:28:42 2014 +0000
Revision:
48:7633d8e7b0d3
Parent:
47:2312a8dc9658
this is the working version of the skin games sowtware (aka, scorelight but with pre-determined "games")

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbedalvaro 31:5f039cbddee8 1 #include "soundSpot.h"
mbedalvaro 31:5f039cbddee8 2
mbedalvaro 47:2312a8dc9658 3 // SHOULD NOT BE HERE: (only because I am using serial princ pc object)
mbedalvaro 47:2312a8dc9658 4 #include "hardwareIO.h"
mbedalvaro 47:2312a8dc9658 5
mbedalvaro 31:5f039cbddee8 6 // Constructor:
mbedalvaro 31:5f039cbddee8 7 soundSpot::soundSpot() { // by default, the child constructor call the parameterless default constructor (we could force another by doing: soundSpot::soundSpot : LivingSpot (params...) { ..}
mbedalvaro 31:5f039cbddee8 8
mbedalvaro 31:5f039cbddee8 9 // DEFAULT sending mode will be all off:
mbedalvaro 31:5f039cbddee8 10 stopAllSending();
mbedalvaro 31:5f039cbddee8 11 resetAllSendingModes();
mbedalvaro 31:5f039cbddee8 12
mbedalvaro 31:5f039cbddee8 13 initCommonVariables();
mbedalvaro 31:5f039cbddee8 14
mbedalvaro 31:5f039cbddee8 15 // initialize timer for sending OSC data:
mbedalvaro 31:5f039cbddee8 16 periodSendingData=25;// by default, we send the data every 25 ms. Note: the "data" to send will of course depend on the kind of blob. That will be therefore re-set when
mbedalvaro 31:5f039cbddee8 17 // instantiating the kind of blob.
mbedalvaro 31:5f039cbddee8 18 measureSendPeriod.start();
mbedalvaro 31:5f039cbddee8 19 }
mbedalvaro 31:5f039cbddee8 20
mbedalvaro 31:5f039cbddee8 21 // IMPORTANT: the destructor of the base class is virtual, but it won't be implemented with the same name in the child class; therefore, it
mbedalvaro 31:5f039cbddee8 22 // must be implemented in the base class (and it will be called when using delete of the child, first the delete child, then delete base)
mbedalvaro 31:5f039cbddee8 23 soundSpot::~soundSpot() {
mbedalvaro 31:5f039cbddee8 24 }
mbedalvaro 31:5f039cbddee8 25
mbedalvaro 47:2312a8dc9658 26 void soundSpot::printParameters() {
mbedalvaro 47:2312a8dc9658 27 // first show common parameters, then call the virtual method:
mbedalvaro 47:2312a8dc9658 28 pc.printf("Mirror delay :%d\n", displaySensingBuffer.delayMirrorSamples);
mbedalvaro 47:2312a8dc9658 29 pc.printf("Angle correction force :%f\n", angleCorrectionForceLoop);
mbedalvaro 47:2312a8dc9658 30 pc.printf("Thresholding mode :%d\n", displaySensingBuffer.modeThreshold);
mbedalvaro 47:2312a8dc9658 31 pc.printf("Min Contrast Ratio :%f / Current Contrast: %f\n", displaySensingBuffer.min_contrast_ratio, 1.0*displaySensingBuffer.maxI/displaySensingBuffer.minI);
mbedalvaro 47:2312a8dc9658 32 pc.printf("Threshold Factor: %f\n", displaySensingBuffer.threshold_factor);
mbedalvaro 47:2312a8dc9658 33 pc.printf("Min Acceptable Intensity :%f\n", displaySensingBuffer.min_acceptable_intensity);
mbedalvaro 47:2312a8dc9658 34 pc.printf("Current Max / Min Intensity: %d / %d\n", displaySensingBuffer.maxI, displaySensingBuffer.minI, displaySensingBuffer.maxI/displaySensingBuffer.minI);
mbedalvaro 47:2312a8dc9658 35 this->showChildParameters();
mbedalvaro 47:2312a8dc9658 36 }
mbedalvaro 47:2312a8dc9658 37
mbedalvaro 31:5f039cbddee8 38 void soundSpot::setColor(unsigned char c) {
mbedalvaro 31:5f039cbddee8 39 blobColor=0x07&c; // we will use the first three bits to set the RGB colors.
mbedalvaro 31:5f039cbddee8 40 }
mbedalvaro 31:5f039cbddee8 41
mbedalvaro 32:52273c3291fe 42 void soundSpot::setGreenColor(unsigned char c) {
mbedalvaro 32:52273c3291fe 43 // this set/reset the green bit only:
mbedalvaro 32:52273c3291fe 44 if (c>0) blobColor=blobColor|0x2; //meaning second bit to 1
mbedalvaro 32:52273c3291fe 45 else blobColor=blobColor&0x5; // meaning second bit to 0
mbedalvaro 32:52273c3291fe 46 }
mbedalvaro 32:52273c3291fe 47
mbedalvaro 32:52273c3291fe 48 void soundSpot::setBlueColor(unsigned char c) {
mbedalvaro 32:52273c3291fe 49 // this set/reset the green bit only:
mbedalvaro 32:52273c3291fe 50 if (c>0) blobColor=blobColor|0x1; //meaning first bit to 1
mbedalvaro 32:52273c3291fe 51 else blobColor=blobColor&0x6; // meaning first bit to 0
mbedalvaro 32:52273c3291fe 52 }
mbedalvaro 32:52273c3291fe 53
mbedalvaro 44:46e25fa1669b 54 void soundSpot::addAngleCorrection(float _moreAngleCorrection) {
mbedalvaro 44:46e25fa1669b 55 angleCorrectionForceLoop+=_moreAngleCorrection;
mbedalvaro 44:46e25fa1669b 56 }
mbedalvaro 44:46e25fa1669b 57 void soundSpot::setAngleCorrection(float _angleCorrection) {
mbedalvaro 44:46e25fa1669b 58 angleCorrectionForceLoop=_angleCorrection;
mbedalvaro 44:46e25fa1669b 59 }
mbedalvaro 44:46e25fa1669b 60
mbedalvaro 31:5f039cbddee8 61 void soundSpot::initCommonVariables() {
mbedalvaro 31:5f039cbddee8 62 firstTimeNoTouch=true;
mbedalvaro 31:5f039cbddee8 63 // randomForce.set(1,0);// first time there won't be any force, or random force
mbedalvaro 31:5f039cbddee8 64 // randomForce=randomForce.getRotatedDeg(1.0*(rand()%360));
mbedalvaro 31:5f039cbddee8 65 // randomForce.normalize();
mbedalvaro 31:5f039cbddee8 66
mbedalvaro 31:5f039cbddee8 67 noTouchedCounter=0;
mbedalvaro 31:5f039cbddee8 68 wallCounter=0;
mbedalvaro 31:5f039cbddee8 69 blobWallCollision=false;
mbedalvaro 31:5f039cbddee8 70 //slidingDirection=true; // (will change when touching wall)
mbedalvaro 31:5f039cbddee8 71
mbedalvaro 31:5f039cbddee8 72 gravity.set(0,0);
mbedalvaro 31:5f039cbddee8 73
mbedalvaro 31:5f039cbddee8 74 render=true;
mbedalvaro 31:5f039cbddee8 75 standByMode=true; // ALWAYS START IN STANDBY MODE
mbedalvaro 31:5f039cbddee8 76 }
mbedalvaro 31:5f039cbddee8 77
mbedalvaro 31:5f039cbddee8 78 void soundSpot::resetAllSendingModes() {
mbedalvaro 31:5f039cbddee8 79 // RESET SENDING DATA:
mbedalvaro 31:5f039cbddee8 80 sendingOnlyWhenTouch=false;
mbedalvaro 31:5f039cbddee8 81 // (a) anchor mass data:
mbedalvaro 31:5f039cbddee8 82 sendingAnchorPosition=false;
mbedalvaro 31:5f039cbddee8 83 sendingAnchorForce=false; // this is the total force on the anchor mass, not just the recentering force
mbedalvaro 31:5f039cbddee8 84 sendingAnchorTouchWall=false;
mbedalvaro 31:5f039cbddee8 85 // (b) data from blob points:
mbedalvaro 31:5f039cbddee8 86 sendingLoopPositions=false;
mbedalvaro 31:5f039cbddee8 87 sendingLoopForces=false;// this is not just the forces from light, but all the forces in each particle
mbedalvaro 31:5f039cbddee8 88 sendingLoopForcesLight=false;// forces only from light
mbedalvaro 31:5f039cbddee8 89 sendingLoopRegions=false; // from this we can detect "hits"
mbedalvaro 31:5f039cbddee8 90 sendingLoopTouchWall=false;
mbedalvaro 31:5f039cbddee8 91 // (c) Blob geometry:
mbedalvaro 31:5f039cbddee8 92 sendingBlobArea=false;
mbedalvaro 31:5f039cbddee8 93 sendingBlobNormals=false;
mbedalvaro 31:5f039cbddee8 94 sendingBlobAngles=false; // redundant with sendingBlobNormals, but simplified (only angle of normal)
mbedalvaro 31:5f039cbddee8 95 sendingKineticEnergy=false;
mbedalvaro 31:5f039cbddee8 96 // (d) Light sensing statistics:
mbedalvaro 31:5f039cbddee8 97 sendingBlobMaxMin=false;
mbedalvaro 31:5f039cbddee8 98 sendingLightForce=false; // the total light force
mbedalvaro 31:5f039cbddee8 99 sendingTouched=false;
mbedalvaro 31:5f039cbddee8 100 // (e) Recentering vector: (note: redundant with sendingLightForce, IF the correction angle is known).
mbedalvaro 31:5f039cbddee8 101 sendingRecenteringVector=false;
mbedalvaro 31:5f039cbddee8 102 sendingRecenteringAngle=false;
mbedalvaro 31:5f039cbddee8 103 sendingRecenteringNorm=false;
mbedalvaro 31:5f039cbddee8 104 }
mbedalvaro 31:5f039cbddee8 105
mbedalvaro 31:5f039cbddee8 106 void soundSpot::stopAllSending() {
mbedalvaro 31:5f039cbddee8 107 // STOP HARDWARE SENDING MODE (per spot):
mbedalvaro 31:5f039cbddee8 108 sendSerial=false;
mbedalvaro 31:5f039cbddee8 109 sendOSC=true;
mbedalvaro 31:5f039cbddee8 110 }
mbedalvaro 31:5f039cbddee8 111
mbedalvaro 31:5f039cbddee8 112 void soundSpot::sendData(void) { // send data common to all kind of blobs
mbedalvaro 31:5f039cbddee8 113 // send common things, such as testing if it is the right time to send data:
mbedalvaro 31:5f039cbddee8 114
mbedalvaro 31:5f039cbddee8 115 if (measureSendPeriod.read_ms()>periodSendingData) {
mbedalvaro 31:5f039cbddee8 116 measureSendPeriod.stop();
mbedalvaro 31:5f039cbddee8 117 measureSendPeriod.reset();
mbedalvaro 31:5f039cbddee8 118
mbedalvaro 31:5f039cbddee8 119 // Send data specific to the derived class:
mbedalvaro 31:5f039cbddee8 120 if ((sendingOnlyWhenTouch==false)||(blobWallCollision==true)||(displaySensingBuffer.lightTouched==true))
mbedalvaro 31:5f039cbddee8 121 sendDataSpecific(); // this will depend on the kind of blob
mbedalvaro 31:5f039cbddee8 122
mbedalvaro 31:5f039cbddee8 123 measureSendPeriod.start();
mbedalvaro 31:5f039cbddee8 124 }
mbedalvaro 31:5f039cbddee8 125
mbedalvaro 31:5f039cbddee8 126 }
mbedalvaro 31:5f039cbddee8 127