An I/O controller for virtual pinball machines: accelerometer nudge sensing, analog plunger input, button input encoding, LedWiz compatible output controls, and more.

Dependencies:   mbed FastIO FastPWM USBDevice

Fork of Pinscape_Controller by Mike R

/media/uploads/mjr/pinscape_no_background_small_L7Miwr6.jpg

This is Version 2 of the Pinscape Controller, an I/O controller for virtual pinball machines. (You can find the old version 1 software here.) Pinscape is software for the KL25Z that turns the board into a full-featured I/O controller for virtual pinball, with support for accelerometer-based nudging, a mechanical plunger, button inputs, and feedback device control.

In case you haven't heard of the idea before, a "virtual pinball machine" is basically a video pinball simulator that's built into a real pinball machine body. A TV monitor goes in place of the pinball playfield, and a second TV goes in the backbox to show the backglass artwork. Some cabs also include a third monitor to simulate the DMD (Dot Matrix Display) used for scoring on 1990s machines, or even an original plasma DMD. A computer (usually a Windows PC) is hidden inside the cabinet, running pinball emulation software that displays a life-sized playfield on the main TV. The cabinet has all of the usual buttons, too, so it not only looks like the real thing, but plays like it too. That's a picture of my own machine to the right. On the outside, it's built exactly like a real arcade pinball machine, with the same overall dimensions and all of the standard pinball cabinet trim hardware.

It's possible to buy a pre-built virtual pinball machine, but it also makes a great DIY project. If you have some basic wood-working skills and know your way around PCs, you can build one from scratch. The computer part is just an ordinary Windows PC, and all of the pinball emulation can be built out of free, open-source software. In that spirit, the Pinscape Controller is an open-source software/hardware project that offers a no-compromises, all-in-one control center for all of the unique input/output needs of a virtual pinball cabinet. If you've been thinking about building one of these, but you're not sure how to connect a plunger, flipper buttons, lights, nudge sensor, and whatever else you can think of, this project might be just what you're looking for.

You can find much more information about DIY Pin Cab building in general in the Virtual Cabinet Forum on vpforums.org. Also visit my Pinscape Resources page for more about this project and other virtual pinball projects I'm working on.

Downloads

  • Pinscape Release Builds: This page has download links for all of the Pinscape software. To get started, install and run the Pinscape Config Tool on your Windows computer. It will lead you through the steps for installing the Pinscape firmware on the KL25Z.
  • Config Tool Source Code. The complete C# source code for the config tool. You don't need this to run the tool, but it's available if you want to customize anything or see how it works inside.

Documentation

The new Version 2 Build Guide is now complete! This new version aims to be a complete guide to building a virtual pinball machine, including not only the Pinscape elements but all of the basics, from sourcing parts to building all of the hardware.

You can also refer to the original Hardware Build Guide (PDF), but that's out of date now, since it refers to the old version 1 software, which was rather different (especially when it comes to configuration).

System Requirements

The new Config Tool requires a fairly up-to-date Microsoft .NET installation. If you use Windows Update to keep your system current, you should be fine. A modern version of Internet Explorer (IE) is required, even if you don't use it as your main browser, because the Config Tool uses some system components that Microsoft packages into the IE install set. I test with IE11, so that's known to work. IE8 doesn't work. IE9 and 10 are unknown at this point.

The Windows requirements are only for the config tool. The firmware doesn't care about anything on the Windows side, so if you can make do without the config tool, you can use almost any Windows setup.

Main Features

Plunger: The Pinscape Controller started out as a "mechanical plunger" controller: a device for attaching a real pinball plunger to the video game software so that you could launch the ball the natural way. This is still, of course, a central feature of the project. The software supports several types of sensors: a high-resolution optical sensor (which works by essentially taking pictures of the plunger as it moves); a slide potentiometer (which determines the position via the changing electrical resistance in the pot); a quadrature sensor (which counts bars printed on a special guide rail that it moves along); and an IR distance sensor (which determines the position by sending pulses of light at the plunger and measuring the round-trip travel time). The Build Guide explains how to set up each type of sensor.

Nudging: The KL25Z (the little microcontroller that the software runs on) has a built-in accelerometer. The Pinscape software uses it to sense when you nudge the cabinet, and feeds the acceleration data to the pinball software on the PC. This turns physical nudges into virtual English on the ball. The accelerometer is quite sensitive and accurate, so we can measure the difference between little bumps and hard shoves, and everything in between. The result is natural and immersive.

Buttons: You can wire real pinball buttons to the KL25Z, and the software will translate the buttons into PC input. You have the option to map each button to a keyboard key or joystick button. You can wire up your flipper buttons, Magna Save buttons, Start button, coin slots, operator buttons, and whatever else you need.

Feedback devices: You can also attach "feedback devices" to the KL25Z. Feedback devices are things that create tactile, sound, and lighting effects in sync with the game action. The most popular PC pinball emulators know how to address a wide variety of these devices, and know how to match them to on-screen action in each virtual table. You just need an I/O controller that translates commands from the PC into electrical signals that turn the devices on and off. The Pinscape Controller can do that for you.

Expansion Boards

There are two main ways to run the Pinscape Controller: standalone, or using the "expansion boards".

In the basic standalone setup, you just need the KL25Z, plus whatever buttons, sensors, and feedback devices you want to attach to it. This mode lets you take advantage of everything the software can do, but for some features, you'll have to build some ad hoc external circuitry to interface external devices with the KL25Z. The Build Guide has detailed plans for exactly what you need to build.

The other option is the Pinscape Expansion Boards. The expansion boards are a companion project, which is also totally free and open-source, that provides Printed Circuit Board (PCB) layouts that are designed specifically to work with the Pinscape software. The PCB designs are in the widely used EAGLE format, which many PCB manufacturers can turn directly into physical boards for you. The expansion boards organize all of the external connections more neatly than on the standalone KL25Z, and they add all of the interface circuitry needed for all of the advanced software functions. The big thing they bring to the table is lots of high-power outputs. The boards provide a modular system that lets you add boards to add more outputs. If you opt for the basic core setup, you'll have enough outputs for all of the toys in a really well-equipped cabinet. If your ambitions go beyond merely well-equipped and run to the ridiculously extravagant, just add an extra board or two. The modular design also means that you can add to the system over time.

Expansion Board project page

Update notes

If you have a Pinscape V1 setup already installed, you should be able to switch to the new version pretty seamlessly. There are just a couple of things to be aware of.

First, the "configuration" procedure is completely different in the new version. Way better and way easier, but it's not what you're used to from V1. In V1, you had to edit the project source code and compile your own custom version of the program. No more! With V2, you simply install the standard, pre-compiled .bin file, and select options using the Pinscape Config Tool on Windows.

Second, if you're using the TSL1410R optical sensor for your plunger, there's a chance you'll need to boost your light source's brightness a little bit. The "shutter speed" is faster in this version, which means that it doesn't spend as much time collecting light per frame as before. The software actually does "auto exposure" adaptation on every frame, so the increased shutter speed really shouldn't bother it, but it does require a certain minimum level of contrast, which requires a certain minimal level of lighting. Check the plunger viewer in the setup tool if you have any problems; if the image looks totally dark, try increasing the light level to see if that helps.

New Features

V2 has numerous new features. Here are some of the highlights...

Dynamic configuration: as explained above, configuration is now handled through the Config Tool on Windows. It's no longer necessary to edit the source code or compile your own modified binary.

Improved plunger sensing: the software now reads the TSL1410R optical sensor about 15x faster than it did before. This allows reading the sensor at full resolution (400dpi), about 400 times per second. The faster frame rate makes a big difference in how accurately we can read the plunger position during the fast motion of a release, which allows for more precise position sensing and faster response. The differences aren't dramatic, since the sensing was already pretty good even with the slower V1 scan rate, but you might notice a little better precision in tricky skill shots.

Keyboard keys: button inputs can now be mapped to keyboard keys. The joystick button option is still available as well, of course. Keyboard keys have the advantage of being closer to universal for PC pinball software: some pinball software can be set up to take joystick input, but nearly all PC pinball emulators can take keyboard input, and nearly all of them use the same key mappings.

Local shift button: one physical button can be designed as the local shift button. This works like a Shift button on a keyboard, but with cabinet buttons. It allows each physical button on the cabinet to have two PC keys assigned, one normal and one shifted. Hold down the local shift button, then press another key, and the other key's shifted key mapping is sent to the PC. The shift button can have a regular key mapping of its own as well, so it can do double duty. The shift feature lets you access more functions without cluttering your cabinet with extra buttons. It's especially nice for less frequently used functions like adjusting the volume or activating night mode.

Night mode: the output controller has a new "night mode" option, which lets you turn off all of your noisy devices with a single button, switch, or PC command. You can designate individual ports as noisy or not. Night mode only disables the noisemakers, so you still get the benefit of your flashers, button lights, and other quiet devices. This lets you play late into the night without disturbing your housemates or neighbors.

Gamma correction: you can designate individual output ports for gamma correction. This adjusts the intensity level of an output to make it match the way the human eye perceives brightness, so that fades and color mixes look more natural in lighting devices. You can apply this to individual ports, so that it only affects ports that actually have lights of some kind attached.

IR Remote Control: the controller software can transmit and/or receive IR remote control commands if you attach appropriate parts (an IR LED to send, an IR sensor chip to receive). This can be used to turn on your TV(s) when the system powers on, if they don't turn on automatically, and for any other functions you can think of requiring IR send/receive capabilities. You can assign IR commands to cabinet buttons, so that pressing a button on your cabinet sends a remote control command from the attached IR LED, and you can have the controller generate virtual key presses on your PC in response to received IR commands. If you have the IR sensor attached, the system can use it to learn commands from your existing remotes.

Yet more USB fixes: I've been gradually finding and fixing USB bugs in the mbed library for months now. This version has all of the fixes of the last couple of releases, of course, plus some new ones. It also has a new "last resort" feature, since there always seems to be "just one more" USB bug. The last resort is that you can tell the device to automatically reboot itself if it loses the USB connection and can't restore it within a given time limit.

More Downloads

  • Custom VP builds: I created modified versions of Visual Pinball 9.9 and Physmod5 that you might want to use in combination with this controller. The modified versions have special handling for plunger calibration specific to the Pinscape Controller, as well as some enhancements to the nudge physics. If you're not using the plunger, you might still want it for the nudge improvements. The modified version also works with any other input controller, so you can get the enhanced nudging effects even if you're using a different plunger/nudge kit. The big change in the modified versions is a "filter" for accelerometer input that's designed to make the response to cabinet nudges more realistic. It also makes the response more subdued than in the standard VP, so it's not to everyone's taste. The downloads include both the updated executables and the source code changes, in case you want to merge the changes into your own custom version(s).

    Note! These features are now standard in the official VP releases, so you don't need my custom builds if you're using 9.9.1 or later and/or VP 10. I don't think there's any reason to use my versions instead of the latest official ones, and in fact I'd encourage you to use the official releases since they're more up to date, but I'm leaving my builds available just in case. In the official versions, look for the checkbox "Enable Nudge Filter" in the Keys preferences dialog. My custom versions don't include that checkbox; they just enable the filter unconditionally.
  • Output circuit shopping list: This is a saved shopping cart at mouser.com with the parts needed to build one copy of the high-power output circuit for the LedWiz emulator feature, for use with the standalone KL25Z (that is, without the expansion boards). The quantities in the cart are for one output channel, so if you want N outputs, simply multiply the quantities by the N, with one exception: you only need one ULN2803 transistor array chip for each eight output circuits. If you're using the expansion boards, you won't need any of this, since the boards provide their own high-power outputs.
  • Cary Owens' optical sensor housing: A 3D-printable design for a housing/mounting bracket for the optical plunger sensor, designed by Cary Owens. This makes it easy to mount the sensor.
  • Lemming77's potentiometer mounting bracket and shooter rod connecter: Sketchup designs for 3D-printable parts for mounting a slide potentiometer as the plunger sensor. These were designed for a particular slide potentiometer that used to be available from an Aliexpress.com seller but is no longer listed. You can probably use this design as a starting point for other similar devices; just check the dimensions before committing the design to plastic.

Copyright and License

The Pinscape firmware is copyright 2014, 2021 by Michael J Roberts. It's released under an MIT open-source license. See License.

Warning to VirtuaPin Kit Owners

This software isn't designed as a replacement for the VirtuaPin plunger kit's firmware. If you bought the VirtuaPin kit, I recommend that you don't install this software. The KL25Z can only run one firmware program at a time, so if you install the Pinscape firmware on your KL25Z, it will replace and erase your existing VirtuaPin proprietary firmware. If you do this, the only way to restore your VirtuaPin firmware is to physically ship the KL25Z back to VirtuaPin and ask them to re-flash it. They don't allow you to do this at home, and they don't even allow you to back up your firmware, since they want to protect their proprietary software from copying. For all of these reasons, if you want to run the Pinscape software, I strongly recommend that you buy a "blank" retail KL25Z to use with Pinscape. They only cost about $15 and are available at several online retailers, including Amazon, Mouser, and eBay. The blank retail boards don't come with any proprietary firmware pre-installed, so installing Pinscape won't delete anything that you paid extra for.

