-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
312 additions
and
39 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
const { execSync } = require('child_process'); | ||
var fs = require('fs'); | ||
|
||
|
||
console.log('Building Client') | ||
console.log(run_cmd('yarn webbuild')) | ||
// copyFile('./dist/index.html', './build/index.html') | ||
|
||
console.log('Building Server') | ||
console.log(run_cmd('pyinstaller -F ./server.spec', path = "./server")) | ||
copyFile('./server/dist/server.exe', './build/vTablet.exe') | ||
|
||
|
||
console.log('Finished!') | ||
|
||
function run_cmd(cmd, path = './') { | ||
return execSync(cmd,{stdio:[0,1,2], cwd: path}) | ||
} | ||
|
||
function copyFile(src, dist) { | ||
fs.writeFileSync(dist, fs.readFileSync(src)); | ||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
# coding=utf-8 | ||
from ctypes import CDLL, c_uint64, c_char, c_double, c_ushort, windll | ||
import mouse | ||
import json | ||
import sys | ||
import pyautogui | ||
import os.path | ||
from simple_http_server import WebsocketHandler, WebsocketRequest, WebsocketSession, websocket_handler, request_map | ||
import simple_http_server.server as server | ||
|
||
DATA_PATH = os.path.split(os.path.realpath(__file__))[0] | ||
CLIENT_FILE = os.path.join(DATA_PATH, "index.html") | ||
HEIGHT, WIDTH = pyautogui.size() | ||
SETTING_FILE = "settings.json" | ||
|
||
VMULTI_DLL = CDLL(os.path.join(DATA_PATH, 'vTabletDriverDll.dll')) | ||
|
||
class VMulti: | ||
def __init__(self): | ||
try: | ||
VMULTI_DLL.vMulti_connect.restype = c_uint64 | ||
self.controller = VMULTI_DLL.vMulti_connect() | ||
print(self.controller) | ||
except: | ||
print('no vMulti devices') | ||
pass | ||
def update_digi(self, x, y, p, b): | ||
if not self.is_connected(): | ||
return False | ||
VMULTI_DLL.vMulti_updateDigi(c_uint64(self.controller), c_ushort(x), c_ushort(y), c_double(p), c_char(b)) | ||
def is_connected(self): | ||
return VMULTI_DLL.vMulti_isOpened(c_uint64(self.controller)) | ||
|
||
vmulti = VMulti() | ||
|
||
def save_setting(data): | ||
with open(SETTING_FILE, 'w') as f: | ||
f.write(data) | ||
print("Saved") | ||
|
||
|
||
def load_setting(): | ||
data = "" | ||
if os.path.isfile(SETTING_FILE): | ||
with open(SETTING_FILE) as f: | ||
data = f.read() | ||
return data | ||
|
||
|
||
# Client | ||
@request_map("/") | ||
def frontend_ctroller_function(): | ||
data = "" | ||
if os.path.isfile(CLIENT_FILE): | ||
with open(CLIENT_FILE, 'r', encoding='utf-8') as f: | ||
data = f.read() | ||
return data | ||
|
||
|
||
# WS server | ||
@websocket_handler(endpoint="/ws") | ||
class WSHandler(WebsocketHandler): | ||
|
||
def on_handshake(self, request: WebsocketRequest): | ||
return 0, {} | ||
|
||
def on_open(self, session: WebsocketSession): | ||
print(">> Connected! ") | ||
# print(session.request.path_values) | ||
|
||
def on_close(self, session: WebsocketSession, reason: str): | ||
print(">> Closeed Connect::") | ||
# print(reason) | ||
|
||
def on_text_message(self, session: WebsocketSession, message: str): | ||
# print(">> Got text message: ") | ||
# print(message) | ||
|
||
data = json.loads(message) | ||
|
||
if data["type"] == "move": | ||
# print(float(data['x']) * HEIGHT, float(data['y']) * WIDTH) | ||
mouse.move(float(data['x']) * HEIGHT, float(data['y']) * WIDTH) | ||
|
||
elif data["type"] == "click": | ||
if data["action"] == "down": | ||
mouse.press() | ||
elif data["action"] == "up": | ||
mouse.release() | ||
|
||
elif data["type"] == "digi": | ||
x = data['x'] | ||
y = data['y'] | ||
pressure = data['pressure'] | ||
bottom = data['bottom'] | ||
print(x, y, pressure, bottom) | ||
is_success = vmulti.update_digi(x, y, pressure, bottom) | ||
|
||
elif data["type"] == "save_setting": | ||
save_setting(data["setting"]) | ||
|
||
elif data["type"] == "load_setting": | ||
session.send(json.dumps({"setting": load_setting()})) | ||
return | ||
|
||
|
||
def main(*args): | ||
server.start(port=8888) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# -*- mode: python ; coding: utf-8 -*- | ||
|
||
|
||
block_cipher = None | ||
|
||
|
||
a = Analysis(['server.py'], | ||
pathex=[], | ||
binaries=[], | ||
datas=[("vTabletDriverDll.dll",'.'), ('../dist/index.html', '.')], | ||
hiddenimports=[], | ||
hookspath=[], | ||
hooksconfig={}, | ||
runtime_hooks=[], | ||
excludes=[], | ||
win_no_prefer_redirects=False, | ||
win_private_assemblies=False, | ||
cipher=block_cipher, | ||
noarchive=False) | ||
pyz = PYZ(a.pure, a.zipped_data, | ||
cipher=block_cipher) | ||
|
||
exe = EXE(pyz, | ||
a.scripts, | ||
a.binaries, | ||
a.zipfiles, | ||
a.datas, | ||
[], | ||
name='server', | ||
debug=False, | ||
bootloader_ignore_signals=False, | ||
strip=False, | ||
upx=True, | ||
upx_exclude=[], | ||
runtime_tmpdir=None, | ||
console=True, | ||
disable_windowed_traceback=False, | ||
target_arch=None, | ||
codesign_identity=None, | ||
entitlements_file=None ) |
Binary file not shown.
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
Oops, something went wrong.