just a test

Dependencies:   mbed

Fork of scoreLight_Advanced by Alvaro Cassinelli

Committer:
mbedalvaro
Date:
Sun May 06 14:40:19 2012 +0000
Revision:
21:bc9b9383f4b6
Parent:
19:228430f1350e
Child:
25:74cb85b85fd2
Version working but not optimal for CHI. This is the first day of the setup.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbedalvaro 0:345b3bc7a0ea 1 #include "soundSpot.h"
mbedalvaro 0:345b3bc7a0ea 2
mbedalvaro 0:345b3bc7a0ea 3 // Constructor:
mbedalvaro 0:345b3bc7a0ea 4 soundSpot::soundSpot() { // by default, the child constructor call the parameterless default constructor (we could force another by doing: soundSpot::soundSpot : LivingSpot (params...) { ..}
mbedalvaro 0:345b3bc7a0ea 5
mbedalvaro 0:345b3bc7a0ea 6 // DEFAULT sending mode will be all off:
mbedalvaro 0:345b3bc7a0ea 7 stopAllSending();
mbedalvaro 0:345b3bc7a0ea 8 resetAllSendingModes();
mbedalvaro 0:345b3bc7a0ea 9
mbedalvaro 0:345b3bc7a0ea 10 initCommonVariables();
mbedalvaro 18:d72935b13858 11
mbedalvaro 18:d72935b13858 12 // initialize timer for sending OSC data:
mbedalvaro 18:d72935b13858 13 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 18:d72935b13858 14 // instantiating the kind of blob.
mbedalvaro 18:d72935b13858 15 measureSendPeriod.start();
mbedalvaro 0:345b3bc7a0ea 16 }
mbedalvaro 0:345b3bc7a0ea 17
mbedalvaro 0:345b3bc7a0ea 18 // 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 0:345b3bc7a0ea 19 // 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 0:345b3bc7a0ea 20 soundSpot::~soundSpot() {
mbedalvaro 0:345b3bc7a0ea 21 }
mbedalvaro 0:345b3bc7a0ea 22
mbedalvaro 12:0de9cd2bced5 23 void soundSpot::setColor(unsigned char c) {
mbedalvaro 0:345b3bc7a0ea 24 blobColor=0x07&c; // we will use the first three bits to set the RGB colors.
mbedalvaro 21:bc9b9383f4b6 25 // NOTE: it may be better to have always the red on?
mbedalvaro 0:345b3bc7a0ea 26 }
mbedalvaro 0:345b3bc7a0ea 27
mbedalvaro 0:345b3bc7a0ea 28 void soundSpot::initCommonVariables() {
mbedalvaro 0:345b3bc7a0ea 29 firstTimeNoTouch=true;
mbedalvaro 0:345b3bc7a0ea 30 // randomForce.set(1,0);// first time there won't be any force, or random force
mbedalvaro 0:345b3bc7a0ea 31 // randomForce=randomForce.getRotatedDeg(1.0*(rand()%360));
mbedalvaro 0:345b3bc7a0ea 32 // randomForce.normalize();
mbedalvaro 0:345b3bc7a0ea 33
mbedalvaro 0:345b3bc7a0ea 34 noTouchedCounter=0;
mbedalvaro 0:345b3bc7a0ea 35 wallCounter=0;
mbedalvaro 0:345b3bc7a0ea 36 blobWallCollision=false;
mbedalvaro 0:345b3bc7a0ea 37 //slidingDirection=true; // (will change when touching wall)
mbedalvaro 0:345b3bc7a0ea 38
mbedalvaro 0:345b3bc7a0ea 39 render=true;
mbedalvaro 0:345b3bc7a0ea 40 standByMode=false;
mbedalvaro 0:345b3bc7a0ea 41 }
mbedalvaro 0:345b3bc7a0ea 42
mbedalvaro 0:345b3bc7a0ea 43 void soundSpot::resetAllSendingModes() {
mbedalvaro 0:345b3bc7a0ea 44 // RESET SENDING DATA:
mbedalvaro 18:d72935b13858 45 sendingOnlyWhenTouch=false;
mbedalvaro 0:345b3bc7a0ea 46 // (a) anchor mass data:
mbedalvaro 0:345b3bc7a0ea 47 sendingAnchorPosition=false;
mbedalvaro 0:345b3bc7a0ea 48 sendingAnchorForce=false; // this is the total force on the anchor mass, not just the recentering force
mbedalvaro 0:345b3bc7a0ea 49 sendingAnchorTouchWall=false;
mbedalvaro 0:345b3bc7a0ea 50 // (b) data from blob points:
mbedalvaro 18:d72935b13858 51 sendingLoopPositions=false;
mbedalvaro 0:345b3bc7a0ea 52 sendingLoopForces=false;// this is not just the forces from light, but all the forces in each particle
mbedalvaro 0:345b3bc7a0ea 53 sendingLoopForcesLight=false;// forces only from light
mbedalvaro 0:345b3bc7a0ea 54 sendingLoopRegions=false; // from this we can detect "hits"
mbedalvaro 0:345b3bc7a0ea 55 sendingLoopTouchWall=false;
mbedalvaro 0:345b3bc7a0ea 56 // (c) Blob geometry:
mbedalvaro 0:345b3bc7a0ea 57 sendingBlobArea=false;
mbedalvaro 0:345b3bc7a0ea 58 sendingBlobNormals=false;
mbedalvaro 0:345b3bc7a0ea 59 sendingBlobAngles=false; // redundant with sendingBlobNormals, but simplified (only angle of normal)
mbedalvaro 19:228430f1350e 60 sendingKineticEnergy=false;
mbedalvaro 0:345b3bc7a0ea 61 // (d) Light sensing statistics:
mbedalvaro 0:345b3bc7a0ea 62 sendingBlobMaxMin=false;
mbedalvaro 0:345b3bc7a0ea 63 sendingLightForce=false; // the total light force
mbedalvaro 0:345b3bc7a0ea 64 sendingTouched=false;
mbedalvaro 0:345b3bc7a0ea 65 // (e) Recentering vector: (note: redundant with sendingLightForce, IF the correction angle is known).
mbedalvaro 0:345b3bc7a0ea 66 sendingRecenteringVector=false;
mbedalvaro 0:345b3bc7a0ea 67 sendingRecenteringAngle=false;
mbedalvaro 0:345b3bc7a0ea 68 sendingRecenteringNorm=false;
mbedalvaro 0:345b3bc7a0ea 69 }
mbedalvaro 0:345b3bc7a0ea 70
mbedalvaro 0:345b3bc7a0ea 71 void soundSpot::stopAllSending() {
mbedalvaro 0:345b3bc7a0ea 72 // STOP HARDWARE SENDING MODE (per spot):
mbedalvaro 0:345b3bc7a0ea 73 sendSerial=false;
mbedalvaro 0:345b3bc7a0ea 74 sendOSC=true;
mbedalvaro 0:345b3bc7a0ea 75 }
mbedalvaro 0:345b3bc7a0ea 76
mbedalvaro 0:345b3bc7a0ea 77 void soundSpot::sendData(void) { // send data common to all kind of blobs
mbedalvaro 18:d72935b13858 78 // send common things, such as testing if it is the right time to send data:
mbedalvaro 18:d72935b13858 79
mbedalvaro 18:d72935b13858 80 if (measureSendPeriod.read_ms()>periodSendingData) {
mbedalvaro 18:d72935b13858 81 measureSendPeriod.stop();
mbedalvaro 18:d72935b13858 82 measureSendPeriod.reset();
mbedalvaro 18:d72935b13858 83
mbedalvaro 18:d72935b13858 84 // Send data specific to the derived class:
mbedalvaro 18:d72935b13858 85 if ((sendingOnlyWhenTouch==false)||(blobWallCollision==true)||(displaySensingBuffer.lightTouched==true))
mbedalvaro 18:d72935b13858 86 sendDataSpecific(); // this will depend on the kind of blob
mbedalvaro 18:d72935b13858 87
mbedalvaro 18:d72935b13858 88 measureSendPeriod.start();
mbedalvaro 18:d72935b13858 89 }
mbedalvaro 18:d72935b13858 90
mbedalvaro 0:345b3bc7a0ea 91 }
mbedalvaro 0:345b3bc7a0ea 92