Skip to content

Commit

Permalink
updated infinity lights and played with writing data
Browse files Browse the repository at this point in the history
  • Loading branch information
christopher committed Mar 15, 2015
1 parent cd9db6b commit 187d872
Show file tree
Hide file tree
Showing 13 changed files with 2,139 additions and 531 deletions.
69 changes: 61 additions & 8 deletions InfinityPortal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,22 +52,64 @@ libusb_device_handle* InfinityPortal::connect(int deviceId) {
}
}

void InfinityPortal::getTagId() {

// ff 03 b4 26 00 dc 02 06 ff 00 00 ca 36 f1 2c 70 00 00 00 00 36 e7 3c 90 00 00 00 00 00 00 00 00
unsigned char* packet = new unsigned char[32];

packet[0] = 0xff;
packet[1] = 0x03;
packet[2] = 0xb4;
packet[3] = 0x26;
packet[4] = 0x00;
packet[5] = 0xdc;
packet[6] = 0x02;
packet[7] = 0x06;
packet[8] = 0xff;
packet[9] = 0x00;
packet[10] = 0x00;
packet[11] = 0xca;
packet[12] = 0x36;
packet[13] = 0xf1;
packet[14] = 0x2c;
packet[15] = 0x70;
packet[16] = 0x00;
packet[17] = 0x00;
packet[18] = 0x00;
packet[19] = 0x00;
packet[20] = 0x36;
packet[21] = 0xe7;
packet[22] = 0x3c;
packet[23] = 0x90;
packet[25] = 0x00;
packet[26] = 0x00;
packet[27] = 0x00;
packet[28] = 0x00;
packet[29] = 0x00;
packet[30] = 0x00;
packet[31] = 0x00;

sendPacket(packet);
}

