summaryrefslogtreecommitdiff
path: root/src/obtsDevice.cpp
blob: 630af693904d0c8b35a38012f68fe7940a1aff67 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
#include "obtsDevice.h"

obtsDevice::obtsDevice()
{
}

obtsDevice::obtsDevice(string &imsi,string &imei,string &num,ofImage *_icon,ofVec2f _coords)
{
	IMSI=imsi;
	IMEI=imei;
	number=num;
	coords=_coords;
	icon=_icon;
	active=false;
	calling=false;
	exciteLevel=0.99;
	lastTime=ofGetElapsedTimef();
	
	
	if (IMSI.size()) {
		
		//colour based on IMSI
		string cc=IMSI.substr(3,2);
		
		printf("new device: carrier code %s\n",cc.c_str());
		
		if(!cc.compare("02")) { //O2
			colour=ofColor(0,88,150);
		}
		else if (!cc.compare("01")) { //vodafone
			colour=ofColor(248,0,0);
		}
		else if (!cc.compare("03")) { //meteor
			colour=ofColor(242,105,0);
		}
		else if (!cc.compare("05")) { //three
			colour=ofColor(0,168,0);
		}
		else if (!cc.compare("07")) { //eircom
			colour=ofColor(241,91,37);
		}
		else colour=ofColor(160,160,160);
	}
	else colour=ofColor(0,0,0);
	
}

obtsDevice::~obtsDevice()
{
    //dtor
}


void obtsDevice::connect(){
	if (!active) {
		connectionHistory.push_back(timeseg());
		active=true;
	}
}

void obtsDevice::disconnect(){
	if (active) {
		connectionHistory[connectionHistory.size()-1].endTime=ofGetElapsedTimef();
		active=false;
	}
}

void obtsDevice::ringing(obtsDevice *to){
	if (!calling) {
		callHistory.push_back(tcall(to,false));
		calling=true;
	}
}

void obtsDevice::connectCall(){
	if (calling) {
		callHistory[callHistory.size()-1].connect();
	}
}

void obtsDevice::call(obtsDevice *to){
	if (!calling) {
		callHistory.push_back(tcall(to,true));
		calling=true;
	}
}

void obtsDevice::endCall(){
	if (calling) {
		callHistory[callHistory.size()-1].endTime=ofGetElapsedTimef();
		callHistory[callHistory.size()-1].connected=false;
		calling=false;
	}
}

void obtsDevice::sms(obtsDevice *to){
	smsHistory.push_back(tsms(to));
	printf("%s: %i sms in history\n",number.c_str(),smsHistory.size());
}

void obtsDevice::excite(float amount) {
	if (!active) connect(); //we lost it for some reason
	exciteLevel=amount;
	lastUsed=ofGetElapsedTimef();
}

float obtsDevice::timeCoord(float t){
	//function to map time to the z dimension
	//timescale is the number of pixels per second
	//return t*timeScale;
	return log10(t+1)*(ofGetHeight()/4);
}

