
import socket
import atexit
import pygame
from message import Message


PRECISION = 3

host = "localhost"
port = 9999

# create a socket object and connect to specified host/port
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((host, port))


def close_socket():
    s.close()


def send_message(controller, type, index, value):
    m = Message()
    m.controller_index = controller
    m.input_type = type
    m.input_index = index
    m.input_value = value

    s.send(bytes(m))

    response = s.recv(1024)
    print(response.decode('ascii'))


atexit.register(close_socket)

pygame.init()
pygame.joystick.init()
stick = pygame.joystick.Joystick(0)
stick.init()

done = False
controller = 0
type = 0

while done is False:
    for event in pygame.event.get():
        value = None

        if event.type == pygame.QUIT:
            done = True
        elif event.type == pygame.JOYAXISMOTION:
            index = event.axis
            value = round(event.value, PRECISION)

        if value is not None:
            send_message(controller, type, index, value)


import socket
import atexit
import pygame
from message import Message


PRECISION = 3

host = "192.168.0.1"
port = 9999

# create a socket object and connect to specified host/port
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((host, port))


def close_socket():
    s.close()


def send_message(controller, type, index, value):
    m = Message()
    m.controller_index = controller
    m.input_type = type
    m.input_index = index
    m.input_value = value

    s.send(bytes(m))

    response = s.recv(1024)
    print(response.decode('ascii'))


atexit.register(close_socket)

pygame.init()
pygame.joystick.init()
stick = pygame.joystick.Joystick(0)
stick.init()

done = False
controller = 0
type = 0

while done is False:
    for event in pygame.event.get():
        value = None

        if event.type == pygame.QUIT:
            done = True
        elif event.type == pygame.JOYAXISMOTION:
            index = event.axis
            value = round(event.value, PRECISION)

        if value is not None:
            send_message(controller, type, index, value)

Update host to use Pi’s static address
Update host to use Pi’s static address

  
  import socket
  import atexit
  import pygame
  from message import Message
  
  
  PRECISION = 3
  
- host = "localhost"
+ host = "192.168.0.1"
  port = 9999
  
  # create a socket object and connect to specified host/port
  s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  s.connect((host, port))
  
  
  def close_socket():
      s.close()
  
  
  def send_message(controller, type, index, value):
      m = Message()
      m.controller_index = controller
      m.input_type = type
      m.input_index = index
      m.input_value = value
  
      s.send(bytes(m))
  
      response = s.recv(1024)
      print(response.decode('ascii'))
  
  
  atexit.register(close_socket)
  
  pygame.init()
  pygame.joystick.init()
  stick = pygame.joystick.Joystick(0)
  stick.init()
  
  done = False
  controller = 0
  type = 0
  
  while done is False:
      for event in pygame.event.get():
          value = None
  
          if event.type == pygame.QUIT:
              done = True
          elif event.type == pygame.JOYAXISMOTION:
              index = event.axis
              value = round(event.value, PRECISION)
  
          if value is not None:
              send_message(controller, type, index, value)
  
Update host to use Pi’s static address
## Code Before:

import socket
import atexit
import pygame
from message import Message


PRECISION = 3

host = "localhost"
port = 9999

# create a socket object and connect to specified host/port
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((host, port))


def close_socket():
    s.close()


def send_message(controller, type, index, value):
    m = Message()
    m.controller_index = controller
    m.input_type = type
    m.input_index = index
    m.input_value = value

    s.send(bytes(m))

    response = s.recv(1024)
    print(response.decode('ascii'))


atexit.register(close_socket)

pygame.init()
pygame.joystick.init()
stick = pygame.joystick.Joystick(0)
stick.init()

done = False
controller = 0
type = 0

while done is False:
    for event in pygame.event.get():
        value = None

        if event.type == pygame.QUIT:
            done = True
        elif event.type == pygame.JOYAXISMOTION:
            index = event.axis
            value = round(event.value, PRECISION)

        if value is not None:
            send_message(controller, type, index, value)

## Instruction:
Update host to use Pi’s static address
## Code After:

import socket
import atexit
import pygame
from message import Message


PRECISION = 3

host = "192.168.0.1"
port = 9999

# create a socket object and connect to specified host/port
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((host, port))


def close_socket():
    s.close()


def send_message(controller, type, index, value):
    m = Message()
    m.controller_index = controller
    m.input_type = type
    m.input_index = index
    m.input_value = value

    s.send(bytes(m))

    response = s.recv(1024)
    print(response.decode('ascii'))


atexit.register(close_socket)

pygame.init()
pygame.joystick.init()
stick = pygame.joystick.Joystick(0)
stick.init()

done = False
controller = 0
type = 0

while done is False:
    for event in pygame.event.get():
        value = None

        if event.type == pygame.QUIT:
            done = True
        elif event.type == pygame.JOYAXISMOTION:
            index = event.axis
            value = round(event.value, PRECISION)

        if value is not None:
            send_message(controller, type, index, value)
