RPI Haptics:Interface
From BluWiki
Sixth revision. Eatmoreart 19:56, 24 April 2008 (EDT)
Contents |
VibroByte Control Abstraction
FULLY FUNCTIONAL, baby!
The abstraction is initialized with two arguments: the first to set its type (group or single), the second to set its address. It can be addressed via OSC, and can also be used as a GUI to output OSC. The selected vibration pattern is made visible with a custom LED object. See the help patch for more information.
For the PD version go here: PD interface
Dependencies: etp.led.js, stringsplit.js, ETPMatrix.pat, Waveform Images.
To download the Max version and all dependencies in one easy package, click here: ETP_rev6.zip.txt (rename to ETP_rev6.zip, then expand). Note: contains OSC-to-serial interpreter.
ETP_rev6.pat
Download in Max/MSP txt format: ETP_rev6.txt
ETP_rev6.help
Download in Max/MSP txt format: ETP_rev6.help.txt
Waveform Images
To be placed in the Max search path or the same folder as the ETP patch:
ETP-Square.png
ETP-Sine.png
ETP-Sawtooth1.png
ETP-Sawtooth2.png
stringsplit.js
To be placed anywhere in the Max search path.
function split(s) {
var stringout = "";
var index = s.split("/");
var length = index.length;
for(var i=0; i<length; i++) {
stringout = stringout + index[i] + " ";
}
outlet(0,stringout);
}
ETPMatrix.pat
Routing controls � to be placed anywhere in the Max search path.
Modified LED object
etp.led.js
Place in jsui-library folder.
Accepts:
- floats: changes the intensity (0 is off, 1 is on)
- setcolor: changes LED color
- setbgcolor: changes background color
- setdiameter: changes the LED diameter
Outputs:
- float: the intensity of the led, can be toggled between 0 and 1 by clicking
Color and size can be specified via the jsui Inspector window arguments field. Right-click and drag to change intensity. Hold shift for fine adjustment.
var diameter = .8;
var foreground = [1., .1, .1, 0];
var background = [.9, .9, .9, 1];
if(jsarguments.length > 3)
foreground = [jsarguments[1]/255., jsarguments[2]/255., jsarguments[3]/255., 0];
if(jsarguments.length > 6)
background = [jsarguments[5]/255., jsarguments[6]/255., jsarguments[7]/255., 1];
if(jsarguments.length > 7)
diameter = jsarguments[9];
var state = 0;
var last_x, last_y;
var basestate;
draw();
function draw() {
foreground[3] = state;
with (sketch) {
glclearcolor(background);
glclear();
moveto(0,0);
glcolor(foreground);
circle(diameter);
}
outlet(0, state);
refresh();
}
function msg_float(v) {
state = v;
draw();
}
function setcolor(r, g, b) {
foreground = [r / 255., g / 255., b / 255., state];
draw();
}
function setbgcolor(r, g, b) {
background = [r / 255., g / 255., b / 255., 1.];
draw();
}
function setdiameter(v) {
diameter = v;
draw();
}
function onclick(x,y,but,cmd,shift,capslock,option,ctrl) {
// cache mouse position for tracking delta movements
last_x = x;
last_y = y;
basestate = state;
state = state == 0 ? 1 : 0;
draw();
}
function ondrag(x,y,but,cmd,shift,capslock,option,ctrl)
{
var m = 100;
// calculate delta movements
var dx = x - last_x;
if (shift){
m = 500;
}
if (but == 2) {
// change intensity if right-clicked
state = basestate + dx/m;
if(state < 0) {
state = 0;
}
else if (state > 1) {
state = 1;
}
draw();
}
}
etp.led.help
max v2; #N vpatcher 627 458 1026 709; #P window setfont "Sans Serif" 9.; #P flonum 59 212 35 9 0. 1. 3 139 0 0 0 221 221 221 222 222 222 0 0 0; #P window linecount 1; #P newex 275 91 93 9109513 prepend setdiameter; #P flonum 275 51 35 9 0. 1. 3 139 0 0 0 221 221 221 222 222 222 0 0 0; #P toggle 16 51 15 0; #P newex 165 91 87 9109513 prepend setbgcolor; #P user swatch 165 51 105 32; #P newex 59 91 77 9109513 prepend setcolor; #P user swatch 59 51 105 32; #P user jsui 59 141 64 64 1 0 0 etp.led.js; #P flonum 19 91 35 9 0. 1. 3 139 0 0 0 221 221 221 222 222 222 0 0 0; #P connect 2 0 3 0; #P connect 0 0 1 0; #P connect 6 0 1 0; #P connect 8 0 1 0; #P connect 5 0 1 0; #P connect 3 0 1 0; #P connect 1 0 9 0; #P connect 4 0 5 0; #P connect 7 0 8 0; #P pop;