void InfinityPortal::sendPacket(unsigned char* packet) {

int len;
int retVal;
int retVal = -1;

receivePackets();

retVal = libusb_bulk_transfer(deviceHandler,0x01,packet,32,&len,0);

if(retVal != 0) {
printf("Error code: %d\n",retVal);
printf("Error name: %s\n",libusb_error_name(retVal));
exit(1);
while(retVal < 0) {
retVal = libusb_bulk_transfer(deviceHandler,0x01,packet,32,&len,100);
receivePackets();
}

receivePackets();
// if(retVal != 0) {
// printf("Error code: %d\n",retVal);
// printf("Error name: %s\n",libusb_error_name(retVal));
// exit(1);
// }

}

void InfinityPortal::processReceivedPacket(unsigned char* packet) {
Expand All @@ -90,6 +132,17 @@ void InfinityPortal::processReceivedPacket(unsigned char* packet) {
} else {
printf("Tag removed from platform: %d\n",platformSetting);
}

getTagId();

} else if(packet[0x00] == 0xaa && packet[0x01] == 0x09) {
printf("Got tag info\n");

// make print tag info!!!
for(int i = 10 ; i > 2 ; i--) {
printf("%x ",packet[i]);
}
printf("\n");
}

}
Expand Down
1 change: 1 addition & 0 deletions InfinityPortal.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class InfinityPortal {
void flashColour(char platform, char r, char g, char b);
void fadeColour(char platform, char r, char g, char b);
void activate();
void getTagId();
private:
void processReceivedPacket(unsigned char* packet);
void sendPacket(unsigned char* packet);
Expand Down
559 changes: 40 additions & 519 deletions SkylandersPortal.cpp

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions SkylandersPortal.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class SkylandersPortal {
void reset();
void set();
void flashTrapLight();
void writeMaskerMind();
private:
libusb_device_handle* deviceHandler;
void writeData(char* data);
Expand Down
39 changes: 36 additions & 3 deletions beat.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,30 @@
$soxOut = $pipes[1];

$channelLast = array();
$peaksTroughs = array();

$startTime = microtime(true);

proc_open(sprintf("play %s 2>&1 &",$audioFile),array(0 => array("pipe", "r"),1 => array("pipe", "w")),$pipesAudio);
echo "Processing the music!\n";

$tempPlayout = tempnam("/tmp/","playOut");

// proc_open(sprintf("play %s 2>&1 >/dev/null | tr '\\r' '\\n' > %s &",$audioFile,$tempPlayout),array(0 => array("pipe", "r"),1 => array("pipe", "w")),$pipesAudio);
$fifoFile = "resources/playfifo";

posix_mkfifo($fifoFile, 777);
$pFile = popen(sprintf("/usr/bin/play %s 2>&1 >/dev/null | tr '\\r' '\\n' > %s &",$audioFile,$fifoFile),"r");

$fifo = fopen("playfifo","r");

echo "Getting ready!\n";

while(true) {

if(strpos(fgets($fifo),"In:") !== false) {
break;
}
}

echo "Starting the music!\n";

Expand All @@ -61,10 +81,23 @@

for($i = 1 ; $i <= $lightCount ; $i++) {
// if(isset($channelLast[$i-1]) && $data[$i] < $channelLast[$i-1]) {
if($data[$i] > 0) {
// if($data[$i] > 0) {
if($data[$i] > (($peaksTroughs[$i-1]["peak"]+$peaksTroughs[$i-1]["trough"])/2)) {
fwrite($lightPipes[0],$i."\n");
}

$channelLast[$i-1] = $data[$i];
if(isset($peaksTroughs[$i-1]["peak"])) {
$peaksTroughs[$i-1]["peak"] = max($peaksTroughs[$i-1]["peak"],$data[$i]);
$peaksTroughs[$i-1]["trough"] = min($peaksTroughs[$i-1]["trough"],$data[$i]);
} else {
$peaksTroughs[$i-1]["peak"] = $data[$i];
$peaksTroughs[$i-1]["trough"] = $data[$i];
}

}
}

// var_dump($peaksTroughs);
}

unlink($tempListOut);
Binary file modified infinitylights
Binary file not shown.
Binary file modified lightshow
Binary file not shown.
2 changes: 2 additions & 0 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ int main(int argc, char** argv) {
// skylanderPortals[j].setLeftColour(random()%0x100,random()%0x100,random()%0x100);
// skylanderPortals[j].setRightColour(random()%0x100,random()%0x100,random()%0x100);
// skylanderPortals[j].flashTrapLight();
// skylanderPortals[j].writeMaskerMind();
return 0;
}

if(j < infinityPortalCount) {
Expand Down
62 changes: 62 additions & 0 deletions resources/calculateWritePacket.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php

$packetDump = file_get_contents("writePacketDump2");

$lines = explode("\n",$packetDump);

$started = false;

$setups = array();

$setupsCount = 0;

$setupNames = array("sheep creep", "broccoli guy", "chompy mage", "cuckoo clocker");

foreach($lines as $line) {

if(!$line) {
continue;
}

$split = explode(":",$line);
$data = explode(" ",trim($split[1]));
$dataBin = array();

if($data[0] == '57') {
$started = true;
}

if($started == true) {

if($data[0] == '57' || $data[0] == '51') {
$setups[$setupsCount][] = trim($split[1]);
} else {
$setupsCount++;
}
}
// foreach(explode(" ",$data) as $dataHex) {
// $dataBin[] = chr(hexdec($dataHex));
// }

}

$keyedSetup = array();

$counter = 0;
foreach($setups as $setupData) {

// echo $setupNames[$counter]."\n";
// foreach($setupData as $setupLine) {
// echo $setupLine."\n";
// }

$keyedSetup[$setupNames[$counter]][] = $setupData;

$counter++;

if($counter >= count($setupNames)) {
$counter = 0;
}
}

var_dump($keyedSetup);
11 changes: 11 additions & 0 deletions resources/maskerminddata
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
57 12 09 45 e0 90 e6 45 6c f4 73 be b8 22 e6 0d db df 2a
57 12 0d 3f 84 e9 22 cd 2d 49 a8 b4 e0 ac 83 54 b7 cd 77
57 12 11 86 b6 7f 43 f7 a6 83 4c 8b f5 90 c6 18 da 29 cd
57 12 21 e3 2b f2 dc 6f af b5 7f 9c 67 10 0e 83 2e 9c 10
57 12 08 62 3d ee c6 05 c7 0d d9 ee 91 17 f3 30 6a 91 78
57 10 0d 5a ff 62 7f 10 12 6b 0d 81 9f 41 90 44 ce d3 6c
57 10 10 4f fa a5 64 81 78 b9 f8 b3 f6 82 eb e5 6a 45 5d
57 10 08 31 23 26 be 33 a3 a7 d2 2c 1a 67 bb f5 79 4b 56
57 11 29 7d 08 c5 37 49 dc 00 bf aa 4f 8a da 3c e4 c8 07
57 11 2c a4 f9 e2 66 0f bc bf 37 36 8f ac 82 07 9a 4a db
57 11 24 e7 d7 03 ea cd 92 06 57 7d 57 23 47 28 43 0a 9c
2 changes: 1 addition & 1 deletion resources/sortPacketsArray.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

$lines = file_get_contents("flashlighttest");
$lines = file_get_contents("maskerminddata");

$lines = explode("\n",$lines);

Expand Down
Loading

0 comments on commit 187d872

Please sign in to comment.