With those warnings in mind, if you're absolutely sure that you don't mind permanently erasing your VirtuaPin firmware, it is at least possible to use Pinscape as a replacement for the VirtuaPin firmware. Pinscape uses the same button wiring conventions as the VirtuaPin setup, so you can keep your buttons (although you'll have to update the GPIO pin mappings in the Config Tool to match your physical wiring). As of the June, 2021 firmware, the Vishay VCNL4010 plunger sensor that comes with the VirtuaPin v3 plunger kit is supported, so you can also keep your plunger, if you have that chip. (You should check to be sure that's the sensor chip you have before committing to this route, if keeping the plunger sensor is important to you. The older VirtuaPin plunger kits came with different IR sensors that the Pinscape software doesn't handle.)

Committer:
mjr
Date:
Thu Dec 14 00:20:20 2017 +0000
Revision:
92:f264fbaa1be5
Parent:
91:ae9be42652bf
Child:
98:4df3c0f7e707
Adjustable joystick report timing

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mjr 35:e959ffba78fd 1 // USB Message Protocol
mjr 35:e959ffba78fd 2 //
mjr 74:822a92bc11d2 3 // This file is purely for documentation, to describe our USB protocol
mjr 74:822a92bc11d2 4 // for incoming messages (host to device). We use the standard HID setup
mjr 74:822a92bc11d2 5 // with one endpoint in each direction. See USBJoystick.cpp and .h for
mjr 74:822a92bc11d2 6 // the USB descriptors.
mjr 74:822a92bc11d2 7 //
mjr 74:822a92bc11d2 8 // Our incoming message protocol is an extended version of the protocol
mjr 74:822a92bc11d2 9 // used by the LedWiz. Our protocol is designed to be 100% backwards
mjr 74:822a92bc11d2 10 // compatible with clients using the original LedWiz wire protocol, as long
mjr 74:822a92bc11d2 11 // as they only send well-formed messages in the original protocol. The
mjr 74:822a92bc11d2 12 // "well-formed" part is an important condition, because our extensions to
mjr 74:822a92bc11d2 13 // the original protocol all consist of messages that aren't defined in the
mjr 74:822a92bc11d2 14 // original protocol and are meaningless to a real LedWiz.
mjr 35:e959ffba78fd 15 //
mjr 74:822a92bc11d2 16 // The protocol compatibility ensures that all original LedWiz clients can
mjr 74:822a92bc11d2 17 // also transparently access a Pinscape unit. Clients will simply think the
mjr 74:822a92bc11d2 18 // Pinscape unit is an LedWiz, thus they'll be able to operate 32 of our
mjr 74:822a92bc11d2 19 // ports. We designate the first 32 ports (ports 1-32) as the ones accessible
mjr 74:822a92bc11d2 20 // through the LedWiz protocol.
mjr 74:822a92bc11d2 21 //
mjr 74:822a92bc11d2 22 // In addition the wire-level protocol compatibility, we can provide legacy
mjr 74:822a92bc11d2 23 // LedWiz clients with access to more than 32 ports by emulating multiple
mjr 74:822a92bc11d2 24 // virtual LedWiz units. We can't do this across the wire protocol, since
mjr 74:822a92bc11d2 25 // the KL25Z USB interface constrains us to a single VID/PID (which is how
mjr 74:822a92bc11d2 26 // LedWiz clients distinguish units). However, virtuall all legacy LedWiz
mjr 74:822a92bc11d2 27 // clients access the device through a shared library, LEDWIZ.DLL, rather
mjr 74:822a92bc11d2 28 // than directly through USB. LEDWIZ.DLL is distributed by the LedWiz's
mjr 74:822a92bc11d2 29 // manufacturer and has a published client interface. We can thus provide
mjr 74:822a92bc11d2 30 // a replacement DLL that contains the logic needed to recognize a Pinscape
mjr 74:822a92bc11d2 31 // unit and represent it to clients as multiple LedWiz devices. This allows
mjr 74:822a92bc11d2 32 // old clients to access our full complement of ports without any changes
mjr 74:822a92bc11d2 33 // to the clients. We define some extended message types (SBX and PBX)
mjr 74:822a92bc11d2 34 // specifically to support this DLL feature.
mjr 74:822a92bc11d2 35 //
mjr 74:822a92bc11d2 36
mjr 35:e959ffba78fd 37
mjr 35:e959ffba78fd 38 // ------ OUTGOING MESSAGES (DEVICE TO HOST) ------
mjr 35:e959ffba78fd 39 //
mjr 47:df7a88cd249c 40 // General note: 16-bit and 32-bit fields in our reports are little-endian
mjr 47:df7a88cd249c 41 // unless otherwise specified.
mjr 47:df7a88cd249c 42 //
mjr 39:b3815a1c3802 43 // 1. Joystick reports
mjr 35:e959ffba78fd 44 // In most cases, our outgoing messages are HID joystick reports, using the
mjr 35:e959ffba78fd 45 // format defined in USBJoystick.cpp. This allows us to be installed on
mjr 35:e959ffba78fd 46 // Windows as a standard USB joystick, which all versions of Windows support
mjr 35:e959ffba78fd 47 // using in-the-box drivers. This allows a completely transparent, driverless,
mjr 39:b3815a1c3802 48 // plug-and-play installation experience on Windows. Our joystick report
mjr 39:b3815a1c3802 49 // looks like this (see USBJoystick.cpp for the formal HID report descriptor):
mjr 35:e959ffba78fd 50 //
mjr 55:4db125cd11a0 51 // ss status bits:
mjr 55:4db125cd11a0 52 // 0x01 -> plunger enabled
mjr 55:4db125cd11a0 53 // 0x02 -> night mode engaged
mjr 73:4e8ce0b18915 54 // 0x04,0x08,0x10 -> power sense status: meaningful only when
mjr 73:4e8ce0b18915 55 // the TV-on timer is used. Figure (ss>>2) & 0x07 to
mjr 73:4e8ce0b18915 56 // isolate the status bits. The resulting value is:
mjr 73:4e8ce0b18915 57 // 1 -> latch was on at last check
mjr 73:4e8ce0b18915 58 // 2 -> latch was off at last check, SET pin high
mjr 73:4e8ce0b18915 59 // 3 -> latch off, SET pin low, ready to check status
mjr 73:4e8ce0b18915 60 // 4 -> TV timer countdown in progress
mjr 73:4e8ce0b18915 61 // 5 -> TV relay is on
mjr 77:0b96f6867312 62 // 6 -> sending IR signals designated as TV ON signals
mjr 77:0b96f6867312 63 // 0x20 -> IR learning mode in progress
mjr 79:682ae3171a08 64 // 0x40 -> configuration saved successfully (see below)
mjr 40:cc0d9814522b 65 // 00 2nd byte of status (reserved)
mjr 40:cc0d9814522b 66 // 00 3rd byte of status (reserved)
mjr 39:b3815a1c3802 67 // 00 always zero for joystick reports
mjr 40:cc0d9814522b 68 // bb joystick buttons, low byte (buttons 1-8, 1 bit per button)
mjr 40:cc0d9814522b 69 // bb joystick buttons, 2nd byte (buttons 9-16)
mjr 40:cc0d9814522b 70 // bb joystick buttons, 3rd byte (buttons 17-24)
mjr 40:cc0d9814522b 71 // bb joystick buttons, high byte (buttons 25-32)
mjr 39:b3815a1c3802 72 // xx low byte of X position = nudge/accelerometer X axis
mjr 39:b3815a1c3802 73 // xx high byte of X position
mjr 39:b3815a1c3802 74 // yy low byte of Y position = nudge/accelerometer Y axis
mjr 39:b3815a1c3802 75 // yy high byte of Y position
mjr 39:b3815a1c3802 76 // zz low byte of Z position = plunger position
mjr 39:b3815a1c3802 77 // zz high byte of Z position
mjr 39:b3815a1c3802 78 //
mjr 39:b3815a1c3802 79 // The X, Y, and Z values are 16-bit signed integers. The accelerometer
mjr 39:b3815a1c3802 80 // values are on an abstract scale, where 0 represents no acceleration,
mjr 39:b3815a1c3802 81 // negative maximum represents -1g on that axis, and positive maximum
mjr 39:b3815a1c3802 82 // represents +1g on that axis. For the plunger position, 0 is the park
mjr 39:b3815a1c3802 83 // position (the rest position of the plunger) and positive values represent
mjr 39:b3815a1c3802 84 // retracted (pulled back) positions. A negative value means that the plunger
mjr 39:b3815a1c3802 85 // is pushed forward of the park position.
mjr 39:b3815a1c3802 86 //
mjr 79:682ae3171a08 87 // Status bit 0x40 is set after a successful configuration update via special
mjr 79:682ae3171a08 88 // command 65 6 (save config to flash). The device always reboots after this
mjr 79:682ae3171a08 89 // command, so if the host wants to receive a status update verifying the
mjr 79:682ae3171a08 90 // save, it has to request a non-zero reboot delay in the message to allow
mjr 79:682ae3171a08 91 // us time to send at least one of these status reports after the save.
mjr 79:682ae3171a08 92 // This bit is only sent after a successful save, which means that the flash
mjr 79:682ae3171a08 93 // write succeeded and the written sectors verified as correct.
mjr 82:4f6209cb5c33 94 // NOTE: older firmware versions didn't support this status bit, so clients
mjr 82:4f6209cb5c33 95 // can't interpret the lack of a response as a failure for older versions.
mjr 82:4f6209cb5c33 96 // To determine if the flag is supported, check the config report feature
mjr 82:4f6209cb5c33 97 // flags.
mjr 82:4f6209cb5c33 98 //
mjr 79:682ae3171a08 99 //
mjr 39:b3815a1c3802 100 // 2. Special reports
mjr 35:e959ffba78fd 101 // We subvert the joystick report format in certain cases to report other
mjr 35:e959ffba78fd 102 // types of information, when specifically requested by the host. This allows
mjr 35:e959ffba78fd 103 // our custom configuration UI on the Windows side to query additional
mjr 35:e959ffba78fd 104 // information that we don't normally send via the joystick reports. We
mjr 35:e959ffba78fd 105 // define a custom vendor-specific "status" field in the reports that we
mjr 35:e959ffba78fd 106 // use to identify these special reports, as described below.
mjr 35:e959ffba78fd 107 //
mjr 39:b3815a1c3802 108 // Normal joystick reports always have 0 in the high bit of the 2nd byte
mjr 35:e959ffba78fd 109 // of the report. Special non-joystick reports always have 1 in the high bit
mjr 35:e959ffba78fd 110 // of the first byte. (This byte is defined in the HID Report Descriptor
mjr 35:e959ffba78fd 111 // as an opaque vendor-defined value, so the joystick interface on the
mjr 35:e959ffba78fd 112 // Windows side simply ignores it.)
mjr 35:e959ffba78fd 113 //
mjr 52:8298b2a73eb2 114 // 2A. Plunger sensor status report
mjr 52:8298b2a73eb2 115 // Software on the PC can request a detailed status report from the plunger
mjr 52:8298b2a73eb2 116 // sensor. The status information is meant as an aid to installing and
mjr 52:8298b2a73eb2 117 // adjusting the sensor device for proper performance. For imaging sensor
mjr 52:8298b2a73eb2 118 // types, the status report includes a complete current image snapshot
mjr 52:8298b2a73eb2 119 // (an array of all of the pixels the sensor is currently imaging). For
mjr 52:8298b2a73eb2 120 // all sensor types, it includes the current plunger position registered
mjr 52:8298b2a73eb2 121 // on the sensor, and some timing information.
mjr 52:8298b2a73eb2 122 //
mjr 52:8298b2a73eb2 123 // To request the sensor status, the host sends custom protocol message 65 3
mjr 52:8298b2a73eb2 124 // (see below). The device replies with a message in this format:
mjr 52:8298b2a73eb2 125 //
mjr 52:8298b2a73eb2 126 // bytes 0:1 = 0x87FF
mjr 86:e30a1f60f783 127 // byte 2 = 0 -> first status report packet
mjr 52:8298b2a73eb2 128 // bytes 3:4 = number of pixels to be sent in following messages, as
mjr 52:8298b2a73eb2 129 // an unsigned 16-bit little-endian integer. This is 0 if
mjr 52:8298b2a73eb2 130 // the sensor isn't an imaging type.
mjr 86:e30a1f60f783 131 // bytes 5:6 = current plunger position registered on the sensor. This
mjr 86:e30a1f60f783 132 // is on the *native* scale for the sensor, which might be
mjr 86:e30a1f60f783 133 // different from joystick units. By default, the native
mjr 86:e30a1f60f783 134 // scale is the number of pixels for an imaging sensor, or
mjr 86:e30a1f60f783 135 // 4096 for other sensor types. The actual native scale can
mjr 86:e30a1f60f783 136 // be reported separately via a second status report message
mjr 86:e30a1f60f783 137 // (see below).
mjr 52:8298b2a73eb2 138 // byte 7 = bit flags:
mjr 52:8298b2a73eb2 139 // 0x01 = normal orientation detected
mjr 52:8298b2a73eb2 140 // 0x02 = reversed orientation detected
mjr 52:8298b2a73eb2 141 // 0x04 = calibration mode is active (no pixel packets
mjr 52:8298b2a73eb2 142 // are sent for this reading)
mjr 52:8298b2a73eb2 143 // bytes 8:9:10 = average time for each sensor read, in 10us units.
mjr 52:8298b2a73eb2 144 // This is the average time it takes to complete the I/O
mjr 52:8298b2a73eb2 145 // operation to read the sensor, to obtain the raw sensor
mjr 52:8298b2a73eb2 146 // data for instantaneous plunger position reading. For
mjr 52:8298b2a73eb2 147 // an imaging sensor, this is the time it takes for the
mjr 52:8298b2a73eb2 148 // sensor to capture the image and transfer it to the
mjr 52:8298b2a73eb2 149 // microcontroller. For an analog sensor (e.g., an LVDT
mjr 52:8298b2a73eb2 150 // or potentiometer), it's the time to complete an ADC
mjr 52:8298b2a73eb2 151 // sample.
mjr 52:8298b2a73eb2 152 // bytes 11:12:13 = time it took to process the current frame, in 10us
mjr 52:8298b2a73eb2 153 // units. This is the software processing time that was
mjr 52:8298b2a73eb2 154 // needed to analyze the raw data read from the sensor.
mjr 52:8298b2a73eb2 155 // This is typically only non-zero for imaging sensors,
mjr 52:8298b2a73eb2 156 // where it reflects the time required to scan the pixel
mjr 52:8298b2a73eb2 157 // array to find the indicated plunger position. The time
mjr 52:8298b2a73eb2 158 // is usually zero or negligible for analog sensor types,
mjr 52:8298b2a73eb2 159 // since the only "analysis" is a multiplication to rescale
mjr 52:8298b2a73eb2 160 // the ADC sample.
mjr 52:8298b2a73eb2 161 //
mjr 86:e30a1f60f783 162 // An optional second message provides additional information:
mjr 86:e30a1f60f783 163 //
mjr 86:e30a1f60f783 164 // bytes 0:1 = 0x87FF
mjr 86:e30a1f60f783 165 // byte 2 = 1 -> second status report packet
mjr 86:e30a1f60f783 166 // bytes 3:4 = Native sensor scale. This is the actual native scale
mjr 86:e30a1f60f783 167 // used for the position report in the first status report
mjr 86:e30a1f60f783 168 // packet above.
mjr 86:e30a1f60f783 169 // bytes 5:6 = Jitter window lower bound, in native sensor scale units.
mjr 86:e30a1f60f783 170 // bytes 7:8 = Jitter window upper bound, in native sensor scale units.
mjr 86:e30a1f60f783 171 // The jitter window bounds reflect the current jitter filter
mjr 86:e30a1f60f783 172 // status as of this reading.
mjr 86:e30a1f60f783 173 // bytes 9:10 = Raw sensor reading before jitter filter was applied.
mjr 86:e30a1f60f783 174 // bytes 11:12 = Auto-exposure time in microseconds
mjr 87:8d35c74403af 175 //
mjr 87:8d35c74403af 176 // An optional third message provides additional information specifically
mjr 87:8d35c74403af 177 // for bar-code sensors:
mjr 87:8d35c74403af 178 //
mjr 87:8d35c74403af 179 // bytes 0:1 = 0x87FF
mjr 87:8d35c74403af 180 // byte 2 = 2 -> bar code status report
mjr 87:8d35c74403af 181 // byte 3 = number of bits in bar code
mjr 87:8d35c74403af 182 // byte 4 = bar code type:
mjr 87:8d35c74403af 183 // 1 = Gray code/Manchester bit coding
mjr 87:8d35c74403af 184 // bytes 5:6 = pixel offset of first bit
mjr 87:8d35c74403af 185 // byte 7 = width in pixels of each bit
mjr 87:8d35c74403af 186 // bytes 8:9 = raw bar code bits
mjr 87:8d35c74403af 187 // bytes 10:11 = mask of successfully read bar code bits; a '1' bit means
mjr 87:8d35c74403af 188 // that the bit was read successfully, '0' means the bit was
mjr 87:8d35c74403af 189 // unreadable
mjr 86:e30a1f60f783 190 //
mjr 86:e30a1f60f783 191 //
mjr 52:8298b2a73eb2 192 // If the sensor is an imaging sensor type, this will be followed by a
mjr 52:8298b2a73eb2 193 // series of pixel messages. The imaging sensor types have too many pixels
mjr 52:8298b2a73eb2 194 // to send in a single USB transaction, so the device breaks up the array
mjr 52:8298b2a73eb2 195 // into as many packets as needed and sends them in sequence. For non-
mjr 52:8298b2a73eb2 196 // imaging sensors, the "number of pixels" field in the lead packet is
mjr 52:8298b2a73eb2 197 // zero, so obviously no pixel packets will follow. If the "calibration
mjr 52:8298b2a73eb2 198 // active" bit in the flags byte is set, no pixel packets are sent even
mjr 52:8298b2a73eb2 199 // if the sensor is an imaging type, since the transmission time for the
mjr 87:8d35c74403af 200 // pixels would interfere with the calibration process. If pixels are sent,
mjr 52:8298b2a73eb2 201 // they're sent in order starting at the first pixel. The format of each
mjr 52:8298b2a73eb2 202 // pixel packet is:
mjr 35:e959ffba78fd 203 //
mjr 35:e959ffba78fd 204 // bytes 0:1 = 11-bit index, with high 5 bits set to 10000. For
mjr 48:058ace2aed1d 205 // example, 0x8004 (encoded little endian as 0x04 0x80)
mjr 48:058ace2aed1d 206 // indicates index 4. This is the starting pixel number
mjr 48:058ace2aed1d 207 // in the report. The first report will be 0x00 0x80 to
mjr 48:058ace2aed1d 208 // indicate pixel #0.
mjr 47:df7a88cd249c 209 // bytes 2 = 8-bit unsigned int brightness level of pixel at index
mjr 47:df7a88cd249c 210 // bytes 3 = brightness of pixel at index+1
mjr 35:e959ffba78fd 211 // etc for the rest of the packet
mjr 35:e959ffba78fd 212 //
mjr 52:8298b2a73eb2 213 // Note that we currently only support one-dimensional imaging sensors
mjr 52:8298b2a73eb2 214 // (i.e., pixel arrays that are 1 pixel wide). The report format doesn't
mjr 52:8298b2a73eb2 215 // have any provision for a two-dimensional layout. The KL25Z probably
mjr 52:8298b2a73eb2 216 // isn't powerful enough to do real-time image analysis on a 2D image
mjr 52:8298b2a73eb2 217 // anyway, so it's unlikely that we'd be able to make 2D sensors work at
mjr 52:8298b2a73eb2 218 // all, but if we ever add such a thing we'll have to upgrade the report
mjr 52:8298b2a73eb2 219 // format here accordingly.
mjr 51:57eb311faafa 220 //
mjr 51:57eb311faafa 221 //
mjr 53:9b2611964afc 222 // 2B. Configuration report.
mjr 39:b3815a1c3802 223 // This is requested by sending custom protocol message 65 4 (see below).
mjr 39:b3815a1c3802 224 // In reponse, the device sends one report to the host using this format:
mjr 35:e959ffba78fd 225 //
mjr 35:e959ffba78fd 226 // bytes 0:1 = 0x8800. This has the bit pattern 10001 in the high
mjr 35:e959ffba78fd 227 // 5 bits, which distinguishes it from regular joystick
mjr 40:cc0d9814522b 228 // reports and from other special report types.
mjr 74:822a92bc11d2 229 // bytes 2:3 = total number of configured outputs, little endian. This
mjr 74:822a92bc11d2 230 // is the number of outputs with assigned functions in the
mjr 74:822a92bc11d2 231 // active configuration.
mjr 75:677892300e7a 232 // byte 4 = Pinscape unit number (0-15), little endian
mjr 75:677892300e7a 233 // byte 5 = reserved (currently always zero)
mjr 40:cc0d9814522b 234 // bytes 6:7 = plunger calibration zero point, little endian
mjr 40:cc0d9814522b 235 // bytes 8:9 = plunger calibration maximum point, little endian
mjr 52:8298b2a73eb2 236 // byte 10 = plunger calibration release time, in milliseconds
mjr 52:8298b2a73eb2 237 // byte 11 = bit flags:
mjr 40:cc0d9814522b 238 // 0x01 -> configuration loaded; 0 in this bit means that
mjr 40:cc0d9814522b 239 // the firmware has been loaded but no configuration
mjr 40:cc0d9814522b 240 // has been sent from the host
mjr 74:822a92bc11d2 241 // 0x02 -> SBX/PBX extension features: 1 in this bit means
mjr 74:822a92bc11d2 242 // that these features are present in this version.
mjr 78:1e00b3fa11af 243 // 0x04 -> new accelerometer features supported (adjustable
mjr 78:1e00b3fa11af 244 // dynamic range, auto-centering on/off, adjustable
mjr 78:1e00b3fa11af 245 // auto-centering time)
mjr 82:4f6209cb5c33 246 // 0x08 -> flash write status flag supported (see flag 0x40
mjr 82:4f6209cb5c33 247 // in normal joystick status report)
mjr 92:f264fbaa1be5 248 // 0x10 -> joystick report timing features supports
mjr 92:f264fbaa1be5 249 // (configurable joystick report interval, acceler-
mjr 92:f264fbaa1be5 250 // ometer stutter counter)
mjr 73:4e8ce0b18915 251 // bytes 12:13 = available RAM, in bytes, little endian. This is the amount
mjr 73:4e8ce0b18915 252 // of unused heap (malloc'able) memory. The firmware generally
mjr 73:4e8ce0b18915 253 // allocates all of the dynamic memory it needs during startup,
mjr 73:4e8ce0b18915 254 // so the free memory figure doesn't tend to fluctuate during
mjr 73:4e8ce0b18915 255 // normal operation. The dynamic memory used is a function of
mjr 73:4e8ce0b18915 256 // the set of features enabled.
mjr 35:e959ffba78fd 257 //
mjr 53:9b2611964afc 258 // 2C. Device ID report.
mjr 40:cc0d9814522b 259 // This is requested by sending custom protocol message 65 7 (see below).
mjr 40:cc0d9814522b 260 // In response, the device sends one report to the host using this format:
mjr 40:cc0d9814522b 261 //
mjr 52:8298b2a73eb2 262 // bytes 0:1 = 0x9000. This has bit pattern 10010 in the high 5 bits
mjr 52:8298b2a73eb2 263 // to distinguish this from other report types.
mjr 53:9b2611964afc 264 // byte 2 = ID type. This is the same ID type sent in the request.
mjr 53:9b2611964afc 265 // bytes 3-12 = requested ID. The ID is 80 bits in big-endian byte
mjr 53:9b2611964afc 266 // order. For IDs longer than 80 bits, we truncate to the
mjr 53:9b2611964afc 267 // low-order 80 bits (that is, the last 80 bits).
mjr 53:9b2611964afc 268 //
mjr 53:9b2611964afc 269 // ID type 1 = CPU ID. This is the globally unique CPU ID
mjr 53:9b2611964afc 270 // stored in the KL25Z CPU.
mjr 35:e959ffba78fd 271 //
mjr 53:9b2611964afc 272 // ID type 2 = OpenSDA ID. This is the globally unique ID
mjr 53:9b2611964afc 273 // for the connected OpenSDA controller, if known. This
mjr 53:9b2611964afc 274 // allow the host to figure out which USB MSD (virtual
mjr 53:9b2611964afc 275 // disk drive), if any, represents the OpenSDA module for
mjr 53:9b2611964afc 276 // this Pinscape USB interface. This is primarily useful
mjr 53:9b2611964afc 277 // to determine which MSD to write in order to update the
mjr 53:9b2611964afc 278 // firmware on a given Pinscape unit.
mjr 53:9b2611964afc 279 //
mjr 53:9b2611964afc 280 // 2D. Configuration variable report.
mjr 52:8298b2a73eb2 281 // This is requested by sending custom protocol message 65 9 (see below).
mjr 52:8298b2a73eb2 282 // In response, the device sends one report to the host using this format:
mjr 52:8298b2a73eb2 283 //
mjr 52:8298b2a73eb2 284 // bytes 0:1 = 0x9800. This has bit pattern 10011 in the high 5 bits
mjr 52:8298b2a73eb2 285 // to distinguish this from other report types.
mjr 52:8298b2a73eb2 286 // byte 2 = Variable ID. This is the same variable ID sent in the
mjr 52:8298b2a73eb2 287 // query message, to relate the reply to the request.
mjr 52:8298b2a73eb2 288 // bytes 3-8 = Current value of the variable, in the format for the
mjr 52:8298b2a73eb2 289 // individual variable type. The variable formats are
mjr 52:8298b2a73eb2 290 // described in the CONFIGURATION VARIABLES section below.
mjr 52:8298b2a73eb2 291 //
mjr 53:9b2611964afc 292 // 2E. Software build information report.
mjr 53:9b2611964afc 293 // This is requested by sending custom protocol message 65 10 (see below).
mjr 53:9b2611964afc 294 // In response, the device sends one report using this format:
mjr 53:9b2611964afc 295 //
mjr 73:4e8ce0b18915 296 // bytes 0:1 = 0xA000. This has bit pattern 10100 in the high 5 bits
mjr 77:0b96f6867312 297 // (and 10100000 in the high 8 bits) to distinguish it from
mjr 77:0b96f6867312 298 // other report types.
mjr 53:9b2611964afc 299 // bytes 2:5 = Build date. This is returned as a 32-bit integer,
mjr 53:9b2611964afc 300 // little-endian as usual, encoding a decimal value
mjr 53:9b2611964afc 301 // in the format YYYYMMDD giving the date of the build.
mjr 53:9b2611964afc 302 // E.g., Feb 16 2016 is encoded as 20160216 (decimal).
mjr 53:9b2611964afc 303 // bytes 6:9 = Build time. This is a 32-bit integer, little-endian,
mjr 53:9b2611964afc 304 // encoding a decimal value in the format HHMMSS giving
mjr 53:9b2611964afc 305 // build time on a 24-hour clock.
mjr 53:9b2611964afc 306 //
mjr 73:4e8ce0b18915 307 // 2F. Button status report.
mjr 73:4e8ce0b18915 308 // This is requested by sending custom protocol message 65 13 (see below).
mjr 73:4e8ce0b18915 309 // In response, the device sends one report using this format:
mjr 73:4e8ce0b18915 310 //
mjr 77:0b96f6867312 311 // bytes 0:1 = 0xA1. This has bit pattern 10100 in the high 5 bits (and
mjr 77:0b96f6867312 312 // 10100001 in the high 8 bits) to distinguish it from other
mjr 77:0b96f6867312 313 // report types.
mjr 73:4e8ce0b18915 314 // byte 2 = number of button reports
mjr 73:4e8ce0b18915 315 // byte 3 = Physical status of buttons 1-8, 1 bit each. The low-order
mjr 73:4e8ce0b18915 316 // bit (0x01) is button 1. Each bit is 0 if the button is off,
mjr 73:4e8ce0b18915 317 // 1 if on. This reflects the physical status of the button
mjr 73:4e8ce0b18915 318 // input pins, after debouncing but before any logical state
mjr 73:4e8ce0b18915 319 // processing. Pulse mode and shifting have no effect on the
mjr 73:4e8ce0b18915 320 // physical state; this simply indicates whether the button is
mjr 73:4e8ce0b18915 321 // electrically on (shorted to GND) or off (open circuit).
mjr 73:4e8ce0b18915 322 // byte 4 = buttons 9-16
mjr 73:4e8ce0b18915 323 // byte 5 = buttons 17-24
mjr 73:4e8ce0b18915 324 // byte 6 = buttons 25-32
mjr 73:4e8ce0b18915 325 // byte 7 = buttons 33-40
mjr 73:4e8ce0b18915 326 // byte 8 = buttons 41-48
mjr 73:4e8ce0b18915 327 //
mjr 77:0b96f6867312 328 // 2G. IR sensor data report.
mjr 77:0b96f6867312 329 // This is requested by sending custom protocol message 65 12 (see below).
mjr 77:0b96f6867312 330 // That command puts controller in IR learning mode for a short time, during
mjr 77:0b96f6867312 331 // which it monitors the IR sensor and send these special reports to relay the
mjr 77:0b96f6867312 332 // readings. The reports contain the raw data, plus the decoded command code
mjr 77:0b96f6867312 333 // and protocol information if the controller is able to recognize and decode
mjr 77:0b96f6867312 334 // the command.
mjr 52:8298b2a73eb2 335 //
mjr 77:0b96f6867312 336 // bytes 0:1 = 0xA2. This has bit pattern 10100 in the high 5 bits (and
mjr 77:0b96f6867312 337 // 10100010 in the high 8 bits to distinguish it from other
mjr 77:0b96f6867312 338 // report types.
mjr 77:0b96f6867312 339 // byte 2 = number of raw reports that follow
mjr 77:0b96f6867312 340 // bytes 3:4 = first raw report, as a little-endian 16-bit int. The
mjr 77:0b96f6867312 341 // value represents the time of an IR "space" or "mark" in
mjr 77:0b96f6867312 342 // 2us units. The low bit is 0 for a space and 1 for a mark.
mjr 77:0b96f6867312 343 // To recover the time in microseconds, mask our the low bit
mjr 77:0b96f6867312 344 // and multiply the result by 2. Received codes always
mjr 77:0b96f6867312 345 // alternate between spaces and marks. A space is an interval
mjr 77:0b96f6867312 346 // where the IR is off, and a mark is an interval with IR on.
mjr 77:0b96f6867312 347 // If the value is 0xFFFE (after masking out the low bit), it
mjr 77:0b96f6867312 348 // represents a timeout, that is, a time greater than or equal
mjr 77:0b96f6867312 349 // to the maximum that can be represented in this format,
mjr 77:0b96f6867312 350 // which is 131068us. None of the IR codes we can parse have
mjr 77:0b96f6867312 351 // any internal signal component this long, so a timeout value
mjr 77:0b96f6867312 352 // is generally seen only during a gap between codes where
mjr 77:0b96f6867312 353 // nothing is being transmitted.
mjr 77:0b96f6867312 354 // bytes 4:5 = second raw report
mjr 77:0b96f6867312 355 // (etc for remaining reports)
mjr 77:0b96f6867312 356 //
mjr 77:0b96f6867312 357 // If byte 2 is 0x00, it indicates that learning mode has expired without
mjr 77:0b96f6867312 358 // a code being received, so it's the last report sent for the learning
mjr 77:0b96f6867312 359 // session.
mjr 77:0b96f6867312 360 //
mjr 77:0b96f6867312 361 // If byte 2 is 0xFF, it indicates that a code has been successfully
mjr 77:0b96f6867312 362 // learned. The rest of the report contains the learned code instead
mjr 77:0b96f6867312 363 // of the raw data:
mjr 77:0b96f6867312 364 //
mjr 77:0b96f6867312 365 // byte 3 = protocol ID, which is an integer giving an internal code
mjr 77:0b96f6867312 366 // identifying the IR protocol that was recognized for the
mjr 77:0b96f6867312 367 // received data. See IRProtocolID.h for a list of the IDs.
mjr 77:0b96f6867312 368 // byte 4 = bit flags:
mjr 77:0b96f6867312 369 // 0x02 -> the protocol uses "dittos"
mjr 77:0b96f6867312 370 // bytes 5:6:7:8:9:10:11:12 = a little-endian 64-bit int containing
mjr 77:0b96f6867312 371 // the code received. The code is essentially the data payload
mjr 77:0b96f6867312 372 // of the IR packet, after removing bits that are purely
mjr 77:0b96f6867312 373 // structural, such as toggle bits and error correction bits.
mjr 77:0b96f6867312 374 // The mapping between the IR bit stream and our 64-bit is
mjr 77:0b96f6867312 375 // essentially arbitrary and varies by protocol, but it always
mjr 77:0b96f6867312 376 // has round-trip fidelity: using the 64-bit code value +
mjr 77:0b96f6867312 377 // protocol ID + flags to send an IR command will result in
mjr 77:0b96f6867312 378 // the same IR bit sequence being sent, modulo structural bits
mjr 77:0b96f6867312 379 // that need to be updates in the reconstruction (such as toggle
mjr 77:0b96f6867312 380 // bits or sequencing codes).
mjr 77:0b96f6867312 381 //
mjr 77:0b96f6867312 382 //
mjr 77:0b96f6867312 383 // WHY WE USE A HACKY APPROACH TO DIFFERENT REPORT TYPES
mjr 35:e959ffba78fd 384 //
mjr 35:e959ffba78fd 385 // The HID report system was specifically designed to provide a clean,
mjr 35:e959ffba78fd 386 // structured way for devices to describe the data they send to the host.
mjr 35:e959ffba78fd 387 // Our approach isn't clean or structured; it ignores the promises we
mjr 35:e959ffba78fd 388 // make about the contents of our report via the HID Report Descriptor
mjr 35:e959ffba78fd 389 // and stuffs our own different data format into the same structure.
mjr 35:e959ffba78fd 390 //
mjr 77:0b96f6867312 391 // We use this hacky approach only because we can't use the standard USB
mjr 77:0b96f6867312 392 // HID mechanism for varying report types, which is to provide multiple
mjr 77:0b96f6867312 393 // report descriptors and tag each report with a type byte that indicates
mjr 77:0b96f6867312 394 // which descriptor applies. We can't use that standard approach because
mjr 77:0b96f6867312 395 // we want to be 100% LedWiz compatible. The snag is that some Windows
mjr 77:0b96f6867312 396 // LedWiz clients parse the USB HID descriptors as part of identifying a
mjr 77:0b96f6867312 397 // USB HID device as a valid LedWiz unit, and will only recognize the device
mjr 77:0b96f6867312 398 // if certain properties of the HID descriptors match those of a real LedWiz.
mjr 77:0b96f6867312 399 // One of the features that's important to some clients is the descriptor
mjr 77:0b96f6867312 400 // link structure, which is affected by the layout of HID Report Descriptor
mjr 77:0b96f6867312 401 // entries. In order to match the expected layout, we can only define a
mjr 77:0b96f6867312 402 // single kind of output report. Since we have to use Joystick reports for
mjr 77:0b96f6867312 403 // the sake of VP and other pinball software, and we're only allowed the
mjr 77:0b96f6867312 404 // one report type, we have to make that one report type the Joystick type.
mjr 77:0b96f6867312 405 // That's why we overload the joystick reports with other meanings. It's a
mjr 77:0b96f6867312 406 // hack, but at least it's a fairly reliable and isolated hack, in that our
mjr 77:0b96f6867312 407 // special reports are only generated when clients specifically ask for
mjr 77:0b96f6867312 408 // them. Plus, even if a client who doesn't ask for a special report
mjr 77:0b96f6867312 409 // somehow gets one, the worst that happens is that they get a momentary
mjr 77:0b96f6867312 410 // spurious reading from the accelerometer and plunger.
mjr 35:e959ffba78fd 411
mjr 35:e959ffba78fd 412
mjr 35:e959ffba78fd 413
mjr 35:e959ffba78fd 414 // ------- INCOMING MESSAGES (HOST TO DEVICE) -------
mjr 35:e959ffba78fd 415 //
mjr 35:e959ffba78fd 416 // For LedWiz compatibility, our incoming message format conforms to the
mjr 35:e959ffba78fd 417 // basic USB format used by real LedWiz units. This is simply 8 data
mjr 35:e959ffba78fd 418 // bytes, all private vendor-specific values (meaning that the Windows HID
mjr 35:e959ffba78fd 419 // driver treats them as opaque and doesn't attempt to parse them).
mjr 35:e959ffba78fd 420 //
mjr 35:e959ffba78fd 421 // Within this basic 8-byte format, we recognize the full protocol used
mjr 35:e959ffba78fd 422 // by real LedWiz units, plus an extended protocol that we define privately.
mjr 35:e959ffba78fd 423 // The LedWiz protocol leaves a large part of the potential protocol space
mjr 35:e959ffba78fd 424 // undefined, so we take advantage of this undefined region for our
mjr 35:e959ffba78fd 425 // extensions. This ensures that we can properly recognize all messages
mjr 35:e959ffba78fd 426 // intended for a real LedWiz unit, as well as messages from custom host
mjr 35:e959ffba78fd 427 // software that knows it's talking to a Pinscape unit.
mjr 35:e959ffba78fd 428
mjr 35:e959ffba78fd 429 // --- REAL LED WIZ MESSAGES ---
mjr 35:e959ffba78fd 430 //
mjr 74:822a92bc11d2 431 // The real LedWiz protocol has two message types, "SBA" and "PBA". The
mjr 74:822a92bc11d2 432 // message type can be determined from the first byte of the 8-byte message
mjr 74:822a92bc11d2 433 // packet: if the first byte 64 (0x40), it's an SBA message. If the first
mjr 74:822a92bc11d2 434 // byte is 0-49 or 129-132, it's a PBA message. All other byte values are
mjr 74:822a92bc11d2 435 // invalid in the original protocol and have undefined behavior if sent to
mjr 74:822a92bc11d2 436 // a real LedWiz. We take advantage of this to extend the protocol with
mjr 74:822a92bc11d2 437 // our new features by assigning new meanings to byte patterns that have no
mjr 74:822a92bc11d2 438 // meaning in the original protocol.
mjr 35:e959ffba78fd 439 //
mjr 74:822a92bc11d2 440 // "SBA" message: 64 xx xx xx xx ss 00 00
mjr 74:822a92bc11d2 441 // xx = on/off bit mask for 8 outputs
mjr 74:822a92bc11d2 442 // ss = global flash speed setting (valid values 1-7)
mjr 74:822a92bc11d2 443 // 00 = unused/reserved; client should set to zero (not enforced, but
mjr 74:822a92bc11d2 444 // strongly recommended in case of future additions)
mjr 35:e959ffba78fd 445 //
mjr 35:e959ffba78fd 446 // If the first byte has value 64 (0x40), it's an SBA message. This type of
mjr 35:e959ffba78fd 447 // message sets all 32 outputs individually ON or OFF according to the next
mjr 35:e959ffba78fd 448 // 32 bits (4 bytes) of the message, and sets the flash speed to the value in
mjr 74:822a92bc11d2 449 // the sixth byte. The flash speed sets the global cycle rate for flashing
mjr 74:822a92bc11d2 450 // outputs - outputs with their values set to the range 128-132. The speed
mjr 74:822a92bc11d2 451 // parameter is in ad hoc units that aren't documented in the LedWiz API, but
mjr 74:822a92bc11d2 452 // observations of real LedWiz units show that the "speed" is actually the
mjr 74:822a92bc11d2 453 // period, each unit representing 0.25s: so speed 1 is a 0.25s period, or 4Hz,
mjr 74:822a92bc11d2 454 // speed 2 is a 0.5s period or 2Hz, etc., up to speed 7 as a 1.75s period or
mjr 74:822a92bc11d2 455 // 0.57Hz. The period is the full waveform cycle time.
mjr 74:822a92bc11d2 456 //
mjr 35:e959ffba78fd 457 //
mjr 74:822a92bc11d2 458 // "PBA" message: bb bb bb bb bb bb bb bb
mjr 74:822a92bc11d2 459 // bb = brightness level, 0-49 or 128-132
mjr 35:e959ffba78fd 460 //
mjr 74:822a92bc11d2 461 // Note that there's no prefix byte indicating this message type. This
mjr 74:822a92bc11d2 462 // message is indicated simply by the first byte being in one of the valid
mjr 74:822a92bc11d2 463 // ranges.
mjr 74:822a92bc11d2 464 //
mjr 74:822a92bc11d2 465 // Each byte gives the new brightness level or flash pattern for one part.
mjr 74:822a92bc11d2 466 // The valid values are:
mjr 35:e959ffba78fd 467 //
mjr 35:e959ffba78fd 468 // 0-48 = fixed brightness level, linearly from 0% to 100% intensity
mjr 35:e959ffba78fd 469 // 49 = fixed brightness level at 100% intensity (same as 48)
mjr 35:e959ffba78fd 470 // 129 = flashing pattern, fade up / fade down (sawtooth wave)
mjr 35:e959ffba78fd 471 // 130 = flashing pattern, on / off (square wave)
mjr 35:e959ffba78fd 472 // 131 = flashing pattern, on for 50% duty cycle / fade down
mjr 35:e959ffba78fd 473 // 132 = flashing pattern, fade up / on for 50% duty cycle
mjr 35:e959ffba78fd 474 //
mjr 74:822a92bc11d2 475 // This message sets new brightness/flash settings for 8 ports. There's
mjr 74:822a92bc11d2 476 // no port number specified in the message; instead, the port is given by
mjr 74:822a92bc11d2 477 // the protocol state. Specifically, the device has an internal register
mjr 74:822a92bc11d2 478 // containing the base port for PBA messages. On reset AND after any SBA
mjr 74:822a92bc11d2 479 // message is received, the base port is set to 0. After any PBA message
mjr 74:822a92bc11d2 480 // is received and processed, the base port is incremented by 8, resetting
mjr 74:822a92bc11d2 481 // to 0 when it reaches 32. The bytes of the message set the brightness
mjr 74:822a92bc11d2 482 // levels for the base port, base port + 1, ..., base port + 7 respectively.
mjr 35:e959ffba78fd 483 //
mjr 74:822a92bc11d2 484 //
mjr 35:e959ffba78fd 485
mjr 35:e959ffba78fd 486 // --- PRIVATE EXTENDED MESSAGES ---
mjr 35:e959ffba78fd 487 //
mjr 35:e959ffba78fd 488 // All of our extended protocol messages are identified by the first byte:
mjr 35:e959ffba78fd 489 //
mjr 35:e959ffba78fd 490 // 65 -> Miscellaneous control message. The second byte specifies the specific
mjr 35:e959ffba78fd 491 // operation:
mjr 35:e959ffba78fd 492 //
mjr 39:b3815a1c3802 493 // 0 -> No Op - does nothing. (This can be used to send a test message on the
mjr 39:b3815a1c3802 494 // USB endpoint.)
mjr 39:b3815a1c3802 495 //
mjr 88:98bce687e6c0 496 // 1 -> Set the device's LedWiz unit number and plunger status, and save the
mjr 88:98bce687e6c0 497 // changes to flash. The device automatically reboots after the changes
mjr 88:98bce687e6c0 498 // are saved if the unit number is changed, since this changes the USB
mjr 88:98bce687e6c0 499 // product ID code. The additional bytes of the message give the
mjr 88:98bce687e6c0 500 // parameters:
mjr 35:e959ffba78fd 501 //
mjr 88:98bce687e6c0 502 // third byte = new LedWiz unit number (0-15, corresponding to nominal
mjr 88:98bce687e6c0 503 // LedWiz unit numbers 1-16)
mjr 35:e959ffba78fd 504 // fourth byte = plunger on/off (0=disabled, 1=enabled)
mjr 35:e959ffba78fd 505 //
mjr 88:98bce687e6c0 506 // Note that this command is from the original version and isn't typically
mjr 88:98bce687e6c0 507 // used any more, since the same information has been subsumed into more
mjr 88:98bce687e6c0 508 // generalized option settings via the config variable system.
mjr 88:98bce687e6c0 509 //
mjr 35:e959ffba78fd 510 // 2 -> Begin plunger calibration mode. The device stays in this mode for about
mjr 35:e959ffba78fd 511 // 15 seconds, and sets the zero point and maximum retraction points to the
mjr 35:e959ffba78fd 512 // observed endpoints of sensor readings while the mode is running. After
mjr 35:e959ffba78fd 513 // the time limit elapses, the device automatically stores the results in
mjr 35:e959ffba78fd 514 // non-volatile flash memory and exits the mode.
mjr 35:e959ffba78fd 515 //
mjr 51:57eb311faafa 516 // 3 -> Send pixel dump. The device sends one complete image snapshot from the
mjr 51:57eb311faafa 517 // plunger sensor, as as series of pixel dump messages. (The message format
mjr 51:57eb311faafa 518 // isn't big enough to allow the whole image to be sent in one message, so
mjr 53:9b2611964afc 519 // the image is broken up into as many messages as necessary.) The device
mjr 53:9b2611964afc 520 // then resumes sending normal joystick messages. If the plunger sensor
mjr 53:9b2611964afc 521 // isn't an imaging type, or no sensor is installed, no pixel messages are
mjr 53:9b2611964afc 522 // sent. Parameters:
mjr 48:058ace2aed1d 523 //
mjr 48:058ace2aed1d 524 // third byte = bit flags:
mjr 51:57eb311faafa 525 // 0x01 = low res mode. The device rescales the sensor pixel array
mjr 51:57eb311faafa 526 // sent in the dump messages to a low-resolution subset. The
mjr 51:57eb311faafa 527 // size of the subset is determined by the device. This has
mjr 51:57eb311faafa 528 // no effect on the sensor operation; it merely reduces the
mjr 51:57eb311faafa 529 // USB transmission time to allow for a faster frame rate for
mjr 51:57eb311faafa 530 // viewing in the config tool.
mjr 35:e959ffba78fd 531 //
mjr 53:9b2611964afc 532 // fourth byte = extra exposure time in 100us (.1ms) increments. For
mjr 53:9b2611964afc 533 // imaging sensors, we'll add this delay to the minimum exposure
mjr 53:9b2611964afc 534 // time. This allows the caller to explicitly adjust the exposure
mjr 53:9b2611964afc 535 // level for calibration purposes.
mjr 53:9b2611964afc 536 //
mjr 35:e959ffba78fd 537 // 4 -> Query configuration. The device sends a special configuration report,
mjr 40:cc0d9814522b 538 // (see above; see also USBJoystick.cpp), then resumes sending normal
mjr 40:cc0d9814522b 539 // joystick reports.
mjr 35:e959ffba78fd 540 //
mjr 74:822a92bc11d2 541 // 5 -> Turn all outputs off and restore LedWiz defaults. Sets all output
mjr 74:822a92bc11d2 542 // ports to OFF and LedWiz brightness/mode setting 48, and sets the LedWiz
mjr 74:822a92bc11d2 543 // global flash speed to 2.
mjr 35:e959ffba78fd 544 //
mjr 35:e959ffba78fd 545 // 6 -> Save configuration to flash. This saves all variable updates sent via
mjr 85:3c28aee81cde 546 // type 66 messages since the last reboot, then optionally reboots the
mjr 82:4f6209cb5c33 547 // device to put the changes into effect. If the flash write succeeds,
mjr 82:4f6209cb5c33 548 // we set the "flash write OK" bit in our status reports, which we
mjr 82:4f6209cb5c33 549 // continue sending between the successful write and the delayed reboot.
mjr 85:3c28aee81cde 550 // We don't set the bit or reboot if the write fails. If the "do not
mjr 85:3c28aee81cde 551 // reboot" flag is set, we still set the flag on success for the delay
mjr 85:3c28aee81cde 552 // time, then clear the flag.
mjr 35:e959ffba78fd 553 //
mjr 53:9b2611964afc 554 // third byte = delay time in seconds. The device will wait this long
mjr 82:4f6209cb5c33 555 // before disconnecting, to allow the PC to test for the success bit
mjr 82:4f6209cb5c33 556 // in the status report, and to perform any cleanup tasks while the
mjr 82:4f6209cb5c33 557 // device is still attached (e.g., modifying Windows device driver
mjr 82:4f6209cb5c33 558 // settings)
mjr 53:9b2611964afc 559 //
mjr 85:3c28aee81cde 560 // fourth byte = flags:
mjr 85:3c28aee81cde 561 // 0x01 -> do not reboot
mjr 85:3c28aee81cde 562 //
mjr 40:cc0d9814522b 563 // 7 -> Query device ID. The device replies with a special device ID report
mjr 40:cc0d9814522b 564 // (see above; see also USBJoystick.cpp), then resumes sending normal
mjr 40:cc0d9814522b 565 // joystick reports.
mjr 40:cc0d9814522b 566 //
mjr 53:9b2611964afc 567 // The third byte of the message is the ID index to retrieve:
mjr 53:9b2611964afc 568 //
mjr 53:9b2611964afc 569 // 1 = CPU ID: returns the KL25Z globally unique CPU ID.
mjr 53:9b2611964afc 570 //
mjr 53:9b2611964afc 571 // 2 = OpenSDA ID: returns the OpenSDA TUID. This must be patched
mjr 53:9b2611964afc 572 // into the firmware by the PC host when the .bin file is
mjr 53:9b2611964afc 573 // installed onto the device. This will return all 'X' bytes
mjr 53:9b2611964afc 574 // if the value wasn't patched at install time.
mjr 53:9b2611964afc 575 //
mjr 40:cc0d9814522b 576 // 8 -> Engage/disengage night mode. The third byte of the message is 1 to
mjr 55:4db125cd11a0 577 // engage night mode, 0 to disengage night mode. The current mode isn't
mjr 55:4db125cd11a0 578 // stored persistently; night mode is always off after a reset.
mjr 40:cc0d9814522b 579 //
mjr 52:8298b2a73eb2 580 // 9 -> Query configuration variable. The second byte is the config variable
mjr 52:8298b2a73eb2 581 // number (see the CONFIGURATION VARIABLES section below). For the array
mjr 52:8298b2a73eb2 582 // variables (button assignments, output ports), the third byte is the
mjr 52:8298b2a73eb2 583 // array index. The device replies with a configuration variable report
mjr 52:8298b2a73eb2 584 // (see above) with the current setting for the requested variable.
mjr 52:8298b2a73eb2 585 //
mjr 53:9b2611964afc 586 // 10 -> Query software build information. No parameters. This replies with
mjr 53:9b2611964afc 587 // the software build information report (see above).
mjr 53:9b2611964afc 588 //
mjr 73:4e8ce0b18915 589 // 11 -> TV ON relay manual control. This allows testing and operating the
mjr 73:4e8ce0b18915 590 // relay from the PC. This doesn't change the power-up configuration;
mjr 88:98bce687e6c0 591 // it merely allows the relay to be controlled directly. The third
mjr 88:98bce687e6c0 592 // byte specifies the relay operation to perform:
mjr 73:4e8ce0b18915 593 //
mjr 73:4e8ce0b18915 594 // 0 = turn relay off
mjr 73:4e8ce0b18915 595 // 1 = turn relay on
mjr 73:4e8ce0b18915 596 // 2 = pulse the relay as though the power-on delay timer fired
mjr 73:4e8ce0b18915 597 //
mjr 77:0b96f6867312 598 // 12 -> Learn IR code. The device enters "IR learning mode". While in
mjr 77:0b96f6867312 599 // learning mode, the device reports the raw signals read through
mjr 77:0b96f6867312 600 // the IR sensor to the PC through the special IR learning report
mjr 77:0b96f6867312 601 // (see "2G" above). If a signal can be decoded through a known
mjr 77:0b96f6867312 602 // protocol, the device sends a final "2G" report with the decoded
mjr 77:0b96f6867312 603 // command, then terminates learning mode. If no signal can be
mjr 77:0b96f6867312 604 // decoded within a timeout period, the mode automatically ends,
mjr 77:0b96f6867312 605 // and the device sends a final IR learning report with zero raw
mjr 77:0b96f6867312 606 // signals to indicate termination. After initiating IR learning
mjr 77:0b96f6867312 607 // mode, the user should point the remote control with the key to
mjr 77:0b96f6867312 608 // be learned at the IR sensor on the KL25Z, and press and hold the
mjr 77:0b96f6867312 609 // key on the remote for a few seconds. Holding the key for a few
mjr 77:0b96f6867312 610 // moments is important because it lets the decoder sense the type
mjr 77:0b96f6867312 611 // of auto-repeat coding the remote uses. The learned code can be
mjr 77:0b96f6867312 612 // written to an IR config variable slot to program the controller
mjr 77:0b96f6867312 613 // to send the learned command on events like TV ON or a button
mjr 77:0b96f6867312 614 // press.
mjr 77:0b96f6867312 615 //
mjr 78:1e00b3fa11af 616 // 13 -> Get button status report. The device sends one button status
mjr 78:1e00b3fa11af 617 // report in response (see section "2F" above).
mjr 78:1e00b3fa11af 618 //
mjr 78:1e00b3fa11af 619 // 14 -> Manually center the accelerometer. This sets the accelerometer
mjr 78:1e00b3fa11af 620 // zero point to the running average of readings over the past few
mjr 78:1e00b3fa11af 621 // seconds.
mjr 78:1e00b3fa11af 622 //
mjr 78:1e00b3fa11af 623 // 15 -> Set up ad hoc IR command, part 1. This sets up the first part
mjr 78:1e00b3fa11af 624 // of an IR command to transmit. The device stores the data in an
mjr 78:1e00b3fa11af 625 // internal register for later use in message 65 16. Send the
mjr 78:1e00b3fa11af 626 // remainder of the command data with 65 16.
mjr 78:1e00b3fa11af 627 //
mjr 78:1e00b3fa11af 628 // byte 3 = IR protocol ID
mjr 78:1e00b3fa11af 629 // byte 4 = flags (IRFlagXxx bit flags)
mjr 78:1e00b3fa11af 630 // byte 5-8 = low-order 32 bits of command code, little-endian
mjr 78:1e00b3fa11af 631 //
mjr 78:1e00b3fa11af 632 // 16 -> Finish and send an ad hoc IR command. Use message 65 15 first
mjr 78:1e00b3fa11af 633 // to set up the start of the command data, then send this message
mjr 78:1e00b3fa11af 634 // to fill in the rest of the data and transmit the command. Upon
mjr 78:1e00b3fa11af 635 // receiving this message, the device performs the transmission.
mjr 78:1e00b3fa11af 636 //
mjr 78:1e00b3fa11af 637 // byte 3-6 = high-order 32 bits of command code, little-endian
mjr 88:98bce687e6c0 638 //
mjr 88:98bce687e6c0 639 // 17 -> Send a pre-programmed IR command. This immediately transmits an
mjr 88:98bce687e6c0 640 // IR code stored in a command slot.
mjr 88:98bce687e6c0 641 //
mjr 88:98bce687e6c0 642 // byte 3 = command number (1..MAX_IR_CODES)
mjr 78:1e00b3fa11af 643 //
mjr 73:4e8ce0b18915 644 //
mjr 35:e959ffba78fd 645 // 66 -> Set configuration variable. The second byte of the message is the config
mjr 35:e959ffba78fd 646 // variable number, and the remaining bytes give the new value for the variable.
mjr 53:9b2611964afc 647 // The value format is specific to each variable; see the CONFIGURATION VARIABLES
mjr 53:9b2611964afc 648 // section below for a list of the variables and their formats. This command
mjr 53:9b2611964afc 649 // only sets the value in RAM; it doesn't write the value to flash and doesn't
mjr 53:9b2611964afc 650 // put the change into effect. To save the new settings, the host must send a
mjr 53:9b2611964afc 651 // type 65 subtype 6 message (see above). That saves the settings to flash and
mjr 53:9b2611964afc 652 // reboots the device, which makes the new settings active.
mjr 35:e959ffba78fd 653 //
mjr 74:822a92bc11d2 654 // 67 -> "SBX". This is an extended form of the original LedWiz SBA message. This
mjr 74:822a92bc11d2 655 // version is specifically designed to support a replacement LEDWIZ.DLL on the
mjr 74:822a92bc11d2 656 // host that exposes one Pinscape device as multiple virtual LedWiz devices,
mjr 74:822a92bc11d2 657 // in order to give legacy clients access to more than 32 ports. Each virtual
mjr 74:822a92bc11d2 658 // LedWiz represents a block of 32 ports. The format of this message is the
mjr 74:822a92bc11d2 659 // same as for the original SBA, with the addition of one byte:
mjr 74:822a92bc11d2 660 //
mjr 74:822a92bc11d2 661 // 67 xx xx xx xx ss pp 00
mjr 74:822a92bc11d2 662 // xx = on/off switches for 8 ports, one bit per port
mjr 74:822a92bc11d2 663 // ss = global flash speed setting for this bank of ports, 1-7
mjr 74:822a92bc11d2 664 // pp = port group: 0 for ports 1-32, 1 for ports 33-64, etc
mjr 74:822a92bc11d2 665 // 00 = unused/reserved; client should set to zero
mjr 74:822a92bc11d2 666 //
mjr 74:822a92bc11d2 667 // As with SBA, this sets the on/off switch states for a block of 32 ports.
mjr 74:822a92bc11d2 668 // SBA always addresses ports 1-32; SBX can address any set of 32 ports.
mjr 74:822a92bc11d2 669 //
mjr 74:822a92bc11d2 670 // We keep a separate speed setting for each group of 32 ports. The purpose
mjr 74:822a92bc11d2 671 // of the SBX extension is to allow a custom LEDWIZ.DLL to expose multiple
mjr 74:822a92bc11d2 672 // virtual LedWiz units to legacy clients, so clients will expect each unit
mjr 74:822a92bc11d2 673 // to have its separate flash speed setting. Each block of 32 ports maps to
mjr 74:822a92bc11d2 674 // a virtual unit on the client side, so each block needs its own speed state.
mjr 74:822a92bc11d2 675 //
mjr 74:822a92bc11d2 676 // 68 -> "PBX". This is an extended form of the original LedWiz PBA message; it's
mjr 74:822a92bc11d2 677 // the PBA equivalent of our SBX extension above.
mjr 74:822a92bc11d2 678 //
mjr 74:822a92bc11d2 679 // 68 pp ee ee ee ee ee ee
mjr 74:822a92bc11d2 680 // pp = port group: 0 for ports 1-8, 1 for 9-16, etc
mjr 74:822a92bc11d2 681 // qq = sequence number: 0 for the first 8 ports in the group, etc
mjr 74:822a92bc11d2 682 // ee = brightness/flash values, 6 bits per port, packed into the bytes
mjr 74:822a92bc11d2 683 //
mjr 74:822a92bc11d2 684 // The port group 'pp' selects a group of 8 ports. Note that, unlike PBA,
mjr 74:822a92bc11d2 685 // the port group being updated is explicitly coded in the message, which makes
mjr 74:822a92bc11d2 686 // the message stateless. This eliminates any possibility of the client and
mjr 74:822a92bc11d2 687 // host getting out of sync as to which ports they're talking about. This
mjr 74:822a92bc11d2 688 // message doesn't affect the PBA port address state.
mjr 74:822a92bc11d2 689 //
mjr 74:822a92bc11d2 690 // The brightness values are *almost* the same as in PBA, but not quite. We
mjr 74:822a92bc11d2 691 // remap the flashing state values as follows:
mjr 74:822a92bc11d2 692 //
mjr 74:822a92bc11d2 693 // 0-48 = brightness level, 0% to 100%, on a linear scale
mjr 74:822a92bc11d2 694 // 49 = brightness level 100% (redundant with 48)
mjr 74:822a92bc11d2 695 // 60 = PBA 129 equivalent, sawtooth
mjr 74:822a92bc11d2 696 // 61 = PBA 130 equivalent, square wave (on/off)
mjr 74:822a92bc11d2 697 // 62 = PBA 131 equivalent, on/fade down
mjr 74:822a92bc11d2 698 // 63 = PBA 132 equivalent, fade up/on
mjr 74:822a92bc11d2 699 //
mjr 74:822a92bc11d2 700 // We reassign the brightness levels like this because it allows us to pack
mjr 74:822a92bc11d2 701 // every possible value into 6 bits. This allows us to fit 8 port settings
mjr 74:822a92bc11d2 702 // into six bytes. The 6-bit fields are packed into the 8 bytes consecutively
mjr 74:822a92bc11d2 703 // starting with the low-order bit of the first byte. An efficient way to
mjr 74:822a92bc11d2 704 // pack the 'ee' fields given the brightness values is to shift each group of
mjr 74:822a92bc11d2 705 // four bytes into a uint, then shift the uint into three 'ee' bytes:
mjr 74:822a92bc11d2 706 //
mjr 74:822a92bc11d2 707 // unsigned int tmp1 = bri[0] | (bri[1]<<6) | (bri[2]<<12) | (bri[3]<<18);
mjr 74:822a92bc11d2 708 // unsigned int tmp2 = bri[4] | (bri[5]<<6) | (bri[6]<<12) | (bri[7]<<18);
mjr 74:822a92bc11d2 709 // unsigned char port_group = FIRST_PORT_TO_ADDRESS / 8;
mjr 74:822a92bc11d2 710 // unsigned char msg[8] = {
mjr 74:822a92bc11d2 711 // 68, pp,
mjr 74:822a92bc11d2 712 // tmp1 & 0xFF, (tmp1 >> 8) & 0xFF, (tmp1 >> 16) & 0xFF,
mjr 74:822a92bc11d2 713 // tmp2 & 0xFF, (tmp2 >> 8) & 0xFF, (tmp2 >> 16) & 0xFF
mjr 74:822a92bc11d2 714 // };
mjr 74:822a92bc11d2 715 //
mjr 35:e959ffba78fd 716 // 200-228 -> Set extended output brightness. This sets outputs N to N+6 to the
mjr 35:e959ffba78fd 717 // respective brightness values in the 2nd through 8th bytes of the message
mjr 35:e959ffba78fd 718 // (output N is set to the 2nd byte value, N+1 is set to the 3rd byte value,
mjr 35:e959ffba78fd 719 // etc). Each brightness level is a linear brightness level from 0-255,
mjr 35:e959ffba78fd 720 // where 0 is 0% brightness and 255 is 100% brightness. N is calculated as
mjr 35:e959ffba78fd 721 // (first byte - 200)*7 + 1:
mjr 35:e959ffba78fd 722 //
mjr 35:e959ffba78fd 723 // 200 = outputs 1-7
mjr 35:e959ffba78fd 724 // 201 = outputs 8-14
mjr 35:e959ffba78fd 725 // 202 = outputs 15-21
mjr 35:e959ffba78fd 726 // ...
mjr 35:e959ffba78fd 727 // 228 = outputs 197-203
mjr 35:e959ffba78fd 728 //
mjr 53:9b2611964afc 729 // This message is the way to address ports 33 and higher. Original LedWiz
mjr 53:9b2611964afc 730 // protocol messages can't access ports above 32, since the protocol is
mjr 53:9b2611964afc 731 // hard-wired for exactly 32 ports.
mjr 35:e959ffba78fd 732 //
mjr 53:9b2611964afc 733 // Note that the extended output messages differ from regular LedWiz commands
mjr 35:e959ffba78fd 734 // in two ways. First, the brightness is the ONLY attribute when an output is
mjr 53:9b2611964afc 735 // set using this mode. There's no separate ON/OFF state per output as there
mjr 35:e959ffba78fd 736 // is with the SBA/PBA messages. To turn an output OFF with this message, set
mjr 35:e959ffba78fd 737 // the intensity to 0. Setting a non-zero intensity turns it on immediately
mjr 35:e959ffba78fd 738 // without regard to the SBA status for the port. Second, the brightness is
mjr 35:e959ffba78fd 739 // on a full 8-bit scale (0-255) rather than the LedWiz's approximately 5-bit
mjr 35:e959ffba78fd 740 // scale, because there are no parts of the range reserved for flashing modes.
mjr 35:e959ffba78fd 741 //
mjr 35:e959ffba78fd 742 // Outputs 1-32 can be controlled by EITHER the regular LedWiz SBA/PBA messages
mjr 35:e959ffba78fd 743 // or by the extended messages. The latest setting for a given port takes
mjr 35:e959ffba78fd 744 // precedence. If an SBA/PBA message was the last thing sent to a port, the
mjr 35:e959ffba78fd 745 // normal LedWiz combination of ON/OFF and brightness/flash mode status is used
mjr 35:e959ffba78fd 746 // to determine the port's physical output setting. If an extended brightness
mjr 35:e959ffba78fd 747 // message was the last thing sent to a port, the LedWiz ON/OFF status and
mjr 35:e959ffba78fd 748 // flash modes are ignored, and the fixed brightness is set. Outputs 33 and
mjr 35:e959ffba78fd 749 // higher inherently can't be addressed or affected by SBA/PBA messages.
mjr 53:9b2611964afc 750 //
mjr 53:9b2611964afc 751 // (The precedence scheme is designed to accommodate a mix of legacy and DOF
mjr 53:9b2611964afc 752 // software transparently. The behavior described is really just to ensure
mjr 53:9b2611964afc 753 // transparent interoperability; it's not something that host software writers
mjr 53:9b2611964afc 754 // should have to worry about. We expect that anyone writing new software will
mjr 53:9b2611964afc 755 // just use the extended protocol and ignore the old LedWiz commands, since
mjr 53:9b2611964afc 756 // the extended protocol is easier to use and more powerful.)
mjr 35:e959ffba78fd 757
mjr 35:e959ffba78fd 758
mjr 35:e959ffba78fd 759 // ------- CONFIGURATION VARIABLES -------
mjr 35:e959ffba78fd 760 //
mjr 35:e959ffba78fd 761 // Message type 66 (see above) sets one configuration variable. The second byte
mjr 35:e959ffba78fd 762 // of the message is the variable ID, and the rest of the bytes give the new
mjr 35:e959ffba78fd 763 // value, in a variable-specific format. 16-bit values are little endian.
mjr 55:4db125cd11a0 764 // Any bytes at the end of the message not otherwise specified are reserved
mjr 55:4db125cd11a0 765 // for future use and should always be set to 0 in the message data.
mjr 35:e959ffba78fd 766 //
mjr 77:0b96f6867312 767 // Variable IDs:
mjr 77:0b96f6867312 768 //
mjr 53:9b2611964afc 769 // 0 -> QUERY ONLY: Describe the configuration variables. The device
mjr 53:9b2611964afc 770 // sends a config variable query report with the following fields:
mjr 53:9b2611964afc 771 //
mjr 53:9b2611964afc 772 // byte 3 -> number of scalar (non-array) variables (these are
mjr 53:9b2611964afc 773 // numbered sequentially from 1 to N)
mjr 53:9b2611964afc 774 // byte 4 -> number of array variables (these are numbered
mjr 53:9b2611964afc 775 // sequentially from 256-N to 255)
mjr 53:9b2611964afc 776 //
mjr 53:9b2611964afc 777 // The description query is meant to allow the host to capture all
mjr 53:9b2611964afc 778 // configuration settings on the device without having to know what
mjr 53:9b2611964afc 779 // the variables mean or how many there are. This is useful for
mjr 53:9b2611964afc 780 // backing up the settings in a file on the PC, for example, or for
mjr 53:9b2611964afc 781 // capturing them to restore after a firmware update. This allows
mjr 53:9b2611964afc 782 // more flexible interoperability between unsynchronized versions
mjr 53:9b2611964afc 783 // of the firmware and the host software.
mjr 53:9b2611964afc 784 //
mjr 53:9b2611964afc 785 // 1 -> USB device ID. This sets the USB vendor and product ID codes
mjr 53:9b2611964afc 786 // to use when connecting to the PC. For LedWiz emulation, use
mjr 35:e959ffba78fd 787 // vendor 0xFAFA and product 0x00EF + unit# (where unit# is the
mjr 53:9b2611964afc 788 // nominal LedWiz unit number, from 1 to 16). If you have any
mjr 53:9b2611964afc 789 // REAL LedWiz units in your system, we recommend starting the
mjr 53:9b2611964afc 790 // Pinscape LedWiz numbering at 8 to avoid conflicts with the
mjr 53:9b2611964afc 791 // real LedWiz units. If you don't have any real LedWiz units,
mjr 53:9b2611964afc 792 // you can number your Pinscape units starting from 1.
mjr 35:e959ffba78fd 793 //
mjr 53:9b2611964afc 794 // If LedWiz emulation isn't desired or causes host conflicts,
mjr 53:9b2611964afc 795 // use our private ID: Vendor 0x1209, product 0xEAEA. (These IDs
mjr 53:9b2611964afc 796 // are registered with http://pid.codes, a registry for open-source
mjr 53:9b2611964afc 797 // USB devices, so they're guaranteed to be free of conflicts with
mjr 53:9b2611964afc 798 // other properly registered devices). The device will NOT appear
mjr 53:9b2611964afc 799 // as an LedWiz if you use the private ID codes, but DOF (R3 or
mjr 53:9b2611964afc 800 // later) will still recognize it as a Pinscape controller.
mjr 53:9b2611964afc 801 //
mjr 53:9b2611964afc 802 // bytes 3:4 -> USB Vendor ID
mjr 53:9b2611964afc 803 // bytes 5:6 -> USB Product ID
mjr 53:9b2611964afc 804 //
mjr 53:9b2611964afc 805 // 2 -> Pinscape Controller unit number for DOF. The Pinscape unit
mjr 53:9b2611964afc 806 // number is independent of the LedWiz unit number, and indepedent
mjr 53:9b2611964afc 807 // of the USB vendor/product IDs. DOF (R3 and later) uses this to
mjr 53:9b2611964afc 808 // identify the unit for the extended Pinscape functionality.
mjr 53:9b2611964afc 809 // For easiest DOF configuration, we recommend numbering your
mjr 53:9b2611964afc 810 // units sequentially starting at 1 (regardless of whether or not
mjr 53:9b2611964afc 811 // you have any real LedWiz units).
mjr 53:9b2611964afc 812 //
mjr 53:9b2611964afc 813 // byte 3 -> unit number, from 1 to 16
mjr 35:e959ffba78fd 814 //
mjr 90:aa4e571da8e8 815 // 3 -> Joystick report settings.
mjr 55:4db125cd11a0 816 //
mjr 92:f264fbaa1be5 817 // byte 3 -> Enable joystick interface: 1 to enable, 0 to disable
mjr 92:f264fbaa1be5 818 // byte 4 -> Joystick axis format, as a USBJoystick::AXIS_FORMAT_XXX value
mjr 92:f264fbaa1be5 819 // bytes 5:8 -> Reporting interval in microseconds
mjr 35:e959ffba78fd 820 //
mjr 55:4db125cd11a0 821 // When joystick reports are disabled, the device registers as a generic HID
mjr 55:4db125cd11a0 822 // device, and only sends the private report types used by the Windows config
mjr 55:4db125cd11a0 823 // tool. It won't appear to Windows as a USB game controller or joystick.
mjr 55:4db125cd11a0 824 //
mjr 55:4db125cd11a0 825 // Note that this doesn't affect whether the device also registers a keyboard
mjr 55:4db125cd11a0 826 // interface. A keyboard interface will appear if and only if any buttons
mjr 55:4db125cd11a0 827 // (including virtual buttons, such as the ZB Launch Ball feature) are assigned
mjr 55:4db125cd11a0 828 // to generate keyboard key input.
mjr 55:4db125cd11a0 829 //
mjr 77:0b96f6867312 830 // 4 -> Accelerometer settings
mjr 35:e959ffba78fd 831 //
mjr 55:4db125cd11a0 832 // byte 3 -> orientation:
mjr 55:4db125cd11a0 833 // 0 = ports at front (USB ports pointing towards front of cabinet)
mjr 55:4db125cd11a0 834 // 1 = ports at left
mjr 55:4db125cd11a0 835 // 2 = ports at right
mjr 55:4db125cd11a0 836 // 3 = ports at rear
mjr 77:0b96f6867312 837 // byte 4 -> dynamic range
mjr 78:1e00b3fa11af 838 // 0 = +/- 1G (2G hardware mode, but rescales joystick reports to 1G
mjr 78:1e00b3fa11af 839 // range; compatible with older versions)
mjr 77:0b96f6867312 840 // 1 = +/- 2G (2G hardware mode)
mjr 77:0b96f6867312 841 // 2 = +/- 4G (4G hardware mode)
mjr 77:0b96f6867312 842 // 3 = +/- 8G (8G hardware mode)
mjr 78:1e00b3fa11af 843 // byte 5 -> Auto-centering mode
mjr 78:1e00b3fa11af 844 // 0 = auto-centering on, 5 second timer (default, compatible
mjr 78:1e00b3fa11af 845 // with older versions)
mjr 78:1e00b3fa11af 846 // 1-60 = auto-centering on with the given time in seconds
mjr 78:1e00b3fa11af 847 // 61-245 = reserved
mjr 78:1e00b3fa11af 848 // 255 = auto-centering off; manual centering only
mjr 92:f264fbaa1be5 849 // byte 6 -> joystick report stutter count: 1 (or 0) means that we
mjr 92:f264fbaa1be5 850 // take a fresh accelerometer on every joystick report; 2 means
mjr 92:f264fbaa1be5 851 // that we take a new reading on every other report, and repeat
mjr 92:f264fbaa1be5 852 // the prior readings on alternate reports; etc
mjr 55:4db125cd11a0 853 //
mjr 55:4db125cd11a0 854 // 5 -> Plunger sensor type.
mjr 35:e959ffba78fd 855 //
mjr 55:4db125cd11a0 856 // byte 3 -> plunger type:
mjr 55:4db125cd11a0 857 // 0 = none (disabled)
mjr 82:4f6209cb5c33 858 // 1 = TSL1410R linear image sensor, 1280x1 pixels, serial mode, edge detection
mjr 82:4f6209cb5c33 859 // 3 = TSL1412R linear image sensor, 1536x1 pixels, serial mode, edge detection
mjr 55:4db125cd11a0 860 // 5 = Potentiometer with linear taper, or any other device that
mjr 55:4db125cd11a0 861 // represents the position reading with a single analog voltage
mjr 82:4f6209cb5c33 862 // 6 = AEDR8300 optical quadrature sensor, 75lpi
mjr 55:4db125cd11a0 863 // *7 = AS5304 magnetic quadrature sensor, 160 steps per 2mm
mjr 82:4f6209cb5c33 864 // 8 = TSL1401CL linear image sensor, 128x1 pixel, bar code detection
mjr 82:4f6209cb5c33 865 // 9 = VL6180X time-of-flight distance sensor
mjr 55:4db125cd11a0 866 //
mjr 55:4db125cd11a0 867 // * The sensor types marked with asterisks (*) are reserved for types
mjr 55:4db125cd11a0 868 // that aren't currently implemented but could be added in the future.
mjr 82:4f6209cb5c33 869 // Selecting these types will effectively disable the plunger. Note
mjr 82:4f6209cb5c33 870 // that sensor types 2 and 4 were formerly reserved for TSL14xx sensors
mjr 82:4f6209cb5c33 871 // in parallel wiring mode, but support for these is no longer planned,
mjr 82:4f6209cb5c33 872 // as the KL25Z's single ADC sampler makes it incapable of gaining any
mjr 82:4f6209cb5c33 873 // advantage from the parallel mode offered by the sensors. Those slots
mjr 82:4f6209cb5c33 874 // could be reassigned in the future for other sensors, since they were
mjr 82:4f6209cb5c33 875 // never enabled in any version of the firwmare.
mjr 55:4db125cd11a0 876 //
mjr 55:4db125cd11a0 877 // 6 -> Plunger pin assignments.
mjr 47:df7a88cd249c 878 //
mjr 55:4db125cd11a0 879 // byte 3 -> pin assignment 1
mjr 55:4db125cd11a0 880 // byte 4 -> pin assignment 2
mjr 55:4db125cd11a0 881 // byte 5 -> pin assignment 3
mjr 55:4db125cd11a0 882 // byte 6 -> pin assignment 4
mjr 55:4db125cd11a0 883 //
mjr 55:4db125cd11a0 884 // All of the pins use the standard GPIO port format (see "GPIO pin number
mjr 55:4db125cd11a0 885 // mappings" below). The actual use of the four pins depends on the plunger
mjr 55:4db125cd11a0 886 // type, as shown below. "NC" means that the pin isn't used at all for the
mjr 82:4f6209cb5c33 887 // corresponding plunger type. "GPIO" means that any GPIO pin will work.
mjr 82:4f6209cb5c33 888 // AnalogIn and InterruptIn means that only pins with the respective
mjr 82:4f6209cb5c33 889 // capabilities can be chosen.
mjr 35:e959ffba78fd 890 //
mjr 55:4db125cd11a0 891 // Plunger Type Pin 1 Pin 2 Pin 3 Pin 4
mjr 35:e959ffba78fd 892 //
mjr 82:4f6209cb5c33 893 // TSL1410R/1412R/1401CL SI (GPIO) CLK (GPIO) AO (AnalogIn) NC
mjr 55:4db125cd11a0 894 // Potentiometer AO (AnalogIn) NC NC NC
mjr 55:4db125cd11a0 895 // AEDR8300 A (InterruptIn) B (InterruptIn) NC NC
mjr 55:4db125cd11a0 896 // AS5304 A (InterruptIn) B (InterruptIn) NC NC
mjr 82:4f6209cb5c33 897 // VL6180X SDA (GPIO) SCL (GPIO) GPIO0/CE (GPIO) NC
mjr 55:4db125cd11a0 898 //
mjr 55:4db125cd11a0 899 // 7 -> Plunger calibration button pin assignments.
mjr 35:e959ffba78fd 900 //
mjr 55:4db125cd11a0 901 // byte 3 -> features enabled/disabled: bit mask consisting of:
mjr 55:4db125cd11a0 902 // 0x01 button input is enabled
mjr 55:4db125cd11a0 903 // 0x02 lamp output is enabled
mjr 55:4db125cd11a0 904 // byte 4 -> DigitalIn pin for the button switch
mjr 55:4db125cd11a0 905 // byte 5 -> DigitalOut pin for the indicator lamp
mjr 55:4db125cd11a0 906 //
mjr 55:4db125cd11a0 907 // Note that setting a pin to NC (Not Connected) will disable it even if the
mjr 55:4db125cd11a0 908 // corresponding feature enable bit (in byte 3) is set.
mjr 35:e959ffba78fd 909 //
mjr 55:4db125cd11a0 910 // 8 -> ZB Launch Ball setup. This configures the ZB Launch Ball feature.
mjr 55:4db125cd11a0 911 //
mjr 55:4db125cd11a0 912 // byte 3 -> LedWiz port number (1-255) mapped to "ZB Launch Ball" in DOF
mjr 55:4db125cd11a0 913 // byte 4 -> key type
mjr 55:4db125cd11a0 914 // byte 5 -> key code
mjr 55:4db125cd11a0 915 // bytes 6:7 -> "push" distance, in 1/1000 inch increments (16 bit little endian)
mjr 55:4db125cd11a0 916 //
mjr 55:4db125cd11a0 917 // Set the port number to 0 to disable the feature. The key type and key code
mjr 55:4db125cd11a0 918 // fields use the same conventions as for a button mapping (see below). The
mjr 55:4db125cd11a0 919 // recommended push distance is 63, which represents .063" ~ 1/16".
mjr 35:e959ffba78fd 920 //
mjr 35:e959ffba78fd 921 // 9 -> TV ON relay setup. This requires external circuitry implemented on the
mjr 35:e959ffba78fd 922 // Expansion Board (or an equivalent circuit as described in the Build Guide).
mjr 55:4db125cd11a0 923 //
mjr 55:4db125cd11a0 924 // byte 3 -> "power status" input pin (DigitalIn)
mjr 55:4db125cd11a0 925 // byte 4 -> "latch" output (DigitalOut)
mjr 55:4db125cd11a0 926 // byte 5 -> relay trigger output (DigitalOut)
mjr 55:4db125cd11a0 927 // bytes 6:7 -> delay time in 10ms increments (16 bit little endian);
mjr 55:4db125cd11a0 928 // e.g., 550 (0x26 0x02) represents 5.5 seconds
mjr 55:4db125cd11a0 929 //
mjr 55:4db125cd11a0 930 // Set the delay time to 0 to disable the feature. The pin assignments will
mjr 55:4db125cd11a0 931 // be ignored if the feature is disabled.
mjr 35:e959ffba78fd 932 //
mjr 77:0b96f6867312 933 // If an IR remote control transmitter is installed (see variable 17), we'll
mjr 77:0b96f6867312 934 // also transmit any IR codes designated as TV ON codes when the startup timer
mjr 77:0b96f6867312 935 // finishes. This allows TVs to be turned on via IR remotes codes rather than
mjr 77:0b96f6867312 936 // hard-wiring them through the relay. The relay can be omitted in this case.
mjr 77:0b96f6867312 937 //
mjr 87:8d35c74403af 938 // 10 -> TLC5940NT setup. This chip is an external PWM controller, with 16 outputs
mjr 35:e959ffba78fd 939 // per chip and a serial data interface that allows the chips to be daisy-
mjr 35:e959ffba78fd 940 // chained. We can use these chips to add an arbitrary number of PWM output
mjr 55:4db125cd11a0 941 // ports for the LedWiz emulation.
mjr 55:4db125cd11a0 942 //
mjr 35:e959ffba78fd 943 // byte 3 = number of chips attached (connected in daisy chain)
mjr 35:e959ffba78fd 944 // byte 4 = SIN pin - Serial data (must connect to SPIO MOSI -> PTC6 or PTD2)
mjr 35:e959ffba78fd 945 // byte 5 = SCLK pin - Serial clock (must connect to SPIO SCLK -> PTC5 or PTD1)
mjr 35:e959ffba78fd 946 // byte 6 = XLAT pin - XLAT (latch) signal (any GPIO pin)
mjr 35:e959ffba78fd 947 // byte 7 = BLANK pin - BLANK signal (any GPIO pin)
mjr 35:e959ffba78fd 948 // byte 8 = GSCLK pin - Grayscale clock signal (must be a PWM-out capable pin)
mjr 35:e959ffba78fd 949 //
mjr 55:4db125cd11a0 950 // Set the number of chips to 0 to disable the feature. The pin assignments are
mjr 55:4db125cd11a0 951 // ignored if the feature is disabled.
mjr 55:4db125cd11a0 952 //
mjr 35:e959ffba78fd 953 // 11 -> 74HC595 setup. This chip is an external shift register, with 8 outputs per
mjr 35:e959ffba78fd 954 // chip and a serial data interface that allows daisy-chaining. We use this
mjr 35:e959ffba78fd 955 // chips to add extra digital outputs for the LedWiz emulation. In particular,
mjr 35:e959ffba78fd 956 // the Chime Board (part of the Expansion Board suite) uses these to add timer-
mjr 55:4db125cd11a0 957 // protected outputs for coil devices (knockers, chimes, bells, etc).
mjr 55:4db125cd11a0 958 //
mjr 35:e959ffba78fd 959 // byte 3 = number of chips attached (connected in daisy chain)
mjr 35:e959ffba78fd 960 // byte 4 = SIN pin - Serial data (any GPIO pin)
mjr 35:e959ffba78fd 961 // byte 5 = SCLK pin - Serial clock (any GPIO pin)
mjr 35:e959ffba78fd 962 // byte 6 = LATCH pin - LATCH signal (any GPIO pin)
mjr 35:e959ffba78fd 963 // byte 7 = ENA pin - ENABLE signal (any GPIO pin)
mjr 35:e959ffba78fd 964 //
mjr 55:4db125cd11a0 965 // Set the number of chips to 0 to disable the feature. The pin assignments are
mjr 55:4db125cd11a0 966 // ignored if the feature is disabled.
mjr 55:4db125cd11a0 967 //
mjr 53:9b2611964afc 968 // 12 -> Disconnect reboot timeout. The reboot timeout allows the controller software
mjr 51:57eb311faafa 969 // to automatically reboot the KL25Z after it detects that the USB connection is
mjr 51:57eb311faafa 970 // broken. On some hosts, the device isn't able to reconnect after the initial
mjr 51:57eb311faafa 971 // connection is lost. The reboot timeout is a workaround for these cases. When
mjr 51:57eb311faafa 972 // the software detects that the connection is no longer active, it will reboot
mjr 51:57eb311faafa 973 // the KL25Z automatically if a new connection isn't established within the
mjr 55:4db125cd11a0 974 // timeout period. Set the timeout to 0 to disable the feature (i.e., the device
mjr 55:4db125cd11a0 975 // will never automatically reboot itself on a broken connection).
mjr 55:4db125cd11a0 976 //
mjr 55:4db125cd11a0 977 // byte 3 -> reboot timeout in seconds; 0 = disabled
mjr 51:57eb311faafa 978 //
mjr 53:9b2611964afc 979 // 13 -> Plunger calibration. In most cases, the calibration is set internally by the
mjr 52:8298b2a73eb2 980 // device by running the calibration procedure. However, it's sometimes useful
mjr 52:8298b2a73eb2 981 // for the host to be able to get and set the calibration, such as to back up
mjr 52:8298b2a73eb2 982 // the device settings on the PC, or to save and restore the current settings
mjr 52:8298b2a73eb2 983 // when installing a software update.
mjr 52:8298b2a73eb2 984 //
mjr 52:8298b2a73eb2 985 // bytes 3:4 = rest position (unsigned 16-bit little-endian)
mjr 52:8298b2a73eb2 986 // bytes 5:6 = maximum retraction point (unsigned 16-bit little-endian)
mjr 52:8298b2a73eb2 987 // byte 7 = measured plunger release travel time in milliseconds
mjr 52:8298b2a73eb2 988 //
mjr 53:9b2611964afc 989 // 14 -> Expansion board configuration. This doesn't affect the controller behavior
mjr 52:8298b2a73eb2 990 // directly; the individual options related to the expansion boards (such as
mjr 52:8298b2a73eb2 991 // the TLC5940 and 74HC595 setup) still need to be set separately. This is
mjr 52:8298b2a73eb2 992 // stored so that the PC config UI can store and recover the information to
mjr 52:8298b2a73eb2 993 // present in the UI. For the "classic" KL25Z-only configuration, simply set
mjr 52:8298b2a73eb2 994 // all of the fields to zero.
mjr 52:8298b2a73eb2 995 //
mjr 53:9b2611964afc 996 // byte 3 = board set type. At the moment, the Pinscape expansion boards
mjr 53:9b2611964afc 997 // are the only ones supported in the software. This allows for
mjr 53:9b2611964afc 998 // adding new designs or independent designs in the future.
mjr 53:9b2611964afc 999 // 0 = Standalone KL25Z (no expansion boards)
mjr 53:9b2611964afc 1000 // 1 = Pinscape expansion boards
mjr 53:9b2611964afc 1001 //
mjr 53:9b2611964afc 1002 // byte 4 = board set interface revision. This *isn't* the version number
mjr 53:9b2611964afc 1003 // of the board itself, but rather of its software interface. In
mjr 53:9b2611964afc 1004 // other words, this doesn't change every time the EAGLE layout
mjr 53:9b2611964afc 1005 // for the board changes. It only changes when a revision is made
mjr 53:9b2611964afc 1006 // that affects the software, such as a GPIO pin assignment.
mjr 53:9b2611964afc 1007 //
mjr 55:4db125cd11a0 1008 // For Pinscape expansion boards (board set type = 1):
mjr 55:4db125cd11a0 1009 // 0 = first release (Feb 2016)
mjr 53:9b2611964afc 1010 //
mjr 55:4db125cd11a0 1011 // bytes 5:8 = additional hardware-specific data. These slots are used
mjr 55:4db125cd11a0 1012 // to store extra data specific to the expansion boards selected.
mjr 55:4db125cd11a0 1013 //
mjr 55:4db125cd11a0 1014 // For Pinscape expansion boards (board set type = 1):
mjr 55:4db125cd11a0 1015 // byte 5 = number of main interface boards
mjr 55:4db125cd11a0 1016 // byte 6 = number of MOSFET power boards
mjr 55:4db125cd11a0 1017 // byte 7 = number of chime boards
mjr 53:9b2611964afc 1018 //
mjr 53:9b2611964afc 1019 // 15 -> Night mode setup.
mjr 53:9b2611964afc 1020 //
mjr 53:9b2611964afc 1021 // byte 3 = button number - 1..MAX_BUTTONS, or 0 for none. This selects
mjr 53:9b2611964afc 1022 // a physically wired button that can be used to control night mode.
mjr 53:9b2611964afc 1023 // The button can also be used as normal for PC input if desired.
mjr 55:4db125cd11a0 1024 // Note that night mode can still be activated via a USB command
mjr 55:4db125cd11a0 1025 // even if no button is assigned.
mjr 55:4db125cd11a0 1026 //
mjr 53:9b2611964afc 1027 // byte 4 = flags:
mjr 66:2e3583fbd2f4 1028 //
mjr 66:2e3583fbd2f4 1029 // 0x01 -> The wired input is an on/off switch: night mode will be
mjr 53:9b2611964afc 1030 // active when the input is switched on. If this bit isn't
mjr 66:2e3583fbd2f4 1031 // set, the input is a momentary button: pushing the button
mjr 53:9b2611964afc 1032 // toggles night mode.
mjr 55:4db125cd11a0 1033 //
mjr 66:2e3583fbd2f4 1034 // 0x02 -> Night Mode is assigned to the SHIFTED button (see Shift
mjr 66:2e3583fbd2f4 1035 // Button setup at variable 16). This can only be used
mjr 66:2e3583fbd2f4 1036 // in momentary mode; it's ignored if flag bit 0x01 is set.
mjr 66:2e3583fbd2f4 1037 // When the shift flag is set, the button only toggles
mjr 66:2e3583fbd2f4 1038 // night mode when you press it while also holding down
mjr 66:2e3583fbd2f4 1039 // the Shift button.
mjr 66:2e3583fbd2f4 1040 //
mjr 53:9b2611964afc 1041 // byte 5 = indicator output number - 1..MAX_OUT_PORTS, or 0 for none. This
mjr 53:9b2611964afc 1042 // selects an output port that will be turned on when night mode is
mjr 53:9b2611964afc 1043 // activated. Night mode activation overrides any setting made by
mjr 53:9b2611964afc 1044 // the host.
mjr 53:9b2611964afc 1045 //
mjr 66:2e3583fbd2f4 1046 // 16 -> Shift Button setup. One button can be designated as a "Local Shift
mjr 66:2e3583fbd2f4 1047 // Button" that can be pressed to select a secondary meaning for other
mjr 78:1e00b3fa11af 1048 // buttons. This isn't the same as the PC keyboard Shift keys; those can
mjr 66:2e3583fbd2f4 1049 // be programmed using the USB key codes for Left Shift and Right Shift.
mjr 66:2e3583fbd2f4 1050 // Rather, this applies a LOCAL shift feature in the cabinet button that
mjr 66:2e3583fbd2f4 1051 // lets you select a secondary meaning. For example, you could assign
mjr 66:2e3583fbd2f4 1052 // the Start button to the "1" key (VP "Start Game") normally, but have
mjr 66:2e3583fbd2f4 1053 // its meaning change to the "5" key ("Insert Coin") when the shift
mjr 66:2e3583fbd2f4 1054 // button is pressed. This provides access to more control functions
mjr 66:2e3583fbd2f4 1055 // without adding more physical buttons.
mjr 66:2e3583fbd2f4 1056 //
mjr 78:1e00b3fa11af 1057 // byte 3 = button number - 1..MAX_BUTTONS, or 0 for none
mjr 78:1e00b3fa11af 1058 // byte 4 = mode (default is 0):
mjr 66:2e3583fbd2f4 1059 //
mjr 78:1e00b3fa11af 1060 // 0 -> Shift OR Key mode. In this mode, the Shift button doesn't
mjr 78:1e00b3fa11af 1061 // send its assigned key or IR command when initially pressed.
mjr 78:1e00b3fa11af 1062 // Instead, we wait to see if another button is pressed while
mjr 78:1e00b3fa11af 1063 // the Shift button is held down. If so, this Shift button
mjr 78:1e00b3fa11af 1064 // press ONLY counts as the Shift function, and its own assigned
mjr 78:1e00b3fa11af 1065 // key is NOT sent to the PC. On the other hand, if you press
mjr 78:1e00b3fa11af 1066 // the Shift button and then release it without having pressed
mjr 78:1e00b3fa11af 1067 // any other key in the meantime, this press counts as a regular
mjr 78:1e00b3fa11af 1068 // key press, so we send the assigned key to the PC.
mjr 78:1e00b3fa11af 1069 //
mjr 78:1e00b3fa11af 1070 // 1 -> Shift AND Key mode. In this mode, the Shift button sends its
mjr 78:1e00b3fa11af 1071 // assigned key when pressed, just like a normal button. If you
mjr 78:1e00b3fa11af 1072 // press another button while the Shift key is pressed, the
mjr 78:1e00b3fa11af 1073 // shifted meaning of the other key is used.
mjr 66:2e3583fbd2f4 1074 //
mjr 77:0b96f6867312 1075 // 17 -> IR Remote Control physical device setup. We support IR remotes for
mjr 77:0b96f6867312 1076 // both sending and receiving. On the receive side, we can read from a
mjr 77:0b96f6867312 1077 // sensor such as a TSOP384xx. The sensor requires one GPIO pin with
mjr 77:0b96f6867312 1078 // interrupt support, so any PTAxx or PTDxx pin will work. On the send
mjr 77:0b96f6867312 1079 // side, we can transmit through any IR LED. This requires one PWM
mjr 77:0b96f6867312 1080 // output pin. To enable send and/or receive, specify a valid pin; to
mjr 77:0b96f6867312 1081 // disable, set the pin NC (not connected). Send and receive can be
mjr 77:0b96f6867312 1082 // enabled and disabled independently; it's not necessary to enable
mjr 77:0b96f6867312 1083 // the transmit function to use the receive function, or vice versa.
mjr 77:0b96f6867312 1084 //
mjr 77:0b96f6867312 1085 // byte 3 = receiver input GPIO pin ID. Must be interrupt-capable.
mjr 77:0b96f6867312 1086 // byte 4 = transmitter pin. Must be PWM-capable.
mjr 77:0b96f6867312 1087 //
mjr 82:4f6209cb5c33 1088 // 18 -> Plunger auto-zeroing. This only applies to sensor types with
mjr 82:4f6209cb5c33 1089 // relative positioning, such as quadrature sensors. Other sensor
mjr 82:4f6209cb5c33 1090 // types simply ignore this.
mjr 82:4f6209cb5c33 1091 //
mjr 82:4f6209cb5c33 1092 // byte 3 = bit flags:
mjr 82:4f6209cb5c33 1093 // 0x01 -> auto-zeroing enabled
mjr 82:4f6209cb5c33 1094 // byte 4 = auto-zeroing time in seconds
mjr 82:4f6209cb5c33 1095 //
mjr 91:ae9be42652bf 1096 // 19 -> Plunger filters. There are two filters that can be applied:
mjr 85:3c28aee81cde 1097 //
mjr 91:ae9be42652bf 1098 // - Jitter filter. This sets a hysteresis window size, to reduce jitter
mjr 91:ae9be42652bf 1099 // jitter in the plunger reading. Most sensors aren't perfectly accurate;
mjr 91:ae9be42652bf 1100 // consecutive readings at the same physical plunger position vary
mjr 91:ae9be42652bf 1101 // slightly, wandering in a range near the true reading. Over time, the
mjr 91:ae9be42652bf 1102 // readings will usually average the true value, but that's not much of a
mjr 91:ae9be42652bf 1103 // consolation to us because we want to display the position in real time.
mjr 91:ae9be42652bf 1104 // To reduce the visible jitter, we can apply a hysteresis filter that
mjr 91:ae9be42652bf 1105 // hides random variations within the specified window. The window is in
mjr 91:ae9be42652bf 1106 // the sensor's native units, so the effect of a given window size
mjr 91:ae9be42652bf 1107 // depends on the sensor type. A value of zero disables the filter.
mjr 91:ae9be42652bf 1108 //
mjr 91:ae9be42652bf 1109 // - Reversed orientation. If set, this inverts the sensor readings, as
mjr 91:ae9be42652bf 1110 // though the sensor were physically flipped to the opposite direction.
mjr 91:ae9be42652bf 1111 // This allows for correcting a reversed physical sensor installation in
mjr 91:ae9be42652bf 1112 // software without having to mess with the hardware.
mjr 91:ae9be42652bf 1113 //
mjr 91:ae9be42652bf 1114 // byte 3:4 = jitter window size in native sensor units, little-endian
mjr 91:ae9be42652bf 1115 // byte 5 = orientation filter bit mask:
mjr 91:ae9be42652bf 1116 // 0x01 -> set if reversed orientation, clear if normal
mjr 91:ae9be42652bf 1117 // 0x80 -> Read-only: this bit is set if the feature is supported
mjr 85:3c28aee81cde 1118 //
mjr 87:8d35c74403af 1119 // 20 -> Plunger bar code setup. Sets parameters applicable only to bar code
mjr 87:8d35c74403af 1120 // sensor types.
mjr 87:8d35c74403af 1121 //
mjr 87:8d35c74403af 1122 // bytes 3:4 = Starting pixel offset of bar code (margin width)
mjr 87:8d35c74403af 1123 //
mjr 87:8d35c74403af 1124 // 21 -> TLC59116 setup. This chip is an external PWM controller with 16
mjr 87:8d35c74403af 1125 // outputs per chip and an I2C bus interface. Up to 14 of the chips
mjr 87:8d35c74403af 1126 // can be connected to a single bus. This chip is a successor to the
mjr 87:8d35c74403af 1127 // TLC5940 with a more modern design and some nice improvements, such
mjr 87:8d35c74403af 1128 // as glitch-free startup and a standard (I2C) physical interface.
mjr 87:8d35c74403af 1129 //
mjr 87:8d35c74403af 1130 // Each chip has a 7-bit I2C address. The top three bits of the
mjr 87:8d35c74403af 1131 // address are fixed in the chip itself and can't be configured, but
mjr 87:8d35c74403af 1132 // the low four bits are configurable via the address line pins on
mjr 87:8d35c74403af 1133 // the chip, A3 A2 A1 A0. Our convention here is to ignore the fixed
mjr 87:8d35c74403af 1134 // three bits and refer to the chip address as just the A3 A2 A1 A0
mjr 87:8d35c74403af 1135 // bits. This gives each chip an address from 0 to 15.
mjr 87:8d35c74403af 1136 //
mjr 87:8d35c74403af 1137 // I2C allows us to discover the attached chips automatically, so in
mjr 87:8d35c74403af 1138 // principle we don't need to know which chips will be present.
mjr 87:8d35c74403af 1139 // However, it's useful for the config tool to know which chips are
mjr 87:8d35c74403af 1140 // expected so that it can offer them in the output port setup UI.
mjr 87:8d35c74403af 1141 // We therefore provide a bit mask specifying the enabled chips. Each
mjr 87:8d35c74403af 1142 // bit specifies whether the chip at the corresponding address is
mjr 87:8d35c74403af 1143 // present: 0x0001 is the chip at address 0, 0x0002 is the chip at
mjr 87:8d35c74403af 1144 // address 1, etc. This is mostly for the config tool's use; we only
mjr 87:8d35c74403af 1145 // use it to determine if TLC59116 support should be enabled at all,
mjr 87:8d35c74403af 1146 // by checking if it's non-zero.
mjr 87:8d35c74403af 1147 //
mjr 87:8d35c74403af 1148 // To disable support, set the populated chip mask to 0. The pin
mjr 87:8d35c74403af 1149 // assignments are all ignored in this case.
mjr 87:8d35c74403af 1150 //
mjr 87:8d35c74403af 1151 // bytes 3:4 = populated chips, as a bit mask (OR in 1<<address
mjr 87:8d35c74403af 1152 // each populated address)
mjr 87:8d35c74403af 1153 // byte 5 = SDA (any GPIO pin)
mjr 87:8d35c74403af 1154 // byte 6 = SCL (any GPIO pin)
mjr 87:8d35c74403af 1155 // byte 7 = RESET (any GPIO pin)
mjr 87:8d35c74403af 1156 //
mjr 53:9b2611964afc 1157 //
mjr 74:822a92bc11d2 1158 // SPECIAL DIAGNOSTICS VARIABLES: These work like the array variables below,
mjr 74:822a92bc11d2 1159 // the only difference being that we don't report these in the number of array
mjr 74:822a92bc11d2 1160 // variables reported in the "variable 0" query.
mjr 74:822a92bc11d2 1161 //
mjr 74:822a92bc11d2 1162 // 220 -> Performance/diagnostics variables. Items marked "read only" can't
mjr 74:822a92bc11d2 1163 // be written; any SET VARIABLE messages on these are ignored. Items
mjr 74:822a92bc11d2 1164 // marked "diagnostic only" refer to counters or statistics that are
mjr 74:822a92bc11d2 1165 // collected only when the diagnostics are enabled via the diags.h
mjr 74:822a92bc11d2 1166 // macro ENABLE_DIAGNOSTICS. These will simply return zero otherwise.
mjr 74:822a92bc11d2 1167 //
mjr 74:822a92bc11d2 1168 // byte 3 = diagnostic index (see below)
mjr 74:822a92bc11d2 1169 //
mjr 74:822a92bc11d2 1170 // Diagnostic index values:
mjr 74:822a92bc11d2 1171 //
mjr 74:822a92bc11d2 1172 // 1 -> Main loop cycle time [read only, diagnostic only]
mjr 74:822a92bc11d2 1173 // Retrieves the average time of one iteration of the main
mjr 74:822a92bc11d2 1174 // loop, in microseconds, as a uint32. This excludes the
mjr 74:822a92bc11d2 1175 // time spent processing incoming messages, as well as any
mjr 74:822a92bc11d2 1176 // time spent waiting for a dropped USB connection to be
mjr 74:822a92bc11d2 1177 // restored. This includes all subroutine time and polled
mjr 74:822a92bc11d2 1178 // task time, such as processing button and plunger input,
mjr 74:822a92bc11d2 1179 // sending USB joystick reports, etc.
mjr 74:822a92bc11d2 1180 //
mjr 74:822a92bc11d2 1181 // 2 -> Main loop message read time [read only, diagnostic only]
mjr 74:822a92bc11d2 1182 // Retrieves the average time spent processing incoming USB
mjr 74:822a92bc11d2 1183 // messages per iteration of the main loop, in microseconds,
mjr 74:822a92bc11d2 1184 // as a uint32. This only counts the processing time when
mjr 74:822a92bc11d2 1185 // messages are actually present, so the average isn't reduced
mjr 74:822a92bc11d2 1186 // by iterations of the main loop where no messages are found.
mjr 74:822a92bc11d2 1187 // That is, if we run a million iterations of the main loop,
mjr 74:822a92bc11d2 1188 // and only five of them have messages at all, the average time
mjr 74:822a92bc11d2 1189 // includes only those five cycles with messages to process.
mjr 74:822a92bc11d2 1190 //
mjr 74:822a92bc11d2 1191 // 3 -> PWM update polling time [read only, diagnostic only]
mjr 74:822a92bc11d2 1192 // Retrieves the average time, as a uint32 in microseconds,
mjr 74:822a92bc11d2 1193 // spent in the PWM update polling routine.
mjr 74:822a92bc11d2 1194 //
mjr 74:822a92bc11d2 1195 // 4 -> LedWiz update polling time [read only, diagnostic only]
mjr 74:822a92bc11d2 1196 // Retrieves the average time, as a uint32 in microseconds,
mjr 74:822a92bc11d2 1197 // units, spent in the LedWiz flash cycle update routine.
mjr 74:822a92bc11d2 1198 //
mjr 74:822a92bc11d2 1199 //
mjr 53:9b2611964afc 1200 // ARRAY VARIABLES: Each variable below is an array. For each get/set message,
mjr 53:9b2611964afc 1201 // byte 3 gives the array index. These are grouped at the top end of the variable
mjr 53:9b2611964afc 1202 // ID range to distinguish this special feature. On QUERY, set the index byte to 0
mjr 53:9b2611964afc 1203 // to query the number of slots; the reply will be a report for the array index
mjr 53:9b2611964afc 1204 // variable with index 0, with the first (and only) byte after that indicating
mjr 53:9b2611964afc 1205 // the maximum array index.
mjr 53:9b2611964afc 1206 //
mjr 77:0b96f6867312 1207 // 250 -> IR remote control commands - code part 2. This stores the high-order
mjr 77:0b96f6867312 1208 // 32 bits of the remote control for each slot. These are combined with
mjr 77:0b96f6867312 1209 // the low-order 32 bits from variable 251 below to form a 64-bit code.
mjr 77:0b96f6867312 1210 //
mjr 77:0b96f6867312 1211 // byte 3 = Command slot number (1..MAX_IR_CODES)
mjr 77:0b96f6867312 1212 // byte 4 = bits 32..39 of remote control command code
mjr 77:0b96f6867312 1213 // byte 5 = bits 40..47
mjr 77:0b96f6867312 1214 // byte 6 = bits 48..55
mjr 77:0b96f6867312 1215 // byte 7 = bits 56..63
mjr 77:0b96f6867312 1216 //
mjr 77:0b96f6867312 1217 // 251 -> IR remote control commands - code part 1. This stores the protocol
mjr 77:0b96f6867312 1218 // identifier and low-order 32 bits of the remote control code for each
mjr 77:0b96f6867312 1219 // remote control command slot. The code represents a key press on a
mjr 77:0b96f6867312 1220 // remote, and is usually determined by reading it from the device's
mjr 77:0b96f6867312 1221 // actual remote via the IR sensor input feature. These codes combine
mjr 77:0b96f6867312 1222 // with variable 250 above to form a 64-bit code for each slot.
mjr 77:0b96f6867312 1223 // See IRRemote/IRProtocolID.h for the protocol ID codes.
mjr 77:0b96f6867312 1224 //
mjr 77:0b96f6867312 1225 // byte 3 = Command slot number (1..MAX_IR_CODES)
mjr 77:0b96f6867312 1226 // byte 4 = protocol ID
mjr 77:0b96f6867312 1227 // byte 5 = bits 0..7 of remote control command code
mjr 77:0b96f6867312 1228 // byte 6 = bits 8..15
mjr 77:0b96f6867312 1229 // byte 7 = bits 16..23
mjr 77:0b96f6867312 1230 // byte 8 = bits 24..31
mjr 77:0b96f6867312 1231 //
mjr 77:0b96f6867312 1232 // 252 -> IR remote control commands - control information. This stores
mjr 77:0b96f6867312 1233 // descriptive information for each remote control command slot.
mjr 77:0b96f6867312 1234 // The IR code for each slot is stored in the corresponding array
mjr 77:0b96f6867312 1235 // entry in variables 251 & 250 above; the information is split over
mjr 77:0b96f6867312 1236 // several variables like this because of the 8-byte command message
mjr 77:0b96f6867312 1237 // size in our USB protocol (which we use for LedWiz compatibility).
mjr 77:0b96f6867312 1238 //
mjr 77:0b96f6867312 1239 // byte 3 = Command slot number (1..MAX_IR_CODES)
mjr 77:0b96f6867312 1240 // byte 4 = bit flags:
mjr 77:0b96f6867312 1241 // 0x01 -> send this code as a TV ON signal at system start
mjr 77:0b96f6867312 1242 // 0x02 -> use "ditto" codes when sending the command
mjr 77:0b96f6867312 1243 // byte 5 = key type; same as the key type in an input button variable
mjr 77:0b96f6867312 1244 // byte 6 = key code; same as the key code in an input button variable
mjr 77:0b96f6867312 1245 //
mjr 77:0b96f6867312 1246 // Each IR command slot can serve three purposes:
mjr 77:0b96f6867312 1247 //
mjr 77:0b96f6867312 1248 // - First, it can be used as part of the TV ON sequence when the
mjr 77:0b96f6867312 1249 // system powers up, to turn on cabinet TVs that don't power up by
mjr 77:0b96f6867312 1250 // themselves. To use this feature, set the TV ON bit in the flags.
mjr 77:0b96f6867312 1251 //
mjr 77:0b96f6867312 1252 // - Second, when the IR sensor receives a command in a given slot, we
mjr 77:0b96f6867312 1253 // can translate it into a keyboard key or joystick button press sent
mjr 77:0b96f6867312 1254 // to the PC. This lets you use any IR remote to send commands to the
mjr 77:0b96f6867312 1255 // PC, allowing access to additional control inputs without any extra
mjr 77:0b96f6867312 1256 // buttons on the cabinet. To use this feature, assign the key to
mjr 77:0b96f6867312 1257 // send in the key type and key code bytes.
mjr 77:0b96f6867312 1258 //
mjr 77:0b96f6867312 1259 // - Third, we can send a given IR command when a physical cabinet
mjr 77:0b96f6867312 1260 // button is pressed. This lets you use cabinet buttons to send IR
mjr 77:0b96f6867312 1261 // commands to other devices in your system. For example, you could
mjr 77:0b96f6867312 1262 // assign cabinet buttons to control the volume on a cab TV. To use
mjr 77:0b96f6867312 1263 // this feature, assign an IR slot as a button function in the button
mjr 77:0b96f6867312 1264 // setup.
mjr 77:0b96f6867312 1265 //
mjr 66:2e3583fbd2f4 1266 // 253 -> Extended input button setup. This adds on to the information set by
mjr 66:2e3583fbd2f4 1267 // variable 254 below, accessing additional fields. The "shifted" key
mjr 66:2e3583fbd2f4 1268 // type and code fields assign a secondary meaning to the button that's
mjr 66:2e3583fbd2f4 1269 // used when the local Shift button is being held down. See variable 16
mjr 66:2e3583fbd2f4 1270 // above for more details on the Shift button.
mjr 66:2e3583fbd2f4 1271 //
mjr 77:0b96f6867312 1272 // byte 3 = Button number (1..MAX_BUTTONS)
mjr 66:2e3583fbd2f4 1273 // byte 4 = shifted key type (same codes as "key type" in var 254)
mjr 77:0b96f6867312 1274 // byte 5 = shifted key code (same codes as "key code" in var 254)
mjr 77:0b96f6867312 1275 // byte 6 = shifted IR command (see "IR command" in var 254)
mjr 66:2e3583fbd2f4 1276 //
mjr 53:9b2611964afc 1277 // 254 -> Input button setup. This sets up one button; it can be repeated for each
mjr 64:ef7ca92dff36 1278 // button to be configured. There are MAX_EXT_BUTTONS button slots (see
mjr 64:ef7ca92dff36 1279 // config.h for the constant definition), numbered 1..MAX_EXT_BUTTONS. Each
mjr 53:9b2611964afc 1280 // slot can be configured as a joystick button, a regular keyboard key, or a
mjr 53:9b2611964afc 1281 // media control key (mute, volume up, volume down).
mjr 53:9b2611964afc 1282 //
mjr 53:9b2611964afc 1283 // The bytes of the message are:
mjr 66:2e3583fbd2f4 1284 // byte 3 = Button number (1..MAX_BUTTONS)
mjr 64:ef7ca92dff36 1285 // byte 4 = GPIO pin for the button input; mapped as a DigitalIn port
mjr 53:9b2611964afc 1286 // byte 5 = key type reported to PC when button is pushed:
mjr 53:9b2611964afc 1287 // 0 = none (no PC input reported when button pushed)
mjr 53:9b2611964afc 1288 // 1 = joystick button -> byte 6 is the button number, 1-32
mjr 53:9b2611964afc 1289 // 2 = regular keyboard key -> byte 6 is the USB key code (see below)
mjr 67:c39e66c4e000 1290 // 3 = media key -> byte 6 is the USB media control code (see below)
mjr 53:9b2611964afc 1291 // byte 6 = key code, which depends on the key type in byte 5
mjr 53:9b2611964afc 1292 // byte 7 = flags - a combination of these bit values:
mjr 53:9b2611964afc 1293 // 0x01 = pulse mode. This reports a physical on/off switch's state
mjr 53:9b2611964afc 1294 // to the host as a brief key press whenever the switch changes
mjr 53:9b2611964afc 1295 // state. This is useful for the VPinMAME Coin Door button,
mjr 53:9b2611964afc 1296 // which requires the End key to be pressed each time the
mjr 53:9b2611964afc 1297 // door changes state.
mjr 77:0b96f6867312 1298 // byte 8 = IR command to transmit when unshifted button is pressed. This
mjr 77:0b96f6867312 1299 // contains an IR slot number (1..MAX_IR_CODES), or 0 if no code
mjr 77:0b96f6867312 1300 // is associated with the button.
mjr 53:9b2611964afc 1301 //
mjr 53:9b2611964afc 1302 // 255 -> LedWiz output port setup. This sets up one output port; it can be repeated
mjr 53:9b2611964afc 1303 // for each port to be configured. There are 128 possible slots for output ports,
mjr 53:9b2611964afc 1304 // numbered 1 to 128. The number of ports atcually active is determined by
mjr 53:9b2611964afc 1305 // the first DISABLED port (type 0). For example, if ports 1-32 are set as GPIO
mjr 53:9b2611964afc 1306 // outputs and port 33 is disabled, we'll report to the host that we have 32 ports,
mjr 53:9b2611964afc 1307 // regardless of the settings for post 34 and higher.
mjr 53:9b2611964afc 1308 //
mjr 53:9b2611964afc 1309 // The bytes of the message are:
mjr 87:8d35c74403af 1310 //
mjr 53:9b2611964afc 1311 // byte 3 = LedWiz port number (1 to MAX_OUT_PORTS)
mjr 87:8d35c74403af 1312 //
mjr 53:9b2611964afc 1313 // byte 4 = physical output type:
mjr 87:8d35c74403af 1314 //
mjr 53:9b2611964afc 1315 // 0 = Disabled. This output isn't used, and isn't visible to the
mjr 53:9b2611964afc 1316 // LedWiz/DOF software on the host. The FIRST disabled port
mjr 53:9b2611964afc 1317 // determines the number of ports visible to the host - ALL ports
mjr 53:9b2611964afc 1318 // after the first disabled port are also implicitly disabled.
mjr 87:8d35c74403af 1319 //
mjr 53:9b2611964afc 1320 // 1 = GPIO PWM output: connected to GPIO pin specified in byte 5,
mjr 53:9b2611964afc 1321 // operating in PWM mode. Note that only a subset of KL25Z GPIO
mjr 53:9b2611964afc 1322 // ports are PWM-capable.
mjr 87:8d35c74403af 1323 //
mjr 53:9b2611964afc 1324 // 2 = GPIO Digital output: connected to GPIO pin specified in byte 5,
mjr 53:9b2611964afc 1325 // operating in digital mode. Digital ports can only be set ON
mjr 53:9b2611964afc 1326 // or OFF, with no brightness/intensity control. All pins can be
mjr 53:9b2611964afc 1327 // used in this mode.
mjr 87:8d35c74403af 1328 //
mjr 53:9b2611964afc 1329 // 3 = TLC5940 port: connected to TLC5940 output port number specified
mjr 53:9b2611964afc 1330 // in byte 5. Ports are numbered sequentially starting from port 0
mjr 53:9b2611964afc 1331 // for the first output (OUT0) on the first chip in the daisy chain.
mjr 87:8d35c74403af 1332 //
mjr 53:9b2611964afc 1333 // 4 = 74HC595 port: connected to 74HC595 output port specified in byte 5.
mjr 53:9b2611964afc 1334 // As with the TLC5940 outputs, ports are numbered sequentially from 0
mjr 53:9b2611964afc 1335 // for the first output on the first chip in the daisy chain.
mjr 87:8d35c74403af 1336 //
mjr 53:9b2611964afc 1337 // 5 = Virtual output: this output port exists for the purposes of the
mjr 53:9b2611964afc 1338 // LedWiz/DOF software on the host, but isn't physically connected
mjr 53:9b2611964afc 1339 // to any output device. This can be used to create a virtual output
mjr 53:9b2611964afc 1340 // for the DOF ZB Launch Ball signal, for example, or simply as a
mjr 53:9b2611964afc 1341 // placeholder in the LedWiz port numbering. The physical output ID
mjr 53:9b2611964afc 1342 // (byte 5) is ignored for this port type.
mjr 87:8d35c74403af 1343 //
mjr 87:8d35c74403af 1344 // 6 = TLC59116 output: connected to the TLC59116 output port specified
mjr 87:8d35c74403af 1345 // in byte 5. The high four bits of this value give the chip's
mjr 87:8d35c74403af 1346 // I2C address, specifically the A3 A2 A1 A0 bits configured in
mjr 87:8d35c74403af 1347 // the hardware. (A chip's I2C address is actually 7 bits, but
mjr 87:8d35c74403af 1348 // the three high-order bits are fixed, so we don't bother including
mjr 87:8d35c74403af 1349 // those in the byte 5 value). The low four bits of this value
mjr 87:8d35c74403af 1350 // give the output port number on the chip. For example, 0x37
mjr 87:8d35c74403af 1351 // specifies chip 3 (the one with A3 A2 A1 A0 wired as 0 0 1 1),
mjr 87:8d35c74403af 1352 // output #7 on that chip. Note that outputs are numbered from 0
mjr 87:8d35c74403af 1353 // to 15 (0xF) on each chip.
mjr 87:8d35c74403af 1354 //
mjr 53:9b2611964afc 1355 // byte 5 = physical output port, interpreted according to the value in byte 4
mjr 87:8d35c74403af 1356 //
mjr 53:9b2611964afc 1357 // byte 6 = flags: a combination of these bit values:
mjr 53:9b2611964afc 1358 // 0x01 = active-high output (0V on output turns attached device ON)
mjr 53:9b2611964afc 1359 // 0x02 = noisemaker device: disable this output when "night mode" is engaged
mjr 89:c43cd923401c 1360 // 0x04 = apply gamma correction to this output (PWM outputs only)
mjr 89:c43cd923401c 1361 // 0x08 = "Flipper Logic" enabled for this output (PWM outputs only)
mjr 89:c43cd923401c 1362 //
mjr 89:c43cd923401c 1363 // byte 7 = "Flipper Logic" parameters. If Flipper Logic is enabled (via bit 0x08
mjr 89:c43cd923401c 1364 // in the flags byte above), the software limits power to the output when
mjr 89:c43cd923401c 1365 // the output stays on continuously for longer than a short time. This is
mjr 89:c43cd923401c 1366 // designed to protect coils and solenoids. Most coils are designed to
mjr 89:c43cd923401c 1367 // be energized only in short bursts, just long enough to complete the
mjr 89:c43cd923401c 1368 // mechanical stroke, and will overheat if energized continuously. In a
mjr 89:c43cd923401c 1369 // pinball machine, most coils are used this way naturally: bumpers,
mjr 89:c43cd923401c 1370 // slingshots, kickers, knockers, chimes, etc. are only fired in brief
mjr 89:c43cd923401c 1371 // bursts. Some coils are left on for long periods, though, particularly
mjr 89:c43cd923401c 1372 // the flippers. The Flipper Logic feature is designed to handle this
mjr 89:c43cd923401c 1373 // in a way similar to how real pinball machines solve the same problem.
mjr 89:c43cd923401c 1374 // When Flipper Logic is enabled, the software gives the output full
mjr 89:c43cd923401c 1375 // power when initially turned on, but reduces the power to a lower
mjr 89:c43cd923401c 1376 // level (via PWM) after a short time elapses. The point is to reduce
mjr 89:c43cd923401c 1377 // the power to a level low enough that the coil can safely dissipate
mjr 89:c43cd923401c 1378 // the generated heat indefinitely, but still high enough to keep the
mjr 89:c43cd923401c 1379 // solenoid mechanically actuated. This is possible because solenoids
mjr 89:c43cd923401c 1380 // generally need much less power to "hold" than to actuate initially.
mjr 89:c43cd923401c 1381 //
mjr 89:c43cd923401c 1382 // The high-order 4 bits of this byte give the initial full power time,
mjr 89:c43cd923401c 1383 // in 50ms increments, starting at a minimum of 50ms: 0 = 50ms, 1 = 100ms,
mjr 89:c43cd923401c 1384 // 2 = 150ms, ..., 15 = 800ms.
mjr 53:9b2611964afc 1385 //
mjr 89:c43cd923401c 1386 // The low-order 4 bits of the byte give the percentage power, in 6.66%
mjr 89:c43cd923401c 1387 // increments: 0 = 0% (off), 1 = 6.66%, ..., 15 = 100%.
mjr 89:c43cd923401c 1388 //
mjr 89:c43cd923401c 1389 // A hold power of 0 provides a software equivalent of the timer-protected
mjr 89:c43cd923401c 1390 // output logic of the Pinscape expansion boards used in the main board's
mjr 89:c43cd923401c 1391 // replay knocker output and all of the chime board outputs. This is
mjr 89:c43cd923401c 1392 // suitable for devices that shouldn't ever fire for long periods to
mjr 89:c43cd923401c 1393 // start with.
mjr 89:c43cd923401c 1394 //
mjr 89:c43cd923401c 1395 // Non-zero hold powers are suitable for devices that do need to stay on
mjr 89:c43cd923401c 1396 // for long periods, such as flippers. The "right" level will vary by
mjr 89:c43cd923401c 1397 // device; you should experiment to find the lowest setting where the
mjr 89:c43cd923401c 1398 // device stays mechanically actuated. Once you find the level, you
mjr 89:c43cd923401c 1399 // should confirm that the device won't overheat at that level by turning
mjr 89:c43cd923401c 1400 // it on at the selected level and carefully monitoring it for heating.
mjr 89:c43cd923401c 1401 // If the coil stays cool for a minute or two, it should be safe to assume
mjr 89:c43cd923401c 1402 // that it's in thermal equilibrium, meaning it should be able to sustain
mjr 89:c43cd923401c 1403 // the power level indefinitely.
mjr 89:c43cd923401c 1404 //
mjr 89:c43cd923401c 1405 //
mjr 89:c43cd923401c 1406 // Note that the KL25Z's on-board LEDs can be used as LedWiz output ports, simply
mjr 89:c43cd923401c 1407 // by assigning the LED GPIO pins as output ports. This is useful for testing a new
mjr 89:c43cd923401c 1408 // installation without having to connect any external devices. Assigning the
mjr 89:c43cd923401c 1409 // on-board LEDs as output ports automatically overrides their normal status and
mjr 89:c43cd923401c 1410 // diagnostic display use, so be aware that the normal status flash pattern won't
mjr 89:c43cd923401c 1411 // appear when they're used this way.
mjr 52:8298b2a73eb2 1412 //
mjr 35:e959ffba78fd 1413
mjr 35:e959ffba78fd 1414
mjr 55:4db125cd11a0 1415 // --- GPIO PIN NUMBER MAPPINGS ---
mjr 35:e959ffba78fd 1416 //
mjr 53:9b2611964afc 1417 // In USB messages that specify GPIO pin assignments, pins are identified by
mjr 53:9b2611964afc 1418 // 8-bit integers. The special value 0xFF means NC (not connected). All actual
mjr 53:9b2611964afc 1419 // pins are mapped with the port number in the top 3 bits and the pin number in
mjr 53:9b2611964afc 1420 // the bottom 5 bits. Port A=0, B=1, ..., E=4. For example, PTC7 is port C (2)
mjr 53:9b2611964afc 1421 // pin 7, so it's represented as (2 << 5) | 7.
mjr 53:9b2611964afc 1422
mjr 35:e959ffba78fd 1423
mjr 35:e959ffba78fd 1424 // --- USB KEYBOARD SCAN CODES ---
mjr 35:e959ffba78fd 1425 //
mjr 53:9b2611964afc 1426 // For regular keyboard keys, we use the standard USB HID scan codes
mjr 53:9b2611964afc 1427 // for the US keyboard layout. The scan codes are defined by the USB
mjr 53:9b2611964afc 1428 // HID specifications; you can find a full list in the official USB
mjr 53:9b2611964afc 1429 // specs. Some common codes are listed below as a quick reference.
mjr 35:e959ffba78fd 1430 //
mjr 53:9b2611964afc 1431 // Key name -> USB scan code (hex)
mjr 53:9b2611964afc 1432 // A-Z -> 04-1D
mjr 53:9b2611964afc 1433 // top row 1!->0) -> 1E-27
mjr 53:9b2611964afc 1434 // Return -> 28
mjr 53:9b2611964afc 1435 // Escape -> 29
mjr 53:9b2611964afc 1436 // Backspace -> 2A
mjr 53:9b2611964afc 1437 // Tab -> 2B
mjr 53:9b2611964afc 1438 // Spacebar -> 2C
mjr 53:9b2611964afc 1439 // -_ -> 2D
mjr 53:9b2611964afc 1440 // =+ -> 2E
mjr 53:9b2611964afc 1441 // [{ -> 2F
mjr 53:9b2611964afc 1442 // ]} -> 30
mjr 53:9b2611964afc 1443 // \| -> 31
mjr 53:9b2611964afc 1444 // ;: -> 33
mjr 53:9b2611964afc 1445 // '" -> 34
mjr 53:9b2611964afc 1446 // `~ -> 35
mjr 53:9b2611964afc 1447 // ,< -> 36
mjr 53:9b2611964afc 1448 // .> -> 37
mjr 53:9b2611964afc 1449 // /? -> 38
mjr 53:9b2611964afc 1450 // Caps Lock -> 39
mjr 53:9b2611964afc 1451 // F1-F12 -> 3A-45
mjr 53:9b2611964afc 1452 // F13-F24 -> 68-73
mjr 53:9b2611964afc 1453 // Print Screen -> 46
mjr 53:9b2611964afc 1454 // Scroll Lock -> 47
mjr 53:9b2611964afc 1455 // Pause -> 48
mjr 53:9b2611964afc 1456 // Insert -> 49
mjr 53:9b2611964afc 1457 // Home -> 4A
mjr 53:9b2611964afc 1458 // Page Up -> 4B
mjr 53:9b2611964afc 1459 // Del -> 4C
mjr 53:9b2611964afc 1460 // End -> 4D
mjr 53:9b2611964afc 1461 // Page Down -> 4E
mjr 53:9b2611964afc 1462 // Right Arrow -> 4F
mjr 53:9b2611964afc 1463 // Left Arrow -> 50
mjr 53:9b2611964afc 1464 // Down Arrow -> 51
mjr 53:9b2611964afc 1465 // Up Arrow -> 52
mjr 53:9b2611964afc 1466 // Num Lock/Clear -> 53
mjr 53:9b2611964afc 1467 // Keypad / * - + -> 54 55 56 57
mjr 53:9b2611964afc 1468 // Keypad Enter -> 58
mjr 53:9b2611964afc 1469 // Keypad 1-9 -> 59-61
mjr 53:9b2611964afc 1470 // Keypad 0 -> 62
mjr 53:9b2611964afc 1471 // Keypad . -> 63
mjr 53:9b2611964afc 1472 // Mute -> 7F
mjr 53:9b2611964afc 1473 // Volume Up -> 80
mjr 53:9b2611964afc 1474 // Volume Down -> 81
mjr 53:9b2611964afc 1475 // Left Control -> E0
mjr 53:9b2611964afc 1476 // Left Shift -> E1
mjr 53:9b2611964afc 1477 // Left Alt -> E2
mjr 53:9b2611964afc 1478 // Left GUI -> E3
mjr 53:9b2611964afc 1479 // Right Control -> E4
mjr 53:9b2611964afc 1480 // Right Shift -> E5
mjr 53:9b2611964afc 1481 // Right Alt -> E6
mjr 53:9b2611964afc 1482 // Right GUI -> E7
mjr 53:9b2611964afc 1483 //
mjr 66:2e3583fbd2f4 1484 // Due to limitations in Windows, there's a limit of 6 regular keys
mjr 66:2e3583fbd2f4 1485 // pressed at the same time. The shift keys in the E0-E7 range don't
mjr 66:2e3583fbd2f4 1486 // count against this limit, though, since they're encoded as modifier
mjr 66:2e3583fbd2f4 1487 // keys; all of these can be pressed at the same time in addition to 6
mjr 67:c39e66c4e000 1488 // regular keys.
mjr 67:c39e66c4e000 1489
mjr 67:c39e66c4e000 1490 // --- USB MEDIA CONTROL SCAN CODES ---
mjr 67:c39e66c4e000 1491 //
mjr 67:c39e66c4e000 1492 // Buttons mapped to type 3 are Media Control buttons. These select
mjr 67:c39e66c4e000 1493 // a small set of common media control functions. We recognize the
mjr 67:c39e66c4e000 1494 // following type codes only:
mjr 67:c39e66c4e000 1495 //
mjr 67:c39e66c4e000 1496 // Mute -> E2
mjr 67:c39e66c4e000 1497 // Volume up -> E9
mjr 67:c39e66c4e000 1498 // Volume Down -> EA
mjr 67:c39e66c4e000 1499 // Next Track -> B5
mjr 67:c39e66c4e000 1500 // Previous Track -> B6
mjr 67:c39e66c4e000 1501 // Stop -> B7
mjr 67:c39e66c4e000 1502 // Play/Pause -> CD