jfpayeur.com‎ > ‎

NESRap : Nintendo controller for 3dPrinter



 +





Lets face it, Pronterface is a really nice and versatile GUI to control and upload G-Code
to your favorite 3d-Printer . But the usage of mouse clicks to manually control your printer
is counterintuitive and inefficient. Pronterface Simply Lack the ability  to  add short-cut to improve this (for now).                                                                                                                 


Pronterface: 


I've found other way to accomplish my project on the web , but they generally involved building your physical remote controller from scratch with switches on a PCB and playing around to send serial commands to the printer with an external uC or directly on the Ramps pcb :
I wanted a simpler way to do it, And I already Had a Nintendo USB remote ready to be used.

They nicest thing about this project is that it is really simple to adapt to any other usb HID windows compatible joystick or even simply your keyboard.

This is where Autohotkey kicks in.  Autohotkey alows you to intercept about any keyboard, mice, or joystick events (or any combinason of the above) and emulate mouse moves and put scripts in between. It create resident script that can run in background. 

This script pop-back  pronterface if the windows is hiden so it allow's you to control the printer even if you leaved another windows in top of pronterface the last time you were on the computer.  The script will stop if pronteface is not running. The emulated mouse clicks are relative to the pronterface app itself, so it should not click else were that intended if the proterface app is moved on the screen. BUT from a pronterface version to another GUI might change and the script might need some tweek





My requirement was to get my NES controller to control intituitivly my printer. So here are the basic function. (notice key combinations )













Demo Video:

NESRap






The Code:

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
CoordMode, ToolTip, Relative ; Set coord relative to active software,  Was already by default , but never to shure


;////////////My input from USB joystick settings//////////////
; x=0   gauche
; x=50  centre
; x=100 droite
; y=0   haut
; y=50  centre
; y=100 bas
; select = 9
; start = 10
; B = 3
; A = 2

;////////Code goal ///////////////
;Joystick   ----> Normal speed X-Y
;B+Joystick ----> Turbo  speed X-Y
;A+Joystick ----> Z Up-down
;SEL        ----> Extrude
;Start      ----> Go home

;/////////HELP//////////////
;jfpayeur.com
;http://ahkscript.org/docs/Tutorial.htm
;http://www.autohotkey.com/docs/commands/Click.htm
;http://www.autohotkey.com/docs/misc/RemapJoystick.htm


#Persistent  ; Keep this script running until the user explicitly exits it.
SetTimer, WatchAxis, 10
return


WatchAxis:
 GetKeyState, JoyX      ,JoyX  ; Get position of X axis.
 GetKeyState, JoyY      ,JoyY  ; Get position of Y axis.
 GetKeyState, JoySelect ,Joy9  ; Get position of
 GetKeyState, JoyStart  ,Joy10 ; Get position of Start
 GetKeyState, JoyA      ,Joy2  ; Get position of
 GetKeyState, JoyB      ,Joy3  ; Get position of

 if JoyStart=D
 {
  gosub,PopupPronterface
  Click 61,309 ;Go home
 }

 if JoySelect =D
 {
  gosub,PopupPronterface
  Click 100,400 ;Extrude
 }


;////////// X on joystick////////////
 if JoyX =0
 {
   if JoyB =D    ;turbo
   {
     gosub,PopupPronterface
     Click 240 ,210
   }
   else
   {
     gosub,PopupPronterface
     Click 210 ,210
   }
 }
 if JoyX =100
 {
   if JoyB =D    ;turbo
   {
     gosub,PopupPronterface
     Click 80 ,210
   }
   else
   {
     gosub,PopupPronterface
     Click 100 ,210
   }
 }


;////////// Y on joystick ////////////
 if JoyY =0
 {
   if JoyB =D    ;turbo 
   {
     gosub,PopupPronterface
     Click 157,135
   }
   else
   {
     if JoyA =D    ;Up-Down
     {
       gosub,PopupPronterface
       Click 310,170
     }
     else{
       gosub,PopupPronterface
       Click 157,157
     }
   }

 }
 if JoyY =100
 {
   if JoyB =D   ;turbo
   {
     gosub,PopupPronterface
     Click 157,284
   }
   else
   {
     if JoyA =D    ;Up-Down
     {
       gosub,PopupPronterface
       Click 310,240
     }
     else{
       gosub,PopupPronterface
       Click 157,260
     }
   }
 }
return  ; Do nothing.


PopupPronterface:
   IfWinExist Pronterface
   {
      WinActivate
      WinWaitActive, Pronterface
   }
   else
   {
      MsgBox,, NESRap, Can't find pronterface. Please Open Pronterface first.,

   }
return








       













ċ
NESRap.ahk
(3k)
Jean-François Payeur,
Feb 18, 2015, 7:21 PM
Comments