<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>gamepad | Learn C Games Programming Blog</title>
	<atom:link href="https://learncgames.com/tag/gamepad/feed/" rel="self" type="application/rss+xml" />
	<link>https://learncgames.com</link>
	<description>A blog about C, programming games and my ebook(s).</description>
	<lastBuildDate>Sun, 17 May 2020 08:24:09 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>

<image>
	<url>https://learncgames.com/wp-content/uploads/2020/03/cropped-favicon-32x32.png</url>
	<title>gamepad | Learn C Games Programming Blog</title>
	<link>https://learncgames.com</link>
	<width>32</width>
	<height>32</height>
</image> 
<site xmlns="com-wordpress:feed-additions:1">181446779</site>	<item>
		<title>Success with gamepad mappings</title>
		<link>https://learncgames.com/success-with-gamepad-mappings/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=success-with-gamepad-mappings</link>
		
		<dc:creator><![CDATA[David]]></dc:creator>
		<pubDate>Thu, 14 May 2020 23:00:55 +0000</pubDate>
				<category><![CDATA[C]]></category>
		<category><![CDATA[Game]]></category>
		<category><![CDATA[raspberry-pi]]></category>
		<category><![CDATA[Source code]]></category>
		<category><![CDATA[gamepad]]></category>
		<guid isPermaLink="false">https://learncgames.com/?p=587</guid>

					<description><![CDATA[<p>My ploy with running gamepad-tool on the Linux laptop worked and I was able to get the correct mappings to use in my game. Though weirdly it seems to have X and Y buttons mixed up as well as A and B. In the end I hard-coded the mapping string and set it up with [&#8230;]</p>
The post <a href="https://learncgames.com/success-with-gamepad-mappings/">Success with gamepad mappings</a> first appeared on <a href="https://learncgames.com">Learn C Games Programming Blog</a>.]]></description>
										<content:encoded><![CDATA[<div class='__iawmlf-post-loop-links' style='display:none;' data-iawmlf-post-links='[{&quot;id&quot;:726,&quot;href&quot;:&quot;https:\/\/pixabay.com\/users\/cobain86-840406\/?utm_source=link-attribution&amp;utm_medium=referral&amp;utm_campaign=image&amp;utm_content=5048166&quot;,&quot;archived_href&quot;:&quot;&quot;,&quot;redirect_href&quot;:&quot;&quot;,&quot;checks&quot;:[],&quot;broken&quot;:false,&quot;last_checked&quot;:null,&quot;process&quot;:&quot;done&quot;},{&quot;id&quot;:727,&quot;href&quot;:&quot;https:\/\/pixabay.com\/?utm_source=link-attribution&amp;utm_medium=referral&amp;utm_campaign=image&amp;utm_content=5048166&quot;,&quot;archived_href&quot;:&quot;http:\/\/web-wp.archive.org\/web\/20260205102120\/https:\/\/pixabay.com\/?utm_source=link-attribution&quot;,&quot;redirect_href&quot;:&quot;&quot;,&quot;checks&quot;:[{&quot;date&quot;:&quot;2026-02-06 17:55:01&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-02-09 22:44:06&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-02-15 15:04:26&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-02-19 12:08:17&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-02-26 09:54:22&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-03-01 15:07:29&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-03-08 13:20:41&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-04-09 02:27:37&quot;,&quot;http_code&quot;:403}],&quot;broken&quot;:true,&quot;last_checked&quot;:{&quot;date&quot;:&quot;2026-04-09 02:27:37&quot;,&quot;http_code&quot;:403},&quot;process&quot;:&quot;done&quot;}]'></div>
<figure id="attachment_589" aria-describedby="caption-attachment-589" style="width: 300px" class="wp-caption alignleft"><img decoding="async" class="size-medium wp-image-589" src="https://learncgames.com/wp-content/uploads/2020/05/controller-5048166_640-300x150.png" alt="SNES Gamepad" width="300" height="150" srcset="https://learncgames.com/wp-content/uploads/2020/05/controller-5048166_640-300x150.png 300w, https://learncgames.com/wp-content/uploads/2020/05/controller-5048166_640.png 640w" sizes="(max-width: 300px) 100vw, 300px" /><figcaption id="caption-attachment-589" class="wp-caption-text">Image by <a href="https://pixabay.com/users/cobain86-840406/?utm_source=link-attribution&amp;utm_medium=referral&amp;utm_campaign=image&amp;utm_content=5048166">Marco Sberveglieri</a> from <a href="https://pixabay.com/?utm_source=link-attribution&amp;utm_medium=referral&amp;utm_campaign=image&amp;utm_content=5048166">Pixabay</a></figcaption></figure>
<p>My ploy with running gamepad-tool on the Linux laptop worked and I was able to get the correct mappings to use in my game. Though weirdly it seems to have X and Y buttons mixed up as well as A and B.</p>
<p>In the end I hard-coded the mapping string and set it up with this code:</p>
<pre><code class="language-c" data-line="">	if (SDL_GameControllerAddMapping(&quot;030000001008000001e5000010010000,NEXT SNES Controller2,platform:Linux,a:b2,b:b1,x:b3,y:b0,back:b8,start:b9,leftshoulder:b4,rightshoulder:b5,dpup:-a1,dpdown:+a1,dpleft:-a0,dpright:+a0&quot;)==-1){
		LogError(&quot;Unable to load gamepad mappings from gamepad.txt&quot;);
	}</code></pre>
<p>Then in my ProcessEvents() function which handles I/O events, I added this code:</p>
<pre><code class="language-c" data-line="">			case SDL_CONTROLLERBUTTONDOWN:
			if (event.cbutton.state== SDL_PRESSED){
				switch(event.cbutton.button){
					case SDL_CONTROLLER_BUTTON_A:
					    fireFlag =1;
					    break;
					case SDL_CONTROLLER_BUTTON_B:						
					    jumpFlag =1;
					    break;
					case SDL_CONTROLLER_BUTTON_X:
					    shieldFlag =1;
					    break;
					case SDL_CONTROLLER_BUTTON_Y:						
					    thrustFlag =1;
					    break;						
					case SDL_CONTROLLER_BUTTON_LEFTSHOULDER:
					    rotateFlag = 1;
					    break;
					case SDL_CONTROLLER_BUTTON_RIGHTSHOULDER:
					    rotateFlag= 2;				
					    break;
					}
				}</code></pre>
<p>There&#8217;s similar code for the SDL_CONTROLLERBUTTONUP except it checks for the state = SDL_RELEASED and in the switch statement it sets each flag to 0. So inspite of the code, it&#8217;s the Y button that does shields and the X button does thrust, B button fires and A button does the hyper space jump.</p>The post <a href="https://learncgames.com/success-with-gamepad-mappings/">Success with gamepad mappings</a> first appeared on <a href="https://learncgames.com">Learn C Games Programming Blog</a>.]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">587</post-id>	</item>
		<item>
		<title>More on Raspberry Pi Gamepad</title>
		<link>https://learncgames.com/more-on-raspberry-pi-gamepad/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=more-on-raspberry-pi-gamepad</link>
		
		<dc:creator><![CDATA[David]]></dc:creator>
		<pubDate>Wed, 13 May 2020 23:00:16 +0000</pubDate>
				<category><![CDATA[hardware]]></category>
		<category><![CDATA[raspberry-pi]]></category>
		<category><![CDATA[gamepad]]></category>
		<category><![CDATA[gamepadtool]]></category>
		<category><![CDATA[jstest]]></category>
		<category><![CDATA[jstest-gtk]]></category>
		<guid isPermaLink="false">https://learncgames.com/?p=581</guid>

					<description><![CDATA[<p>Unfortunately there&#8217;s no gamepad-tool for the PI, but there is a program called jstest and in particular a visual one called jstest-gtk. That&#8217;s it on the left. You install it on any Linux system, including Raspbian on the Pi with the command sudo apt install jstest-gtk Then run it with a jstest-gtk command from a [&#8230;]</p>
The post <a href="https://learncgames.com/more-on-raspberry-pi-gamepad/">More on Raspberry Pi Gamepad</a> first appeared on <a href="https://learncgames.com">Learn C Games Programming Blog</a>.]]></description>
										<content:encoded><![CDATA[<p><img fetchpriority="high" decoding="async" class="alignleft size-full wp-image-582" src="https://learncgames.com/wp-content/uploads/2020/05/jstest-gtk.png" alt="jstest-gtk" width="306" height="614" srcset="https://learncgames.com/wp-content/uploads/2020/05/jstest-gtk.png 306w, https://learncgames.com/wp-content/uploads/2020/05/jstest-gtk-150x300.png 150w" sizes="(max-width: 306px) 100vw, 306px" />Unfortunately there&#8217;s no gamepad-tool for the PI, but there is a program called jstest and in particular a visual one called jstest-gtk. That&#8217;s it on the left. You install it on any Linux system, including Raspbian on the Pi with the command</p>
<pre><code class="language-c" data-line="">sudo apt install jstest-gtk</code></pre>
<p>Then run it with a <em>jstest-gtk</em> command from a terminal.</p>
<p>It then detects your game pad and responds to button presses and joystick movements.</p>
<p>The weird thing is although my gamepad identifies it as a NEXT SNES but so far attempts to load that have not been successful in the Asteroids game. It loads but doesn&#8217;t seem to work and its not recognising the right shoulder button and has A and B buttons muddled up. Yet in jstest, it is clearly able to identify them.</p>
<p>Time I think to create a mapping under Linux with gamepadtool. Unfortunately it doesn&#8217;t work on the Hyper-V Ubuntu so it&#8217;s time to fetch my Linux laptop and try it on that.</p>
<p>&nbsp;</p>The post <a href="https://learncgames.com/more-on-raspberry-pi-gamepad/">More on Raspberry Pi Gamepad</a> first appeared on <a href="https://learncgames.com">Learn C Games Programming Blog</a>.]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">581</post-id>	</item>
	</channel>
</rss>
