diff --git a/.dep.inc b/.dep.inc deleted file mode 100644 index 4560e55..0000000 --- a/.dep.inc +++ /dev/null @@ -1,5 +0,0 @@ -# This code depends on make tool being used -DEPFILES=$(wildcard $(addsuffix .d, ${OBJECTFILES})) -ifneq (${DEPFILES},) -include ${DEPFILES} -endif diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d8dd753 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*.wav diff --git a/DeviceHandler.cpp b/DeviceHandler.cpp new file mode 100644 index 0000000..e69de29 diff --git a/DeviceHandler.h b/DeviceHandler.h new file mode 100644 index 0000000..e69de29 diff --git a/Makefile b/Makefile index 4e5ebdb..0290c9f 100644 --- a/Makefile +++ b/Makefile @@ -2,6 +2,9 @@ all: rm -f infinitylights g++ -lusb-1.0 main.cpp InfinityPortal.cpp SkylandersPortal.cpp -o infinitylights +lightshow: + rm -f lightshow + g++ -lusb-1.0 lightshow.cpp InfinityPortal.cpp SkylandersPortal.cpp -o lightshow clean: - rm -f infinitylights \ No newline at end of file + rm -f infinitylights lightshow \ No newline at end of file diff --git a/beat.php b/beat.php new file mode 100644 index 0000000..086ec59 --- /dev/null +++ b/beat.php @@ -0,0 +1,70 @@ + 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]; + } +} \ No newline at end of file diff --git a/lightshow b/lightshow new file mode 100755 index 0000000..2d07b3e Binary files /dev/null and b/lightshow differ diff --git a/lightshow.cpp b/lightshow.cpp new file mode 100644 index 0000000..7ed2e59 --- /dev/null +++ b/lightshow.cpp @@ -0,0 +1,122 @@ +/* + * File: main.cpp + * Author: christopher + * + * Created on 10 August 2014, 21:09 + */ + +#include +#include +#include +#include +#include +#include "libusb-1.0/libusb.h" +#include +#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; +} diff --git a/main.cpp b/main.cpp index b172633..35c1d6d 100644 --- a/main.cpp +++ b/main.cpp @@ -93,6 +93,8 @@ int main(int argc, char** argv) { if(j < skylanderPortalCount) { // printf("Doing %d\n",j); 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(); }