just a test

Dependencies:   mbed

Fork of scoreLight_Advanced by Alvaro Cassinelli

Committer:
mbedalvaro
Date:
Mon Oct 29 14:28:47 2012 +0000
Revision:
32:52273c3291fe
Parent:
31:5f039cbddee8
Child:
44:46e25fa1669b
code for Tokyo design week (starting with two colored following spots, and NO standby mode)

Who changed what in which revision?

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