forked from Iskuri/Disney-Infinity-and-Skylanders-Lighting
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added light show functionality for songs
- Loading branch information
christopher
committed
Feb 23, 2015
1 parent
41cfbd5
commit cd9db6b
Showing
9 changed files
with
199 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
*.wav |
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
<?php | ||
|
||
if(posix_getuid() != 0) { | ||
die("Please run this application as root/sudo\n"); | ||
} | ||
|
||
if(!isset($argv[1])) { | ||
throw new Exception("No file selected"); | ||
} | ||
|
||
$audioFile = $argv[1]; | ||
$fileType = mime_content_type($audioFile); | ||
|
||
if($fileType != "audio/x-wav") { | ||
throw new Exception("Wrong file type selected"); | ||
} | ||
|
||
$lightShowProc = proc_open(sprintf("./lightshow",$audioFile),array(0 => array("pipe", "r"),1 => array("pipe", "w")),$lightPipes); | ||
|
||
$lightsLine = explode(" ",str_replace("\n","",fgets($lightPipes[1]))); | ||
|
||
if($lightsLine[0] != "lights") { | ||
throw new Exception("Output formatting error"); | ||
} | ||
|
||
$lightCount = $lightsLine[1]; | ||
|
||
$lightCount = max($lightCount,3); | ||
|
||
$soxProc = proc_open(sprintf("sox %s -t dat -r 32 -c %d - 2>&1",$audioFile,$lightCount),array(0 => array("pipe", "r"),1 => array("pipe", "w")),$pipes); | ||
|
||
$soxOut = $pipes[1]; | ||
|
||
$channelLast = array(); | ||
|
||
$startTime = microtime(true); | ||
|
||
proc_open(sprintf("play %s 2>&1 &",$audioFile),array(0 => array("pipe", "r"),1 => array("pipe", "w")),$pipesAudio); | ||
|
||
echo "Starting the music!\n"; | ||
|
||
while(!feof($soxOut)) { | ||
|
||
$line = trim(str_replace(array("\n","\r"),"",fgets($soxOut))); | ||
|
||
if(strpos($line,";") === 0 || !$line) { | ||
continue; | ||
} | ||
|
||
// $data = explode(" ",$line); | ||
$data = preg_split("/ +/",$line); | ||
$time = $data[0]; | ||
|
||
$currTime = microtime(true)-$startTime; | ||
|
||
while($currTime < $time) { | ||
$currTime = microtime(true)-$startTime; | ||
} | ||
|
||
// var_dump("It's $currTime"); | ||
|
||
for($i = 1 ; $i <= $lightCount ; $i++) { | ||
// if(isset($channelLast[$i-1]) && $data[$i] < $channelLast[$i-1]) { | ||
if($data[$i] > 0) { | ||
fwrite($lightPipes[0],$i."\n"); | ||
} | ||
|
||
$channelLast[$i-1] = $data[$i]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
/* | ||
* File: main.cpp | ||
* Author: christopher | ||
* | ||
* Created on 10 August 2014, 21:09 | ||
*/ | ||
|
||
#include <cstdlib> | ||
#include <stdio.h> | ||
#include <sys/types.h> | ||
#include <iostream> | ||
#include <math.h> | ||
#include "libusb-1.0/libusb.h" | ||
#include <unistd.h> | ||
#include "InfinityPortal.h" | ||
#include "SkylandersPortal.h" | ||
|
||
using namespace std; | ||
|
||
/* | ||
* | ||
*/ | ||
int main(int argc, char** argv) { | ||
|
||
srand (time(NULL)); | ||
|
||
libusb_device** devices; | ||
libusb_context* context; | ||
struct libusb_device_handle* tryDeviceHandler; | ||
|
||
libusb_init(&context); | ||
int devicesCount = libusb_get_device_list(context, &devices); | ||
|
||
struct libusb_device_descriptor descriptor; | ||
libusb_device_handle* deviceHandler; | ||
|
||
int retVal = 0; | ||
int skylanderPortalIds[0xff]; | ||
int infinityPortalIds[0xff]; | ||
int skylanderPortalCount = 0; | ||
int infinityPortalCount = 0; | ||
|
||
for(int i = 0 ; i < devicesCount ; i++) { | ||
|
||
retVal = libusb_open(devices[i], &tryDeviceHandler); | ||
|
||
if(retVal < 0) { | ||
continue; | ||
} | ||
|
||
libusb_get_device_descriptor(devices[i], &descriptor); | ||
|
||
if(descriptor.idVendor == 0x0e6f && descriptor.idProduct == 0x0129) { | ||
|
||
infinityPortalIds[infinityPortalCount] = i; | ||
infinityPortalCount++; | ||
|
||
} else if(descriptor.idVendor == 0x1430 && descriptor.idProduct == 0x150) { | ||
|
||
skylanderPortalIds[skylanderPortalCount] = i; | ||
skylanderPortalCount++; | ||
} | ||
} | ||
|
||
if(skylanderPortalCount == 0 && infinityPortalCount == 0) { | ||
printf("Please plug in either a Portal of Power or an Infinity Base\n"); | ||
return -1; | ||
} | ||
|
||
InfinityPortal infinityPortals[infinityPortalCount]; | ||
SkylandersPortal skylanderPortals[skylanderPortalCount]; | ||
|
||
int j; | ||
|
||
int lightsCount = 0; | ||
|
||
for(j = 0 ; j < infinityPortalCount ; j++) { | ||
infinityPortals[j] = InfinityPortal(infinityPortalIds[j]); | ||
lightsCount += 3; | ||
} | ||
|
||
for(j = 0 ; j < skylanderPortalCount ; j++) { | ||
skylanderPortals[j] = SkylandersPortal(skylanderPortalIds[j]); | ||
lightsCount += 1; | ||
} | ||
|
||
printf("lights %d\n",lightsCount); | ||
|
||
// while(true) { | ||
// for(j = 0 ; j < max(skylanderPortalCount,infinityPortalCount) ; j++) { | ||
// if(j < skylanderPortalCount) { | ||
// skylanderPortals[j].setColour(random()%0x100,random()%0x100,random()%0x100); | ||
// // skylanderPortals[j].setLeftColour(random()%0x100,random()%0x100,random()%0x100); | ||
// // skylanderPortals[j].setRightColour(random()%0x100,random()%0x100,random()%0x100); | ||
// // skylanderPortals[j].flashTrapLight(); | ||
// } | ||
|
||
// if(j < infinityPortalCount) { | ||
// for(int k = 0 ; k < 3 ; k++) { | ||
// infinityPortals[j].setColour(k+1,random()%0x100,random()%0x100,random()%0x100); | ||
// } | ||
// } | ||
// } | ||
|
||
// usleep(100000); | ||
// } | ||
|
||
for (std::string line; std::getline(std::cin, line);) { | ||
int intVal = atoi(line.c_str()); | ||
// printf("Got line: %d\n",intVal); | ||
|
||
if(intVal > lightsCount) { | ||
continue; | ||
} | ||
|
||
skylanderPortals[intVal-1].setColour(random()%0x100,random()%0x100,random()%0x100); | ||
|
||
} | ||
|
||
printf("Done!\n"); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters