diff --git a/deploy/hidapi.dll b/deploy/hidapi.dll new file mode 100644 index 0000000..7b98d8d Binary files /dev/null and b/deploy/hidapi.dll differ diff --git a/src/DMX_Remake/DMX_Remake/DMX_Remake.vcxproj b/src/DMX_Remake/DMX_Remake/DMX_Remake.vcxproj index 794f1d8..4b99d28 100644 --- a/src/DMX_Remake/DMX_Remake/DMX_Remake.vcxproj +++ b/src/DMX_Remake/DMX_Remake/DMX_Remake.vcxproj @@ -38,13 +38,13 @@ DMX_Debug - ..\..\lib\allegro-4.4.2-msvc-10.0\include;..\..\lib\fmodapi375win\api\inc;..\..\lib\libpng\include\libpng12;..\..\lib\libpng\include;..\..\lib\loadpng;..\..\headers;..\..\lib\apeg\include;..\..\lib\pacdrive\include;$(IncludePath) - ..\..\lib\allegro-4.4.2-msvc-10.0\lib;..\..\lib\fmodapi375win\api\lib;..\..\lib\libpng\lib;..\..\lib\apeg\lib\release;..\..\lib\pacdrive\lib;$(LibraryPath) + ..\..\lib\allegro-4.4.2-msvc-10.0\include;..\..\lib\fmodapi375win\api\inc;..\..\lib\libpng\include\libpng12;..\..\lib\libpng\include;..\..\lib\loadpng;..\..\headers;..\..\lib\apeg\include;..\..\lib\pacdrive\include;..\..\lib\hidapi\include;$(IncludePath) + ..\..\lib\allegro-4.4.2-msvc-10.0\lib;..\..\lib\fmodapi375win\api\lib;..\..\lib\libpng\lib;..\..\lib\apeg\lib\release;..\..\lib\pacdrive\lib;..\..\lib\hidapi\lib;$(LibraryPath) DMX - ..\..\lib\allegro-4.4.2-msvc-10.0\include;..\..\lib\fmodapi375win\api\inc;..\..\lib\libpng\include\libpng12;..\..\lib\libpng\include;..\..\lib\loadpng;..\..\headers;..\..\lib\apeg\include;..\..\lib\pacdrive\include;$(IncludePath) - ..\..\lib\allegro-4.4.2-msvc-10.0\lib;..\..\lib\fmodapi375win\api\lib;..\..\lib\libpng\lib;..\..\lib\apeg\lib\release;..\..\lib\pacdrive\lib;$(LibraryPath) + ..\..\lib\allegro-4.4.2-msvc-10.0\include;..\..\lib\fmodapi375win\api\inc;..\..\lib\libpng\include\libpng12;..\..\lib\libpng\include;..\..\lib\loadpng;..\..\headers;..\..\lib\apeg\include;..\..\lib\pacdrive\include;..\..\lib\hidapi\include;$(IncludePath) + ..\..\lib\allegro-4.4.2-msvc-10.0\lib;..\..\lib\fmodapi375win\api\lib;..\..\lib\libpng\lib;..\..\lib\apeg\lib\release;..\..\lib\pacdrive\lib;..\..\lib\hidapi\lib;$(LibraryPath) @@ -55,7 +55,7 @@ true - allegro-4.4.2-mt.lib;loadpng-1.5-mt.lib;logg-1.0-mt.lib;zlib-1.2.5-static-mt.lib;fmodvc.lib;apeg_r.lib;ogg_static.lib;vorbis_static.lib;libtheora.lib;winmm.lib;urlmon.lib;%(AdditionalDependencies) + allegro-4.4.2-mt.lib;loadpng-1.5-mt.lib;logg-1.0-mt.lib;zlib-1.2.5-static-mt.lib;fmodvc.lib;apeg_r.lib;ogg_static.lib;vorbis_static.lib;libtheora.lib;winmm.lib;urlmon.lib;hidapi.lib;%(AdditionalDependencies) Windows @@ -78,7 +78,7 @@ true true true - allegro-4.4.2-mt.lib;loadpng-1.5-mt.lib;logg-1.0-mt.lib;zlib-1.2.5-static-mt.lib;fmodvc.lib;apeg_r.lib;ogg_static.lib;vorbis_static.lib;libtheora.lib;winmm.lib;urlmon.lib;%(AdditionalDependencies) + allegro-4.4.2-mt.lib;loadpng-1.5-mt.lib;logg-1.0-mt.lib;zlib-1.2.5-static-mt.lib;fmodvc.lib;apeg_r.lib;ogg_static.lib;vorbis_static.lib;libtheora.lib;winmm.lib;urlmon.lib;hidapi.lib;%(AdditionalDependencies) Windows false @@ -97,6 +97,7 @@ + @@ -121,6 +122,7 @@ + diff --git a/src/DMX_Remake/DMX_Remake/DMX_Remake.vcxproj.filters b/src/DMX_Remake/DMX_Remake/DMX_Remake.vcxproj.filters index c0bc2bc..47c09a0 100644 --- a/src/DMX_Remake/DMX_Remake/DMX_Remake.vcxproj.filters +++ b/src/DMX_Remake/DMX_Remake/DMX_Remake.vcxproj.filters @@ -66,6 +66,9 @@ Header Files + + Header Files + @@ -152,5 +155,8 @@ Source Files + + Source Files + \ No newline at end of file diff --git a/src/DMX_Remake/Debug/DMX_Debug.exp b/src/DMX_Remake/Debug/DMX_Debug.exp new file mode 100644 index 0000000..99e2ef1 Binary files /dev/null and b/src/DMX_Remake/Debug/DMX_Debug.exp differ diff --git a/src/DMX_Remake/Debug/DMX_Debug.lib b/src/DMX_Remake/Debug/DMX_Debug.lib new file mode 100644 index 0000000..70c2295 Binary files /dev/null and b/src/DMX_Remake/Debug/DMX_Debug.lib differ diff --git a/src/headers/minimaidManager.h b/src/headers/minimaidManager.h new file mode 100644 index 0000000..642bf7b --- /dev/null +++ b/src/headers/minimaidManager.h @@ -0,0 +1,43 @@ +// minimaidManager.h implements HID support for a certain custom IO board +// source file created by Allen Seitz 02/07/2016 + +#ifndef _MINIMAIDMANAGER_H_ +#define _MINIMAIDMANAGER_H_ + +#include "hidapi.h" + +#include "common.h" + +class minimaidManager +{ +public: + minimaidManager::minimaidManager(); + + void initialize(); + // precondition: called only once before the visible boot sequence begins + // postcondition: ready for updateInitialize() to begin + + bool updateInitialize(UTIME dt); + // precondition: called continuously during the boot loop, until the IO is ready + // postcondition: hopefully, eventualy, isReady() will return true + // returns: false when the software should give up on finding an IO board, true when it should continue to wait + + bool isReady(); + // returns: true when the initialization is complete and the hardware is fully usable + + void update(UTIME dt); + // precondition: isReady() (checked) or else this call will do nothing + // postcondition: updates the IO board, if necessary + + void updateLamps(); + // precondition: called only by the LightsManager whenever a lamp change happens, and not more than 20 times per second + // postcondition: a packet has been sent to the IO board + +private: + hid_device* handle; + + time_t powerOnTime; + time_t timeSinceLastLampUpdate; +}; + +#endif \ No newline at end of file diff --git a/src/hidapi-bsd.txt b/src/hidapi-bsd.txt new file mode 100644 index 0000000..809012a --- /dev/null +++ b/src/hidapi-bsd.txt @@ -0,0 +1,26 @@ +Copyright (c) 2010, Alan Ott, Signal 11 Software +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + * Neither the name of Signal 11 Software nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. \ No newline at end of file diff --git a/src/lib/hidapi/include/hidapi.h b/src/lib/hidapi/include/hidapi.h new file mode 100644 index 0000000..e5bc2dc --- /dev/null +++ b/src/lib/hidapi/include/hidapi.h @@ -0,0 +1,391 @@ +/******************************************************* + HIDAPI - Multi-Platform library for + communication with HID devices. + + Alan Ott + Signal 11 Software + + 8/22/2009 + + Copyright 2009, All Rights Reserved. + + At the discretion of the user of this library, + this software may be licensed under the terms of the + GNU General Public License v3, a BSD-Style license, or the + original HIDAPI license as outlined in the LICENSE.txt, + LICENSE-gpl3.txt, LICENSE-bsd.txt, and LICENSE-orig.txt + files located at the root of the source distribution. + These files may also be found in the public source + code repository located at: + http://github.com/signal11/hidapi . +********************************************************/ + +/** @file + * @defgroup API hidapi API + */ + +#ifndef HIDAPI_H__ +#define HIDAPI_H__ + +#include + +#ifdef _WIN32 + #define HID_API_EXPORT __declspec(dllexport) + #define HID_API_CALL +#else + #define HID_API_EXPORT /**< API export macro */ + #define HID_API_CALL /**< API call macro */ +#endif + +#define HID_API_EXPORT_CALL HID_API_EXPORT HID_API_CALL /**< API export and call macro*/ + +#ifdef __cplusplus +extern "C" { +#endif + struct hid_device_; + typedef struct hid_device_ hid_device; /**< opaque hidapi structure */ + + /** hidapi info structure */ + struct hid_device_info { + /** Platform-specific device path */ + char *path; + /** Device Vendor ID */ + unsigned short vendor_id; + /** Device Product ID */ + unsigned short product_id; + /** Serial Number */ + wchar_t *serial_number; + /** Device Release Number in binary-coded decimal, + also known as Device Version Number */ + unsigned short release_number; + /** Manufacturer String */ + wchar_t *manufacturer_string; + /** Product string */ + wchar_t *product_string; + /** Usage Page for this Device/Interface + (Windows/Mac only). */ + unsigned short usage_page; + /** Usage for this Device/Interface + (Windows/Mac only).*/ + unsigned short usage; + /** The USB interface which this logical device + represents. Valid on both Linux implementations + in all cases, and valid on the Windows implementation + only if the device contains more than one interface. */ + int interface_number; + + /** Pointer to the next device */ + struct hid_device_info *next; + }; + + + /** @brief Initialize the HIDAPI library. + + This function initializes the HIDAPI library. Calling it is not + strictly necessary, as it will be called automatically by + hid_enumerate() and any of the hid_open_*() functions if it is + needed. This function should be called at the beginning of + execution however, if there is a chance of HIDAPI handles + being opened by different threads simultaneously. + + @ingroup API + + @returns + This function returns 0 on success and -1 on error. + */ + int HID_API_EXPORT HID_API_CALL hid_init(void); + + /** @brief Finalize the HIDAPI library. + + This function frees all of the static data associated with + HIDAPI. It should be called at the end of execution to avoid + memory leaks. + + @ingroup API + + @returns + This function returns 0 on success and -1 on error. + */ + int HID_API_EXPORT HID_API_CALL hid_exit(void); + + /** @brief Enumerate the HID Devices. + + This function returns a linked list of all the HID devices + attached to the system which match vendor_id and product_id. + If @p vendor_id is set to 0 then any vendor matches. + If @p product_id is set to 0 then any product matches. + If @p vendor_id and @p product_id are both set to 0, then + all HID devices will be returned. + + @ingroup API + @param vendor_id The Vendor ID (VID) of the types of device + to open. + @param product_id The Product ID (PID) of the types of + device to open. + + @returns + This function returns a pointer to a linked list of type + struct #hid_device, containing information about the HID devices + attached to the system, or NULL in the case of failure. Free + this linked list by calling hid_free_enumeration(). + */ + struct hid_device_info HID_API_EXPORT * HID_API_CALL hid_enumerate(unsigned short vendor_id, unsigned short product_id); + + /** @brief Free an enumeration Linked List + + This function frees a linked list created by hid_enumerate(). + + @ingroup API + @param devs Pointer to a list of struct_device returned from + hid_enumerate(). + */ + void HID_API_EXPORT HID_API_CALL hid_free_enumeration(struct hid_device_info *devs); + + /** @brief Open a HID device using a Vendor ID (VID), Product ID + (PID) and optionally a serial number. + + If @p serial_number is NULL, the first device with the + specified VID and PID is opened. + + @ingroup API + @param vendor_id The Vendor ID (VID) of the device to open. + @param product_id The Product ID (PID) of the device to open. + @param serial_number The Serial Number of the device to open + (Optionally NULL). + + @returns + This function returns a pointer to a #hid_device object on + success or NULL on failure. + */ + HID_API_EXPORT hid_device * HID_API_CALL hid_open(unsigned short vendor_id, unsigned short product_id, const wchar_t *serial_number); + + /** @brief Open a HID device by its path name. + + The path name be determined by calling hid_enumerate(), or a + platform-specific path name can be used (eg: /dev/hidraw0 on + Linux). + + @ingroup API + @param path The path name of the device to open + + @returns + This function returns a pointer to a #hid_device object on + success or NULL on failure. + */ + HID_API_EXPORT hid_device * HID_API_CALL hid_open_path(const char *path); + + /** @brief Write an Output report to a HID device. + + The first byte of @p data[] must contain the Report ID. For + devices which only support a single report, this must be set + to 0x0. The remaining bytes contain the report data. Since + the Report ID is mandatory, calls to hid_write() will always + contain one more byte than the report contains. For example, + if a hid report is 16 bytes long, 17 bytes must be passed to + hid_write(), the Report ID (or 0x0, for devices with a + single report), followed by the report data (16 bytes). In + this example, the length passed in would be 17. + + hid_write() will send the data on the first OUT endpoint, if + one exists. If it does not, it will send the data through + the Control Endpoint (Endpoint 0). + + @ingroup API + @param device A device handle returned from hid_open(). + @param data The data to send, including the report number as + the first byte. + @param length The length in bytes of the data to send. + + @returns + This function returns the actual number of bytes written and + -1 on error. + */ + int HID_API_EXPORT HID_API_CALL hid_write(hid_device *device, const unsigned char *data, size_t length); + + /** @brief Read an Input report from a HID device with timeout. + + Input reports are returned + to the host through the INTERRUPT IN endpoint. The first byte will + contain the Report number if the device uses numbered reports. + + @ingroup API + @param device A device handle returned from hid_open(). + @param data A buffer to put the read data into. + @param length The number of bytes to read. For devices with + multiple reports, make sure to read an extra byte for + the report number. + @param milliseconds timeout in milliseconds or -1 for blocking wait. + + @returns + This function returns the actual number of bytes read and + -1 on error. If no packet was available to be read within + the timeout period, this function returns 0. + */ + int HID_API_EXPORT HID_API_CALL hid_read_timeout(hid_device *dev, unsigned char *data, size_t length, int milliseconds); + + /** @brief Read an Input report from a HID device. + + Input reports are returned + to the host through the INTERRUPT IN endpoint. The first byte will + contain the Report number if the device uses numbered reports. + + @ingroup API + @param device A device handle returned from hid_open(). + @param data A buffer to put the read data into. + @param length The number of bytes to read. For devices with + multiple reports, make sure to read an extra byte for + the report number. + + @returns + This function returns the actual number of bytes read and + -1 on error. If no packet was available to be read and + the handle is in non-blocking mode, this function returns 0. + */ + int HID_API_EXPORT HID_API_CALL hid_read(hid_device *device, unsigned char *data, size_t length); + + /** @brief Set the device handle to be non-blocking. + + In non-blocking mode calls to hid_read() will return + immediately with a value of 0 if there is no data to be + read. In blocking mode, hid_read() will wait (block) until + there is data to read before returning. + + Nonblocking can be turned on and off at any time. + + @ingroup API + @param device A device handle returned from hid_open(). + @param nonblock enable or not the nonblocking reads + - 1 to enable nonblocking + - 0 to disable nonblocking. + + @returns + This function returns 0 on success and -1 on error. + */ + int HID_API_EXPORT HID_API_CALL hid_set_nonblocking(hid_device *device, int nonblock); + + /** @brief Send a Feature report to the device. + + Feature reports are sent over the Control endpoint as a + Set_Report transfer. The first byte of @p data[] must + contain the Report ID. For devices which only support a + single report, this must be set to 0x0. The remaining bytes + contain the report data. Since the Report ID is mandatory, + calls to hid_send_feature_report() will always contain one + more byte than the report contains. For example, if a hid + report is 16 bytes long, 17 bytes must be passed to + hid_send_feature_report(): the Report ID (or 0x0, for + devices which do not use numbered reports), followed by the + report data (16 bytes). In this example, the length passed + in would be 17. + + @ingroup API + @param device A device handle returned from hid_open(). + @param data The data to send, including the report number as + the first byte. + @param length The length in bytes of the data to send, including + the report number. + + @returns + This function returns the actual number of bytes written and + -1 on error. + */ + int HID_API_EXPORT HID_API_CALL hid_send_feature_report(hid_device *device, const unsigned char *data, size_t length); + + /** @brief Get a feature report from a HID device. + + Set the first byte of @p data[] to the Report ID of the + report to be read. Make sure to allow space for this + extra byte in @p data[]. Upon return, the first byte will + still contain the Report ID, and the report data will + start in data[1]. + + @ingroup API + @param device A device handle returned from hid_open(). + @param data A buffer to put the read data into, including + the Report ID. Set the first byte of @p data[] to the + Report ID of the report to be read, or set it to zero + if your device does not use numbered reports. + @param length The number of bytes to read, including an + extra byte for the report ID. The buffer can be longer + than the actual report. + + @returns + This function returns the number of bytes read plus + one for the report ID (which is still in the first + byte), or -1 on error. + */ + int HID_API_EXPORT HID_API_CALL hid_get_feature_report(hid_device *device, unsigned char *data, size_t length); + + /** @brief Close a HID device. + + @ingroup API + @param device A device handle returned from hid_open(). + */ + void HID_API_EXPORT HID_API_CALL hid_close(hid_device *device); + + /** @brief Get The Manufacturer String from a HID device. + + @ingroup API + @param device A device handle returned from hid_open(). + @param string A wide string buffer to put the data into. + @param maxlen The length of the buffer in multiples of wchar_t. + + @returns + This function returns 0 on success and -1 on error. + */ + int HID_API_EXPORT_CALL hid_get_manufacturer_string(hid_device *device, wchar_t *string, size_t maxlen); + + /** @brief Get The Product String from a HID device. + + @ingroup API + @param device A device handle returned from hid_open(). + @param string A wide string buffer to put the data into. + @param maxlen The length of the buffer in multiples of wchar_t. + + @returns + This function returns 0 on success and -1 on error. + */ + int HID_API_EXPORT_CALL hid_get_product_string(hid_device *device, wchar_t *string, size_t maxlen); + + /** @brief Get The Serial Number String from a HID device. + + @ingroup API + @param device A device handle returned from hid_open(). + @param string A wide string buffer to put the data into. + @param maxlen The length of the buffer in multiples of wchar_t. + + @returns + This function returns 0 on success and -1 on error. + */ + int HID_API_EXPORT_CALL hid_get_serial_number_string(hid_device *device, wchar_t *string, size_t maxlen); + + /** @brief Get a string from a HID device, based on its string index. + + @ingroup API + @param device A device handle returned from hid_open(). + @param string_index The index of the string to get. + @param string A wide string buffer to put the data into. + @param maxlen The length of the buffer in multiples of wchar_t. + + @returns + This function returns 0 on success and -1 on error. + */ + int HID_API_EXPORT_CALL hid_get_indexed_string(hid_device *device, int string_index, wchar_t *string, size_t maxlen); + + /** @brief Get a string describing the last error which occurred. + + @ingroup API + @param device A device handle returned from hid_open(). + + @returns + This function returns a string containing the last error + which occurred or NULL if none has occurred. + */ + HID_API_EXPORT const wchar_t* HID_API_CALL hid_error(hid_device *device); + +#ifdef __cplusplus +} +#endif + +#endif + diff --git a/src/lib/hidapi/lib/hidapi.lib b/src/lib/hidapi/lib/hidapi.lib new file mode 100644 index 0000000..fb3a480 Binary files /dev/null and b/src/lib/hidapi/lib/hidapi.lib differ diff --git a/src/source/lightsManager.cpp b/src/source/lightsManager.cpp index 2ee7038..035d287 100644 --- a/src/source/lightsManager.cpp +++ b/src/source/lightsManager.cpp @@ -8,9 +8,11 @@ #include "lightsManager.h" #include "extioManager.h" #include "pacdriveManager.h" +#include "minimaidManager.h" extern extioManager extio; extern pacdriveManager pacio; +extern minimaidManager minimaidio; bool LightsManager::initialize() { @@ -55,6 +57,7 @@ void LightsManager::update(UTIME dt) // update the IO board, whichever one is plugged in extio.updateLamps(); pacio.updateLamps(); + minimaidio.updateLamps(); } void LightsManager::setLamp(PinACIO which, int milliseconds) diff --git a/src/source/main.cpp b/src/source/main.cpp index 81943f9..ff190d9 100644 --- a/src/source/main.cpp +++ b/src/source/main.cpp @@ -8,6 +8,8 @@ #include #include +#include "hidapi.h" + #include "common.h" #include "bookManager.h" #include "downloadManager.h" @@ -16,6 +18,7 @@ #include "gameStateManager.h" #include "lightsManager.h" #include "pacdriveManager.h" +#include "minimaidManager.h" #include "scoreManager.h" #include "videoManager.h" @@ -84,6 +87,7 @@ EffectsManager em; LightsManager lm; extioManager extio; pacdriveManager pacio; +minimaidManager minimaidio; DownloadManager dm; void firstSplashLoop(); @@ -245,6 +249,12 @@ int main() set_alpha_blender(); // the game assumes the graphics are left in this mode register_bitmap_file_type("png", load_png, NULL); + // initialize the HID (Human Interface Device) library, used by the minimaid IO board + if ( hid_init() == 0 ) + { + printf("Unable to initialize the HID library.\n"); + } + if ( fileExists("allsongs") ) { allsongsDebug = true; @@ -371,6 +381,7 @@ int main() vm.update(dt); lm.update(dt); extio.update(dt); + minimaidio.update(dt); if ( gs.g_gameModeTransition == 2 ) { @@ -588,6 +599,7 @@ int main() // clean up gs.killSong(); + hid_exit(); return EXIT_SUCCESS; } @@ -759,7 +771,7 @@ void renderCreditsDisplay() bool checkForUpdates() { bool startedDownload = true; - if ( !fileExists(MANIFEST_FILENAME) ) + if ( !fileExists(MANIFEST_FILENAME) ) // TODO: no don't use the cached one! redownload it every time! { dm.downloadFile(MANIFEST_FILENAME, MANIFEST_FILENAME); } @@ -1332,7 +1344,7 @@ void firstBootLoop() void mainBootLoop(UTIME dt) { - static char results[8][5] = { ".", "..", "...", "....", "OK", "BAD", "SKIP", "PAC" }; + static char results[9][5] = { ".", "..", "...", "....", "OK", "BAD", "SKIP", "PAC", "MINI" }; int dotdotdot = (bootStepTime / 333) % 3; // which board type to render? @@ -1345,6 +1357,10 @@ void mainBootLoop(UTIME dt) { boardType = 7; // "PAC" } + if ( minimaidio.isReady() ) + { + boardType = 8; // "MINI" + } bootStepTime += dt; if ( currentBootStep <= 2 ) @@ -1360,7 +1376,7 @@ void mainBootLoop(UTIME dt) if ( currentBootStep == 0 ) { - if ( extio.updateInitialize(dt) == false && pacio.updateInitialize(dt) == false ) + if ( extio.updateInitialize(dt) == false && pacio.updateInitialize(dt) == false && minimaidio.updateInitialize(dt) == false ) { textprintf(rm.m_backbuf, font, 154, 140, RED, results[5]); // hard fail bootStepTime = 0; @@ -1370,7 +1386,7 @@ void mainBootLoop(UTIME dt) { textprintf(rm.m_backbuf, font, 154, 140, WHITE, results[dotdotdot]); - if ( extio.isReady() || pacio.isReady() ) + if ( extio.isReady() || pacio.isReady() || minimaidio.isReady() ) { bootStepTime = 0; currentBootStep = 1; diff --git a/src/source/minimaidManager.cpp b/src/source/minimaidManager.cpp new file mode 100644 index 0000000..5df4ab7 --- /dev/null +++ b/src/source/minimaidManager.cpp @@ -0,0 +1,124 @@ +// minimaidManager.h implements HID support for a certain custom IO board +// source file created by Allen Seitz 02/07/2016 + +#include "minimaidManager.h" +#include "inputManager.h" +#include "lightsManager.h" + +extern InputManager im; +extern LightsManager lm; + +struct mm_input { + uint8_t report_id; + uint8_t dip_switches; + uint32_t jamma; + uint8_t ext_in; +}; + +struct mm_output { + uint8_t report_id; + uint8_t ext_output; + uint32_t lights; + uint8_t blue_led; + uint8_t kbd_enable; + uint8_t aux_flags; +}; + +// four molexes fit on the minimaid, each with up to 8 pins +// I guess the menu buttons just don't fit? +int minimaidLampOrder[32] = { + lampBlue0, lampRed0, lampBlue1, lampRed1, lampBlue0+1, lampRed0+1, lampBlue1+1, lampRed1+1, + lampBlue2a, lampBlue2b, lampRed2a, lampRed2b, lampBlue3a, lampRed3b, lampRed3a, lampRed3b, + lampBlue2a+1, lampBlue2b+1, lampRed2a+1, lampRed2b+1, lampBlue3a+1, lampRed3b+1, lampRed3a+1, lampRed3b+1, + spotlightA, spotlightB, spotlightC, NULL, NULL, NULL, NULL, NULL +}; + +minimaidManager::minimaidManager() +{ + handle = NULL; + powerOnTime = 0; + timeSinceLastLampUpdate = 0; +} + +void minimaidManager::initialize() +{ + wchar_t wstr[256]; + + // Open the device using the VID, PID, and optionally the Serial number. + handle = hid_open(0x5730, 0x0000, NULL); + + // Read the Manufacturer String - sample code, not used for anything + int res = hid_get_manufacturer_string(handle, wstr, 256); + wprintf(L"Manufacturer String: %s\n", wstr); + + // Read the Product String - sample code, not used for anything + res = hid_get_product_string(handle, wstr, 256); + wprintf(L"Product String: %s\n", wstr); + + // Read the Serial Number String - sample code, not used for anything + res = hid_get_serial_number_string(handle, wstr, 256); + wprintf(L"Serial Number String: (%d) %s\n", wstr[0], wstr); +} + +bool minimaidManager::updateInitialize(UTIME dt) +{ + // easy. if initialize didn't find it right away, then it's not plugged in + if ( handle == NULL ) + { + return false; + } + return true; +} + +bool minimaidManager::isReady() +{ + return handle != NULL; +} + +void minimaidManager::update(UTIME dt) +{ + if ( !isReady() ) + { + return; + } + powerOnTime += dt; + timeSinceLastLampUpdate += dt; + + // read input from the hid +} + +void minimaidManager::updateLamps() +{ + char b0 = 0, b1 = 0, b2 = 0; + + if ( timeSinceLastLampUpdate < 20 ) + { + //al_trace("--STIFLED LAMP UPDATE-- too soon of an update.\r\n"); + return; // don't do that + } + timeSinceLastLampUpdate = 0; + + // prepare the output structure - I'm not sure what most of thse do to be honest + struct mm_output out; + out.report_id = 0; + out.ext_output = 0; + out.blue_led = 0; + out.aux_flags = 0; + out.kbd_enable = 0; // might be a good idea to see what the bindings are, and if that would be easier? + out.lights = 0; // set in the next code block + + for ( int i = 0; i < 32; i++ ) + { + if ( minimaidLampOrder[i] != 0 ) + { + out.lights |= lm.getLamp(minimaidLampOrder[i]) ? 1 << i : 0; + } + } + + al_trace("LAMP %d\n", out.lights); + + // move the mm_output struct into an array of chars for hid_write + unsigned char outstream[128]; + memcpy_s(&outstream, 128, &out, sizeof(mm_output)); + hid_write(handle, outstream, sizeof(mm_output)); +} \ No newline at end of file