void obtsDevice::draw(float t)
{
	timeScale=t;
	float decay=2.0;
	float now=ofGetElapsedTimef();
	if ((now-lastUsed) > 6000) disconnect(); //connection timeout 10 minutes
	float timeSeg=now-lastTime;
	lastTime=now;
	//draw a line at the angular position of the device 
	//z=0 is the  'surface' i.e. now.
	//the device know the time now and when it was created 
	//needs to know the time the app began in order to scale the line vertically
	//dynamic scaling or fixed vertical scale?
	//for dynamic, just scale vertically based on time
	//for fixed/dynamic, pass a scaling parameter when drawing
	
	//enable depth? possible?
	//colour based on IMSI, excitation and movement
	//sms and calls coloured based on the phone that made them.
	
	if (connectionHistory.size()) {
	
		float rf=sin((coords.y/(ofGetWidth()*0.9))*TWO_PI);
		ofSetColor(colour); //*rf);
		float endPos;
		for (vector<timeseg>::iterator i=connectionHistory.begin();i!=connectionHistory.end();i++){
			float startPos=-timeCoord(now-(*i).startTime);
			endPos=(*i).endTime>0.0f?-timeCoord(now-(*i).endTime):0.0f;
			ofLine(cos(coords.x)*coords.y,sin(coords.x)*coords.y,startPos,cos(coords.x)*coords.y,sin(coords.x)*coords.y,endPos);
			//printf("%f drawing %f,%f,%f to %f,%f,%f\n",ofGetElapsedTimef(),cos(coords.x)*coords.y,sin(coords.x)*coords.y,startPos,cos(coords.x)*coords.y,sin(coords.x)*coords.y,endPos);
		}

		for (vector<tsms>::iterator i=smsHistory.begin();i!=smsHistory.end();i++){
			float timepos=-timeCoord(now-(*i).time);
			ofLine(cos(coords.x)*coords.y,sin(coords.x)*coords.y,timepos,cos((*i).recipient->coords.x)*(*i).recipient->coords.y,sin((*i).recipient->coords.x)*(*i).recipient->coords.y,timepos);
		}
		
		ofEnableAlphaBlending();
		
		for (vector<tcall>::iterator i=callHistory.begin();i!=callHistory.end();i++){
			float stimepos=-timeCoord(now-(*i).startTime);
			float etimepos=((*i).endTime>0.0f?-timeCoord(now-(*i).endTime):0.0f);
			float ctimepos=(*i).endTime<.01f&&!(*i).connected?0.0f:-timeCoord(now-(*i).connectedTime);
			if (((*i).connectedTime>(*i).startTime)||((!(*i).connected)&&((*i).endTime<.01f))) { //draw ringing section
				ofSetColor(colour.r,colour.g,colour.b,0x2f);
				glBegin(GL_QUADS);
				glVertex3f(cos(coords.x)*coords.y,sin(coords.x)*coords.y,stimepos);
				glVertex3f(cos((*i).recipient->coords.x)*(*i).recipient->coords.y,sin((*i).recipient->coords.x)*(*i).recipient->coords.y,stimepos);
				glVertex3f(cos((*i).recipient->coords.x)*(*i).recipient->coords.y,sin((*i).recipient->coords.x)*(*i).recipient->coords.y,ctimepos);
				glVertex3f(cos(coords.x)*coords.y,sin(coords.x)*coords.y,ctimepos);
				glEnd();
			}
			if ((*i).connectedTime>0.0f) { //draw connected section
				ofSetColor(colour.r,colour.g,colour.b,0x4f);
				glBegin(GL_QUADS);
				glVertex3f(cos(coords.x)*coords.y,sin(coords.x)*coords.y,ctimepos);
				glVertex3f(cos((*i).recipient->coords.x)*(*i).recipient->coords.y,sin((*i).recipient->coords.x)*(*i).recipient->coords.y,ctimepos);
				glVertex3f(cos((*i).recipient->coords.x)*(*i).recipient->coords.y,sin((*i).recipient->coords.x)*(*i).recipient->coords.y,etimepos);
				glVertex3f(cos(coords.x)*coords.y,sin(coords.x)*coords.y,etimepos);
				glEnd();
			}
		}
		
		ofDisableAlphaBlending();
		
		int greylev=0x7f+((int)(128.0f*exciteLevel));
		//printf("%s %i\n",number.c_str(),greylev);
		ofSetColor(greylev,greylev,greylev,0xff);
		ofSetDrawBitmapMode(OF_BITMAPMODE_MODEL_BILLBOARD);
		ofDrawBitmapString(number,cos(coords.x)*coords.y,sin(coords.x)*coords.y,endPos);
		ofSetDrawBitmapMode(OF_BITMAPMODE_SIMPLE);
		exciteLevel=pow(exciteLevel,1+(timeSeg*decay));
	}
}