Created
August 8, 2016 19:48
-
-
Save brantje/563e592c1bcb7e1adb81a9710194316e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"websocket": { | |
"start_embedded_server": true, | |
"server_url": "0.0.0.0:4000", | |
"remote_control": true | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
import lcd | |
import sys | |
lcd = lcd.lcd() | |
lcd.set_addr(0x23) # hier je i2c adres | |
strings = { | |
'login_started': 'Login procedure started.', | |
'location_found': 'Location found: {location} {position}', | |
'load_cached_location': '', | |
'set_start_location': 'Setting start location.', | |
'login_failed': 'Login error, server busy. Waiting 10 seconds to try again.', | |
'login_successful': 'Login successful.', | |
'bot_start': 'Starting bot...', | |
'item_discarded': 'Discarded {amount}x {item}', | |
'pokemon_appeared': 'A wild {pokemon} appeared! [CP {cp}] [Potential {iv}]', | |
'threw_berry': 'Threw a {berry_name}! Catch rate now: {new_catch_rate}', | |
'threw_pokeball': 'Used {pokeball}, with chance {success_percentage}%', | |
'pokemon_caught': 'Captured {pokemon}! [CP {cp}] [Potential {iv}] [+{exp} exp]', | |
'pokemon_fled': 'Attempted to capture {pokemon} - failed.. trying again!', | |
'pokemon_vanished': 'Oh no.. {pokemon} vanished!', | |
'pokemon_release': 'Exchanged {pokemon} [CP {cp}] [IV {iv}] for candy.', | |
'arrived_at_fort': 'Arrived at fort.', | |
'moving_to_lured_fort': 'Moving towards pokestop {fort_name} - {distance}', | |
'moving_to_fort': 'Moving towards pokestop {fort_name} - {distance}', | |
'position_update': 'Now at {current_position}', | |
'softban_fix': 'Got a softban, fixing', | |
'softban_fix_done': 'Softban should be fixed', | |
'egg_hatched': 'Egg hatched with a {{pokemon}}! [CP {cp}]' | |
} | |
def login_started(*args): | |
lcd.message(strings['login_started']) | |
def login_failed(*args): | |
lcd.message(strings['login_failed']) | |
def location_found(*args): | |
print args | |
lcd.message(strings['location_found']) | |
def set_start_location(*args): | |
lcd.message(strings['set_start_location']) | |
def login_successful(*args): | |
lcd.message(strings['login_successful']) | |
def bot_start(*args): | |
lcd.message(strings['bot_start']) | |
def item_discarded(*args): | |
lcd.message(strings['item_discarded'].format( | |
amount=args[0]['amount'], | |
item=args[0]['item'] | |
)) | |
def pokemon_appeared(*args): | |
lcd.message(strings['pokemon_appeared'].format( | |
pokemon=args[0]['pokemon'], | |
cp=args[0]['cp'], | |
iv=args[0]['iv'] | |
)) | |
def threw_berry(*args): | |
lcd.message(strings['threw_berry'].format( | |
berry_name=args[0]['berry_name'], | |
new_catch_rate=args[0]['new_catch_rate'] | |
)) | |
def threw_pokeball(*args): | |
lcd.message(strings['threw_pokeball'].format( | |
pokeball=args[0]['pokeball'], | |
success_percentage=args[0]['success_percentage'] | |
)) | |
def pokemon_fled(*args): | |
lcd.message(strings['pokemon_fled'].format( | |
pokemon=args[0]['pokemon'] | |
)) | |
def pokemon_vanished(*args): | |
lcd.message(strings['pokemon_vanished'].format( | |
pokemon=args[0]['pokemon'] | |
)) | |
def pokemon_caught(*args): | |
lcd.message(strings['pokemon_caught'].format( | |
pokemon=args[0]['pokemon'], | |
exp=args[0]['exp'], | |
cp=args[0]['cp'], | |
iv=args[0]['iv'] | |
)) | |
def pokemon_release(*args): | |
lcd.message(strings['pokemon_release'].format( | |
pokemon=args[0]['pokemon'], | |
iv=args[0]['iv'], | |
cp=args[0]['cp'] | |
)) | |
def arrived_at_fort(*args): | |
lcd.message(strings['arrived_at_fort']) | |
def spun_pokestop(*args): | |
pokestop = (args[0]['pokestop'][:20]) if len(args[0]['pokestop']) > 20 else args[0]['pokestop'] | |
lcd.write_line('Now at Pokestop:', 1) | |
lcd.write_line(pokestop, 2) | |
lcd.write_line('Spinning...', 3) | |
# logger.log('Now at Pokestop: {0}'.format(fort_name), 'cyan') | |
# logger.log('Spinning ...', 'cyan') | |
time.sleep(2) | |
rewards = ['+' + str(args[0]['exp']) + 'xp'] | |
for item, amount in args[0]['items'].iteritems(): | |
rewards.append(str(amount) + 'x ' + item) | |
lcd.message('Rewards: ' + ', '.join(rewards)) | |
# Rewards: + 50xp ..... | |
def moving_to_lured_fort(*args): | |
pokestop = (args[0]['fort_name'][:20]) if len(args[0]['fort_name']) > 20 else args[0]['fort_name'] | |
lcd.message(strings['moving_to_lured_fort'].format( | |
fort_name=pokestop, | |
distance=str(args[0]['distance']) | |
)) | |
def moving_to_fort(*args): | |
pokestop = (args[0]['fort_name'][:20]) if len(args[0]['fort_name']) > 20 else args[0]['fort_name'] | |
distance = (args[0]['distance']) if (args[0]['distance']) else '' | |
lcd.message(strings['moving_to_lured_fort'].format( | |
fort_name=pokestop, | |
distance=str(distance) | |
)) | |
def position_update(*args): | |
lcd.message(strings['position_update']) | |
def incubate(*args): | |
lcd.message(args[0]['msg']) | |
time.sleep(2) | |
def next_egg_incubates(*args): | |
lcd.message(args[0]['msg']) | |
time.sleep(3) | |
def egg_hatched(*args): | |
# : 'Egg hatched with a {{pokemon}}! [CP {cp}]' | |
line1 = strings['egg_hatched'].format( | |
pokemon=args[0]['pokemon'], | |
cp=args[0]['cp'] | |
) | |
line2 = 'Reward: ' | |
line3 = str(args[0]['cp']) + 'x, candy +' + str(args[0]['exp']) + ' exp' | |
line4 = str(args[0]['stardust']) + ' stardus' | |
lcd.write_line(line1, 1) | |
lcd.write_line(line2, 2) | |
lcd.write_line(line3, 3) | |
lcd.write_line(line4, 4) | |
def softban_fix(*args): | |
lcd.message(strings['softban_fix']) | |
def softban_fix_done(*args): | |
lcd.message(strings['softban_fix_done']) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
""" | |
Compiled, mashed and generally mutilated 2014-2015 by Denis Pleic | |
Made available under GNU GENERAL PUBLIC LICENSE | |
# Modified Python I2C library for Raspberry Pi | |
# as found on http://www.recantha.co.uk/blog/?p=4849 | |
# Joined existing 'i2c_lib.py' and 'lcddriver.py' into a single library | |
# added bits and pieces from various sources | |
# By DenisFromHR (Denis Pleic) | |
# 2015-02-10, ver 0.1 | |
""" | |
import os | |
from itertools import islice | |
from time import * | |
import smbus | |
class i2c_device: | |
def __init__(self, addr, port=1): | |
self.addr = addr | |
self.bus = smbus.SMBus(port) | |
# Write a single command | |
def write_cmd(self, cmd): | |
self.bus.write_byte(self.addr, cmd) | |
sleep(0.0001) | |
# Write a command and argument | |
def write_cmd_arg(self, cmd, data): | |
self.bus.write_byte_data(self.addr, cmd, data) | |
sleep(0.0001) | |
# Write a block of data | |
def write_block_data(self, cmd, data): | |
self.bus.write_block_data(self.addr, cmd, data) | |
sleep(0.0001) | |
# Read a single byte | |
def read(self): | |
return self.bus.read_byte(self.addr) | |
# Read | |
def read_data(self, cmd): | |
return self.bus.read_byte_data(self.addr, cmd) | |
# Read a block of data | |
def read_block_data(self, cmd): | |
return self.bus.read_block_data(self.addr, cmd) | |
# LCD Address | |
# ADDRESS = 0x27 | |
LCD_WIDTH = 20 | |
LCD_HEIGHT = 2 | |
LCD_CHARS = [0x40, 0x48, 0x50, 0x58, 0x60, 0x68, 0x70, 0x78] # Address position for custom chars | |
# Use char generator here: https://omerk.github.io/lcdchargen/ or http://www.quinapalus.com/hd44780udg.html | |
# commands | |
LCD_CLEARDISPLAY = 0x01 | |
LCD_RETURNHOME = 0x02 | |
LCD_ENTRYMODESET = 0x04 | |
LCD_DISPLAYCONTROL = 0x08 | |
LCD_CURSORSHIFT = 0x10 | |
LCD_FUNCTIONSET = 0x20 | |
LCD_SETCGRAMADDR = 0x40 | |
LCD_SETDDRAMADDR = 0x80 | |
# flags for display entry mode | |
LCD_ENTRYRIGHT = 0x00 | |
LCD_ENTRYLEFT = 0x02 | |
LCD_ENTRYSHIFTINCREMENT = 0x01 | |
LCD_ENTRYSHIFTDECREMENT = 0x00 | |
# flags for display on/off control | |
LCD_DISPLAYON = 0x04 | |
LCD_DISPLAYOFF = 0x00 | |
LCD_CURSORON = 0x02 | |
LCD_CURSOROFF = 0x00 | |
LCD_BLINKON = 0x01 | |
LCD_BLINKOFF = 0x00 | |
# flags for display/cursor shift | |
LCD_DISPLAYMOVE = 0x08 | |
LCD_CURSORMOVE = 0x00 | |
LCD_MOVERIGHT = 0x04 | |
LCD_MOVELEFT = 0x00 | |
# flags for function set | |
LCD_8BITMODE = 0x10 | |
LCD_4BITMODE = 0x00 | |
LCD_2LINE = 0x08 | |
LCD_1LINE = 0x00 | |
LCD_5x10DOTS = 0x04 | |
LCD_5x8DOTS = 0x00 | |
# flags for backlight control | |
LCD_BACKLIGHT = 0x08 | |
LCD_NOBACKLIGHT = 0x00 | |
En = 0b00000100 # Enable bit | |
Rw = 0b00000010 # Read/Write bit | |
Rs = 0b00000001 # Register select bit | |
class lcd: | |
# initializes objects and lcd | |
# def __init__(self, adress): | |
def set_addr(self, adress): | |
self.lcd_device = i2c_device(adress) | |
self.lcd_write(0x03) | |
self.lcd_write(0x03) | |
self.lcd_write(0x03) | |
self.lcd_write(0x02) | |
self.lcd_write(LCD_FUNCTIONSET | LCD_2LINE | LCD_5x8DOTS | | |
LCD_4BITMODE) | |
self.displaycontrol = LCD_DISPLAYON | LCD_CURSOROFF | LCD_BLINKOFF | |
self.lcd_write(LCD_DISPLAYCONTROL | LCD_DISPLAYON | LCD_BLINKOFF) | |
self.lcd_write(LCD_CLEARDISPLAY) | |
self.lcd_write(LCD_ENTRYMODESET | LCD_ENTRYLEFT) | |
def show_cursor(self, show): | |
"""Show or hide the cursor. Cursor is shown if show is True.""" | |
if show: | |
self.displaycontrol |= LCD_CURSORON | |
else: | |
self.displaycontrol &= ~LCD_CURSORON | |
self.lcd_write(LCD_DISPLAYCONTROL | self.displaycontrol) | |
def blink(self, blink): | |
"""Turn on or off cursor blinking. Set blink to True to enable blinking.""" | |
if blink: | |
self.displaycontrol |= LCD_BLINKON | |
else: | |
self.displaycontrol &= ~LCD_BLINKON | |
self.lcd_write(LCD_DISPLAYCONTROL | self.displaycontrol) | |
# clocks EN to latch command | |
def lcd_strobe(self, data): | |
self.lcd_device.write_cmd(data | En | LCD_BACKLIGHT) | |
sleep(.0005) | |
self.lcd_device.write_cmd(((data & ~En) | LCD_BACKLIGHT)) | |
sleep(.0001) | |
def lcd_write_four_bits(self, data): | |
self.lcd_device.write_cmd(data | LCD_BACKLIGHT) | |
self.lcd_strobe(data) | |
# write a command to lcd | |
def lcd_write(self, cmd, mode=0): | |
self.lcd_write_four_bits(mode | (cmd & 0xF0)) | |
self.lcd_write_four_bits(mode | ((cmd << 4) & 0xF0)) | |
# write a character to lcd (or character rom) 0x09: backlight | RS=DR< | |
# works! | |
def lcd_write_char(self, charvalue, mode=1): | |
self.lcd_write_four_bits(mode | (charvalue & 0xF0)) | |
self.lcd_write_four_bits(mode | ((charvalue << 4) & 0xF0)) | |
def message(self, message, style=1, speed=1): | |
"""Send a message to the display, use \n for new line""" | |
# style=1 Left justified | |
# style=2 Centred | |
# style=3 Right justified | |
# style=4 typing | |
self.clear() | |
words = iter(message.split()) | |
lines, current = [], next(words) | |
for word in words: | |
if len(current) + 1 + len(word) > LCD_WIDTH: | |
lines.append(current) | |
current = word | |
else: | |
current += " " + word | |
lines.append(current) | |
for (idx, line) in enumerate(lines): | |
if idx == 0: | |
self.lcd_write(0x80) | |
if idx == 1: | |
self.lcd_write(0xC0) | |
if idx == 2: | |
self.lcd_write(0x94) | |
if idx == 3: | |
self.lcd_write(0xD4) | |
for char in line: | |
self.lcd_write(ord(char), Rs) | |
def type_string(self, message, line, speed=0.3, style=1, blink=True): | |
"""Type like a type machine""" | |
# style=1 Left justified | |
# style=2 Centred | |
# style=3 Right justified | |
if line == 1: | |
self.lcd_write(0x80) | |
if line == 2: | |
self.lcd_write(0xC0) | |
if line == 3: | |
self.lcd_write(0x94) | |
if line == 4: | |
self.lcd_write(0xD4) | |
if style == 0x01: | |
message = message.ljust(LCD_WIDTH, '') | |
elif style == 0x02: | |
message = message.center(LCD_WIDTH, '') | |
elif style == 3: | |
message = message.rjust(LCD_WIDTH, '') | |
for i in range(len(message)): | |
self.lcd_write(ord(message[i]), Rs) | |
sleep(speed) | |
def split_every(self, n, iterable): | |
i = iter(iterable) | |
piece = list(islice(i, n)) | |
while piece: | |
yield piece | |
piece = list(islice(i, n)) | |
def filler(self, str1, str2): | |
len1 = len(str1) | |
len2 = len(str2) | |
left = LCD_WIDTH - len1 - len2 | |
fill = ' ' * left | |
return str1 + fill + str2 | |
# put string function | |
def write_line(self, string, line, style=1): | |
if line == 1: | |
self.lcd_write(0x80) | |
if line == 2: | |
self.lcd_write(0xC0) | |
if line == 3: | |
self.lcd_write(0x94) | |
if line == 4: | |
self.lcd_write(0xD4) | |
if style == 0x01: | |
string = string.ljust(LCD_WIDTH, ' ') | |
elif style == 0x02: | |
string = string.center(LCD_WIDTH, ' ') | |
elif style == 3: | |
string = string.rjust(LCD_WIDTH, ' ') | |
for char in string: | |
self.lcd_write(ord(char), Rs) | |
# clear lcd and set to home | |
def clear(self): | |
self.lcd_clear() | |
def lcd_clear(self): | |
self.lcd_write(LCD_CLEARDISPLAY) | |
self.lcd_write(LCD_RETURNHOME) | |
# define backlight on/off (lcd.backlight(1); off= lcd.backlight(0) | |
def backlight(self, state): # for state, 1 = on, 0 = off | |
if state == 1: | |
self.lcd_device.write_cmd(LCD_BACKLIGHT) | |
elif state == 0: | |
self.lcd_device.write_cmd(LCD_NOBACKLIGHT) | |
# add custom characters (0 - 7) | |
def createChar(self, charPos, charDef): | |
self.lcd_write(LCD_CHARS[charPos], 0) | |
for line in charDef: | |
self.lcd_write(line, 1) | |
def lcd_display_string_pos(self, string, line, pos): | |
if line == 1: | |
pos_new = pos | |
elif line == 2: | |
pos_new = 0x40 + pos | |
elif line == 3: | |
pos_new = 0x14 + pos | |
elif line == 4: | |
pos_new = 0x54 + pos | |
self.lcd_write(0x80 + pos_new) | |
for char in string: | |
self.lcd_write(ord(char), Rs) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from socketIO_client import SocketIO | |
import logging | |
from eventHandler import * | |
playername = 'superstoner' | |
io = SocketIO('127.0.0.1', 4000) | |
events = [ | |
'login_started', | |
'login_failed', | |
'location_found', | |
'set_start_location', | |
'login_successful', | |
'login_failed', | |
'bot_start', | |
'item_discarded', | |
'pokemon_appeared', | |
'threw_pokeball', | |
'threw_berry', | |
'pokemon_caught', | |
'pokemon_fled', | |
'pokemon_release', | |
'arrived_at_fort', | |
'spun_pokestop', | |
'moving_to_lured_fort', | |
'moving_to_fort', | |
'egg_hatched', | |
'next_egg_incubates', | |
'incubate' | |
] | |
for event in events: | |
io.on(event + ':' + playername, globals()[event]) | |
io.wait() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment