{"id":17957930,"url":"https://github.com/petrockblog/controlblockservice2","last_synced_at":"2025-03-25T03:30:56.006Z","repository":{"id":147186430,"uuid":"48791705","full_name":"petrockblog/ControlBlockService2","owner":"petrockblog","description":"This is the driver for the ControlBlock re.v 2.X, a power switch and input/output/gameapd gadget for the Raspberry Pi","archived":false,"fork":false,"pushed_at":"2024-10-01T06:25:42.000Z","size":2747,"stargazers_count":23,"open_issues_count":8,"forks_count":9,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-03-19T07:33:42.403Z","etag":null,"topics":["arcade","controlblock-driver","driver","game-pads","gamepad","gaming","petrockblock","power-switch","raspberry","raspberry-pi","raspberry-pi-3","raspberry-pi-4","raspberry-pi-5","raspberrypi","retro","retropie","rpi","rpi2","rpi3","shutdown"],"latest_commit_sha":null,"homepage":"https://www.petrockblock.com/controlblock/","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/petrockblog.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2015-12-30T08:52:17.000Z","updated_at":"2024-11-25T07:25:03.000Z","dependencies_parsed_at":"2024-03-16T12:28:36.569Z","dependency_job_id":null,"html_url":"https://github.com/petrockblog/ControlBlockService2","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/petrockblog%2FControlBlockService2","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/petrockblog%2FControlBlockService2/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/petrockblog%2FControlBlockService2/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/petrockblog%2FControlBlockService2/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/petrockblog","download_url":"https://codeload.github.com/petrockblog/ControlBlockService2/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245394515,"owners_count":20608115,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["arcade","controlblock-driver","driver","game-pads","gamepad","gaming","petrockblock","power-switch","raspberry","raspberry-pi","raspberry-pi-3","raspberry-pi-4","raspberry-pi-5","raspberrypi","retro","retropie","rpi","rpi2","rpi3","shutdown"],"created_at":"2024-10-29T10:58:11.588Z","updated_at":"2025-03-25T03:30:55.248Z","avatar_url":"https://github.com/petrockblog.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"ControlBlockService2\n====================\n\nThis is the driver for the petrockblock.com ControlBlock, which is an extension board for the Raspberry Pi (TM). The driver itself is denoted as _controlblock_ in the following. The driver provides a service for interacting with the power button signals as well as for mapping attached game controllers to corresponding game pad devices on the Raspberry Pi.\n\n**Please note that this is the driver for revision 2.X of the ControlBlock. If you have a revision 1.X board, you need to use the [driver for that revision series](https://github.com/petrockblog/ControlBlockService).**\n\n## Contents\n\n- [ControlBlockService2](#controlblockservice2)\n  - [Contents](#contents)\n  - [Prerequisites](#prerequisites)\n  - [Downloading](#downloading)\n  - [Quick Installation](#quick-installation)\n  - [Building and Installation](#building-and-installation)\n  - [Installation as Service](#installation-as-service)\n  - [Uninstalling the service and/or the binary](#uninstalling-the-service-andor-the-binary)\n  - [Configuration](#configuration)\n    - [Setting the Type of Gamepad](#setting-the-type-of-gamepad)\n      - [Arcade](#arcade)\n      - [MAME](#mame)\n      - [SNES / NES](#snes--nes)\n      - [Genesis / Megadrive](#genesis--megadrive)\n      - [Saturn](#saturn)\n    - [Using Only one Gamepad](#using-only-one-gamepad)\n    - [Enabling or Disabling the Power Switch Functionality](#enabling-or-disabling-the-power-switch-functionality)\n    - [Custom Actions at Shutdown](#custom-actions-at-shutdown)\n    - [4-Player Extension with two ControlBlocks](#4-player-extension-with-two-controlblocks)\n      - [Setting Base Address with the Solder Jumpers](#setting-base-address-with-the-solder-jumpers)\n      - [Interrupting the Signal Lines for the Power Switch on the Second ControlBlock](#interrupting-the-signal-lines-for-the-power-switch-on-the-second-controlblock)\n      - [Adapting the Configuration File for Four Players](#adapting-the-configuration-file-for-four-players)\n      - [Four Player Hardware Setup Example](#four-player-hardware-setup-example)\n  - [Troubleshooting](#troubleshooting)\n    - [Checking the Raw GPIO of the Raspberry](#checking-the-raw-gpio-of-the-raspberry)\n\n## Prerequisites\n\nTo be able to successfully build ControlBlockService you need to have certain APT packages installed. You can make sure that you have the latest version of those packages with these commands:\n\n```bash\nsudo apt-get update\nsudo apt-get upgrade -y\nsudo apt-get install -y git cmake g++ doxygen libc6 libc6-dev\n```\n\n## Downloading\n\nIf you would like to download the latest version of _controlblock_ from [its Github repository](https://github.com/petrockblog/ControlBlockService2), you can use this command:\n\n```bash\ngit clone --recursive https://github.com/petrockblog/ControlBlockService2.git\n```\n\nNote that the above command also takes care for downloading the included Git submodules.\n\n## Quick Installation\n\nThere comes an installation script with this reposity that does all the steps described below: `install.sh` This script compiles the driver, installs the binary and configuration files, and installs the ControlBlock service.\n\nTo run the quick installation, you just need to call this one line from the Raspbian console\n\n```bash\nwget -O - https://raw.githubusercontent.com/petrockblog/ControlBlockService2/master/install.sh | sudo bash\n```\n\nHere is a video of a typical quick installation procedure:\n\n[![asciicast](https://asciinema.org/a/lOGtRU99jT0MDulxSc3ZGuPRd.png)](https://asciinema.org/a/lOGtRU99jT0MDulxSc3ZGuPRd)\n\n## Building and Installation\n\nTo build _controlblock_ follow these commands:\n\n```bash\ncd ControlBlockService2\nmkdir build\ncd build\ncmake ..\nmake\n```\n\nIf everything went fine you can install the driver from within the folder `build` with the command\n\n```bash\nsudo make install\n```\n\n## Installation as Service\n\nYou can install _controlblock_ as daemon from within the folder `build` with this command:\n\n```bash\nsudo make installservice\n```\n\nIt might be that you need to **restart** your Raspberry afterwards to have all needed services running.\n\n## Uninstalling the service and/or the binary\n\nYou can uninstall the daemon from within the folder `build` with this command:\n\n```bash\nsudo make uninstallservice\n```\n\nYou can uninstall the binary from within the folder `build` with this command:\n\n```bash\nsudo make uninstall\n```\n\n## Configuration\n\nThe configuration file of _controlblock_ is located at __```/etc/controlblockconfig.cfg```__. It uses JSON syntax for setting the the values of its configuration parameters.\n\nThe default configuration file looks like this:\n\n```\n{\n    \"controlblocks\" : [\n        {\n            \"enabled\" : true,          // Enables (=true) or disables (=false) the ControlBlock \n            \"address\" : {              // The address information of the first ControlBlock\n                \"SJ1\" : 0,             // The hardware address solder-jumper SJ1. Options: 0, 1 \n                \"SJ2\" : 0              // The hardware address solder-jumper SJ2, Options: 0, 1\n            },\n            \"gamepadtype\" : \"arcade\",  // Sets the gamepad type. Options: \"arcade\", \"mame\", \"snes\", \"nes\", \"genesis\", \"none\"\n            \"onlyOneGamepad\" : false,  // If true, registers only one gamepad instead of two\n            \"powerswitchOn\" : true     // Enables (=true) the power switch functionality. Options: true, false\n        },\n        {\n            \"enabled\" : false,          // Enables (=true) or disables (=false) the second ControlBlock \n            \"address\" : {               // The address information of the second ControlBlock\n                \"SJ1\" : 1,              // The hardware address solder-jumper SJ1. Options: 0, 1 \n                \"SJ2\" : 0               // The hardware address solder-jumper SJ2, Options: 0, 1\n            },\n            \"gamepadtype\" : \"arcade\",   // Sets the gamepad type. Options: \"arcade\", \"mame\", \"snes\", \"nes\", \"genesis\", \"none\"\n            \"onlyOneGamepad\" : false    // If true, registers only one gamepad instead of two\n        }\n    ]\n}\n```\n\n### Setting the Type of Gamepad\n\nTo set the type of the gamepad you need to set the value of the element `gamepadtype`. You can choose between these values:\n\n#### Arcade\n\n- ```arcade```: Enables two game pads in the system and maps the GPIOs of the ControlBlock to these game pads.\u003cbr\u003e\n ![ArcadeMapping](https://github.com/petrockblog/ControlBlockService2/raw/master/supplementary/ControlBlockLayoutArcade.png)\n\n#### MAME\n\n- ```mame```: Enables a virtual keyboard and maps the GPIOs of the ControlBlock to this keyboard with a MAME layout.\u003cbr\u003e\n ![MAMEMapping](https://github.com/petrockblog/ControlBlockService2/raw/master/supplementary/ControlBlockLayoutMAME.png)\n\n#### SNES / NES\n\n- ```snes```: Enables two game pads in the system and maps the attached SNES/NES controllers accordingly.\u003cbr\u003e\n ![SNESMapping](https://github.com/petrockblog/ControlBlockService2/raw/master/supplementary/ControlBlockLayoutSNES.png)\nYou can also connect a non-latching __reset button__ to `Player-1, Input B`. If the button is pressed a virtual ESC-key press will be triggered as well as a simultaneous press of the start and select buttons for player 1.\n\n#### Genesis / Megadrive\n\n- ```genesis```: Enables two game pads in the system and maps the attached Genesis/Megadrive/Atari controllers accordingly.\u003cbr\u003e\n ![GenesisMapping](https://github.com/petrockblog/ControlBlockService2/raw/master/supplementary/ControlBlockLayoutGenesis.png)\nYou can __switch to six-button__ controller by pressing the button combination `START, A, B, C, UP` at the same time.\n\n#### Saturn\n\n- ```saturn```: Enables two gamepads in the system and maps the attached Sega Saturn controllers accordingly. This table shows the pin assignment for Sega Saturn controllers:\n\n| Control\u003cbr\u003eport\u003cbr\u003epin # | Name | Function | Cable Color | ControlBlock\u003cbr\u003ePort |\n| --- | --- | --- | --- | --- |\n| 1 | VCC | +5v (Out) | Red | right |\n| 2 | D1 | Data 1    | White | left |\n| 3 | D0 | Data 0    | Yellow | up |\n| 4 | S0 | Select 1  | Orange |  down |\n| 5 | S1 | Select 0  | Blue | sw1 |\n| 6 | 5v | +5v (Inp) | Green | sw2|\n| 7 | D3 | Data 3    | Brown | sw3 |\n| 8 | D2 | Data 2    | Black | sw4 |\n| 9 | GND | Ground    | Purple | sw5 |\n\nThe Control port pins of the connector are assigned as follows:\n\n```plain\n      /                /\n     -----------------    /\n   /                   \\ / \n  |  1 2 3 4 5 6 7 8 9  |  /\n  |                     | /\n  -----------------------\n     Front / Outside\n```\n\n### Using Only one Gamepad\n\nIf you want to connect only one gamepad to the ControlBlock you can set the element `onlyOneGamepad` to `true`: It enables only one gamepad in the system (e.g., if only Player-1 buttons are wired to the ControlBlock in your setup, this prevents a ghost gamepad from being selected as default player 2 in retroarch)\n\n### Enabling or Disabling the Power Switch Functionality\n\nTo enable or disable the power switch functionality you can set the element `powerswitchOn` to `true` or `false`:\n\n- ```true```: Activates the handling of the power switch signals of the ControlBlock.\n- ```false```: Deactivates the handling of the power switch signals of the ControlBlock.\n\n### Custom Actions at Shutdown\n\nWhen the driver observes a shutdown signal from the ControlBlock, a shutdown Bash script is called. You can find and edit it at `/etc/controlblockswitchoff.sh`.\n\n### 4-Player Extension with two ControlBlocks\n\nThe driver can handle up to two ControlBlocks. This means that you can stack two ControlBlock on top of each other to have inputs for four players.\n\n#### Setting Base Address with the Solder Jumpers\n\nIn order to use two ControlBlocks on top of each other, you need to change the base address of one of the ControlBlocks to a different value than the default one. The base address is used by the ControlBlock driver to identify and distinguish the two ControlBlocks from each other. The base address can be set with the solder jumpers SJ1 and SJ2. To change the base address, you need to _use a solder iron_ and set, e.g., SJ1 to \"1\". Make sure that only two of the three solder pads are connected with each other! The following image shows the solder jumpers:\n\n![Solder jumpers SJ1 and SJ2 for setting the base address](https://github.com/petrockblog/ControlBlockService2/raw/master/supplementary/4playerCB3.jpg)\n\n#### Interrupting the Signal Lines for the Power Switch on the Second ControlBlock\n\nIt is important that you interrupt the signal lines for the power switch to the second ControlBlock. If you do not interrupt the signals to the top ControlBlock, the system will shutdown immediately after the system start. To interrupt the signal lines you can snap off or bend the pins 11 and 12 on the bottom ControlBlock. The power switch functionality and all game pad functionalities are still given!  Here are two images that show how the pins could be bent:\n\n![Bending pins for 4-player functionality, view 1](https://github.com/petrockblog/ControlBlockService2/raw/master/supplementary/4playerCB1.jpg)\n\n![Bending pins for 4-player functionality, view 2](https://github.com/petrockblog/ControlBlockService2/raw/master/supplementary/4playerCB2.jpg)\n\n#### Adapting the Configuration File for Four Players\n\nThe values of the solder jumpers have to be set in the configuration file with the elements `SJ1` and `SJ2`. Also, you have to enable the second ControlBlock by setting the element `enabled` for the second ControlBlock to `true`.\n\nIf you have set the solder jumper SJ1 to 1, a usual 4-player configuration that enables two ControlBlocks with arcade mode would look like this:\n\n```\n{\n    \"controlblocks\" : [\n        {\n            \"enabled\" : true,          // Enables (=true) or disables (=false) the ControlBlock \n            \"address\" : {              // The address information of the first ControlBlock\n                \"SJ1\" : 0,             // The hardware address solder-jumper SJ1. Options: 0, 1 \n                \"SJ2\" : 0              // The hardware address solder-jumper SJ2, Options: 0, 1\n            },\n            \"gamepadtype\" : \"arcade\",  // Sets the gamepad type. Options: \"arcade\", \"mame\", \"snes\", \"genesis\", \"none\"\n            \"onlyOneGamepad\" : false,  // If true, registers only one gamepad instead of two\n            \"powerswitchOn\" : true     // Enables (=true) the power switch functionality. Options: true, false\n        },\n        {\n            \"enabled\" : true,          // Enables (=true) or disables (=false) the second ControlBlock \n            \"address\" : {               // The address information of the second ControlBlock\n                \"SJ1\" : 1,              // The hardware address solder-jumper SJ1. Options: 0, 1 \n                \"SJ2\" : 0               // The hardware address solder-jumper SJ2, Options: 0, 1\n            },\n            \"gamepadtype\" : \"arcade\",   // Sets the gamepad type. Options: \"arcade\", \"mame\", \"snes\", \"none\"\n            \"onlyOneGamepad\" : false    // If true, registers only one gamepad instead of two\n        }\n    ]\n}\n```\n\n#### Four Player Hardware Setup Example\n\nHere is an image that shows an exemplary 4-player hardware setup:\n\n![Four Player Hardware Setup Example](https://github.com/petrockblog/ControlBlockService2/raw/master/supplementary/4playerCB4.jpg)\n\nThings to note:\n\n 1. The ControlBlock with the interrupted signal lines for the power switch is directly attached to the Raspberry Pi. The other ControlBlock is on top of that.\n 2. If you want to use a power switch, you need to attach the switch and the optional LED to the \"lower\" ControlBlock, which is directly attached to the Raspberry Pi.\n 3. The micro USB connector for the supply power is attached to the lower ControlBlock, which is directly attached to the Raspberry Pi.\n\n## Troubleshooting\n\nIt is important to start with a well defined and working installation. Therefore, I suggest to start with a fresh Raspbian, RetroPie or whatever image and install the ControlBlock driver with only the power switch connected. Follow the steps [as described above for that.\n\nIf that works, you can test the functionality of the arcade button input pins by using a jumper wire that is connected to GND and contacting the various button pins. `jstest /dev/input/js0` gives you the so simulated button presses for player one and `jstest /dev/input/js1` gives you the simulated button presses for player two (You can exit `jstest` with `Ctrl-C`.\n\nIf you find that every input pin is working as expected start with connecting the controls in small steps. For example, first the joysticks, then the buttons for one player, then the ones for the other player. Use `jstest` after every smaller step to verify that things still work as expected.\n\n### Checking the Raw GPIO of the Raspberry\n\nTo check that the GPIOs of the Raspberry Pi itself are working correctly, you can use the bash script `scripts/testRPiGPIO.sh`). You can start it with `./scripts/testRPiGPIO.sh`. Please follow the instructions that are printed to the shell.\n\n\u003cbr\u003e\u003cbr\u003e\n__Have fun!__\n\n-Florian [petrockblock.com](http://blog.petrockblock.com)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpetrockblog%2Fcontrolblockservice2","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpetrockblog%2Fcontrolblockservice2","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpetrockblog%2Fcontrolblockservice2/lists"}