diff --git a/README.md b/README.md new file mode 100644 index 0000000..ee36cef --- /dev/null +++ b/README.md @@ -0,0 +1,18 @@ +# b0xx-input-viewer + +The B0XX Input Viewer uses electron-serialport and is derived from one if its examples. To install this dependency follow the following instruction and move the node-modules from electron-serialport into the main directory. It can then be run using npm start and compiled. + +To clone and run this repository you'll need [Git](https://git-scm.com) and [Node.js](https://nodejs.org/en/download/) (which comes with [npm](http://npmjs.com)) installed on your computer. From your command line: + +```bash +# Clone this repository +git clone https://github.com/serialport/electron-serialport.git +# Go into the repository +cd electron-serialport +# Install dependencies +npm install +# Run the app +npm start +``` + +This app may be used by third parties with disclosure. It is easy to change the background by simply changing bg.png. Layout changes are done by changing the images (assigned to each button) as they are just layered and shown and masked accordingly. diff --git a/icons/B0XX.icns b/icons/B0XX.icns new file mode 100644 index 0000000..d8b63e4 Binary files /dev/null and b/icons/B0XX.icns differ diff --git a/icons/Contents.json b/icons/Contents.json new file mode 100644 index 0000000..b32bc8b --- /dev/null +++ b/icons/Contents.json @@ -0,0 +1,68 @@ +{ + "images" : [ + { + "idiom" : "mac", + "size" : "16x16", + "scale" : "1x", + "filename" : "icon_16@1x.png" + }, + { + "idiom" : "mac", + "size" : "16x16", + "scale" : "2x", + "filename" : "icon_16@2x.png" + }, + { + "idiom" : "mac", + "size" : "32x32", + "scale" : "1x", + "filename" : "icon_32@1x.png" + }, + { + "idiom" : "mac", + "size" : "32x32", + "scale" : "2x", + "filename" : "icon_32@2x.png" + }, + { + "idiom" : "mac", + "size" : "128x128", + "scale" : "1x", + "filename" : "icon_128@1x.png" + }, + { + "idiom" : "mac", + "size" : "128x128", + "scale" : "2x", + "filename" : "icon_128@2x.png" + }, + { + "idiom" : "mac", + "size" : "256x256", + "scale" : "1x", + "filename" : "icon_256@1x.png" + }, + { + "idiom" : "mac", + "size" : "256x256", + "scale" : "2x", + "filename" : "icon_256@2x.png" + }, + { + "idiom" : "mac", + "size" : "512x512", + "scale" : "1x", + "filename" : "icon_512@1x.png" + }, + { + "idiom" : "mac", + "size" : "512x512", + "scale" : "2x", + "filename" : "icon_512@2x.png" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/icons/icon_128@1x.png b/icons/icon_128@1x.png new file mode 100644 index 0000000..e13066a Binary files /dev/null and b/icons/icon_128@1x.png differ diff --git a/icons/icon_128@2x.png b/icons/icon_128@2x.png new file mode 100644 index 0000000..de084e4 Binary files /dev/null and b/icons/icon_128@2x.png differ diff --git a/icons/icon_16@1x.png b/icons/icon_16@1x.png new file mode 100644 index 0000000..3c1633c Binary files /dev/null and b/icons/icon_16@1x.png differ diff --git a/icons/icon_16@2x.png b/icons/icon_16@2x.png new file mode 100644 index 0000000..6aaa8fe Binary files /dev/null and b/icons/icon_16@2x.png differ diff --git a/icons/icon_256@1x.png b/icons/icon_256@1x.png new file mode 100644 index 0000000..de084e4 Binary files /dev/null and b/icons/icon_256@1x.png differ diff --git a/icons/icon_256@2x.png b/icons/icon_256@2x.png new file mode 100644 index 0000000..a5d8da5 Binary files /dev/null and b/icons/icon_256@2x.png differ diff --git a/icons/icon_32@1x.png b/icons/icon_32@1x.png new file mode 100644 index 0000000..6aaa8fe Binary files /dev/null and b/icons/icon_32@1x.png differ diff --git a/icons/icon_32@2x.png b/icons/icon_32@2x.png new file mode 100644 index 0000000..3d3eade Binary files /dev/null and b/icons/icon_32@2x.png differ diff --git a/icons/icon_512@1x.png b/icons/icon_512@1x.png new file mode 100644 index 0000000..a5d8da5 Binary files /dev/null and b/icons/icon_512@1x.png differ diff --git a/icons/icon_512@2x.png b/icons/icon_512@2x.png new file mode 100644 index 0000000..e94f6d3 Binary files /dev/null and b/icons/icon_512@2x.png differ diff --git a/images/A.png b/images/A.png new file mode 100644 index 0000000..c5578b9 Binary files /dev/null and b/images/A.png differ diff --git a/images/B.png b/images/B.png new file mode 100644 index 0000000..2d31555 Binary files /dev/null and b/images/B.png differ diff --git a/images/B0XX.icns b/images/B0XX.icns new file mode 100644 index 0000000..d117ffa Binary files /dev/null and b/images/B0XX.icns differ diff --git a/images/B0XX.ico b/images/B0XX.ico new file mode 100644 index 0000000..19a8c30 Binary files /dev/null and b/images/B0XX.ico differ diff --git a/images/B0XX_256.ico b/images/B0XX_256.ico new file mode 100644 index 0000000..ffa74ce Binary files /dev/null and b/images/B0XX_256.ico differ diff --git a/images/CD.png b/images/CD.png new file mode 100644 index 0000000..d699c78 Binary files /dev/null and b/images/CD.png differ diff --git a/images/CL.png b/images/CL.png new file mode 100644 index 0000000..d87745f Binary files /dev/null and b/images/CL.png differ diff --git a/images/CR.png b/images/CR.png new file mode 100644 index 0000000..11cb7ee Binary files /dev/null and b/images/CR.png differ diff --git a/images/CU.png b/images/CU.png new file mode 100644 index 0000000..6ad2db3 Binary files /dev/null and b/images/CU.png differ diff --git a/images/DN.png b/images/DN.png new file mode 100644 index 0000000..b9aaaf8 Binary files /dev/null and b/images/DN.png differ diff --git a/images/L.png b/images/L.png new file mode 100644 index 0000000..45388f8 Binary files /dev/null and b/images/L.png differ diff --git a/images/LS.png b/images/LS.png new file mode 100644 index 0000000..a333b02 Binary files /dev/null and b/images/LS.png differ diff --git a/images/LT.png b/images/LT.png new file mode 100644 index 0000000..0d739ef Binary files /dev/null and b/images/LT.png differ diff --git a/images/M1.png b/images/M1.png new file mode 100644 index 0000000..6b3f4f5 Binary files /dev/null and b/images/M1.png differ diff --git a/images/M2.png b/images/M2.png new file mode 100644 index 0000000..4209fca Binary files /dev/null and b/images/M2.png differ diff --git a/images/MS.png b/images/MS.png new file mode 100644 index 0000000..578617a Binary files /dev/null and b/images/MS.png differ diff --git a/images/R.png b/images/R.png new file mode 100644 index 0000000..86f953f Binary files /dev/null and b/images/R.png differ diff --git a/images/R2.png b/images/R2.png new file mode 100644 index 0000000..d7ba2a5 Binary files /dev/null and b/images/R2.png differ diff --git a/images/RT.png b/images/RT.png new file mode 100644 index 0000000..7462f9e Binary files /dev/null and b/images/RT.png differ diff --git a/images/ST.png b/images/ST.png new file mode 100644 index 0000000..5ef48a1 Binary files /dev/null and b/images/ST.png differ diff --git a/images/UP.png b/images/UP.png new file mode 100644 index 0000000..64cba45 Binary files /dev/null and b/images/UP.png differ diff --git a/images/X.png b/images/X.png new file mode 100644 index 0000000..b8b328b Binary files /dev/null and b/images/X.png differ diff --git a/images/Y.png b/images/Y.png new file mode 100644 index 0000000..896170c Binary files /dev/null and b/images/Y.png differ diff --git a/images/Z.png b/images/Z.png new file mode 100644 index 0000000..0a716bf Binary files /dev/null and b/images/Z.png differ diff --git a/images/bg.png b/images/bg.png new file mode 100644 index 0000000..892c1f4 Binary files /dev/null and b/images/bg.png differ diff --git a/images/recconect.png b/images/recconect.png new file mode 100644 index 0000000..a6b2322 Binary files /dev/null and b/images/recconect.png differ diff --git a/index.html b/index.html new file mode 100644 index 0000000..9b406a2 --- /dev/null +++ b/index.html @@ -0,0 +1,46 @@ + + + + + + B0XX Input Viewer + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + +
+ + + diff --git a/main.js b/main.js new file mode 100644 index 0000000..39ede2e --- /dev/null +++ b/main.js @@ -0,0 +1,71 @@ +const electron = require('electron') +// Module to control application life. +const app = electron.app +// Module to create native browser window. +const BrowserWindow = electron.BrowserWindow; + +//var usbDetect = require('usb-detection'); + +const path = require('path') +const url = require('url') + +// Keep a global reference of the window object, if you don't, the window will +// be closed automatically when the JavaScript object is garbage collected. +let mainWindow + +function createWindow() { + // Create the browser window. + mainWindow = new BrowserWindow({ + width: 1600, + height: 840, + resizable : true, + autoHideMenuBar: true, + webPreferences: { + nodeIntegration: true, // to allow require + contextIsolation: false, // allow use with Electron 12+ + preload: path.join(__dirname, 'preload.js') + } + }) + + // and load the index.html of the app. + mainWindow.loadURL(url.format({ + pathname: path.join(__dirname, 'index.html'), + protocol: 'file:', + slashes: true + })) + + // Open the DevTools. + //mainWindow.webContents.openDevTools() + + + // Emitted when the window is closed. + mainWindow.on('closed', function() { + // Dereference the window object, usually you would store windows + // in an array if your app supports multi windows, this is the time + // when you should delete the corresponding element. + mainWindow = null + }) +} + +// This method will be called when Electron has finished +// initialization and is ready to create browser windows. +// Some APIs can only be used after this event occurs. +app.on('ready', createWindow) + +// Quit when all windows are closed. +app.on('window-all-closed', function() { + // On OS X it is common for applications and their menu bar + // to stay active until the user quits explicitly with Cmd + Q + app.quit() +}) + +app.on('activate', function() { + // On OS X it's common to re-create a window in the app when the + // dock icon is clicked and there are no other windows open. + if (mainWindow === null) { + createWindow() + } +}) + +// In this file you can include the rest of your app's specific main process +// code. You can also put them in separate files and require them here. diff --git a/package.json b/package.json new file mode 100644 index 0000000..479e621 --- /dev/null +++ b/package.json @@ -0,0 +1,28 @@ +{ + "name": "B0XX", + "version": "1.0.0", + "description": "B0XX Input Viewer using NodeJS and Electron.", + "main": "main.js", + "scripts": { + "start": "electron ." + }, + "repository": { + "url": "https://b0xx.com/pages/resources" + }, + "keywords": [ + "B0XX", + "Input", + "Viewer", + "Game", + "Controller" + ], + "author": "20XX Corp", + "license": "GNU-LGPL-2.1", + "devDependencies": { + "electron": "^17.0.0" + }, + "dependencies": { + "serialport": "^10.3.0", + "tableify": "^1.1.1" + } +} diff --git a/preload.js b/preload.js new file mode 100644 index 0000000..bc97b37 --- /dev/null +++ b/preload.js @@ -0,0 +1,10 @@ +// All of the Node.js APIs are available in the preload process. +// It has the same sandbox as a Chrome extension. +window.addEventListener('DOMContentLoaded', () => { + for (const versionType of['chrome', 'electron', 'node']) { + document.getElementById(`${versionType}-version`).innerText = process.versions[versionType] + } + + document.getElementById('serialport-version').innerText = require('serialport/package').version + +}) \ No newline at end of file diff --git a/serial.js b/serial.js new file mode 100644 index 0000000..9ae9f9a --- /dev/null +++ b/serial.js @@ -0,0 +1,97 @@ + +//const SerialPort = require('serialport') +//var serialport = require("serialport"); +//var SerialPort = serialport.SerialPort; + +//const SerialPort = require('serialport'); + +const { SerialPort } = require('serialport') +const { ReadlineParser } = require('@serialport/parser-readline') + +//const Readline = SerialPort.parsers.Readline; +//const { dialog } = require('electron') + + +function serialCon(){ + SerialPort.list().then(ports => { + var port = ports.find(port => (/2341/.test(port.vendorId) && /8036/.test(port.productId)) || (/2E8A/.test(port.vendorId) && /102F/.test(port.productId))) + + if (!port) { + console.log("B0XX Not Found") + //console.log(dialog.showMessageBox(mainWindow, {message: "B0XX Not Found"})) + //const response = dialog.showMessageBox(null); + //console.log(response); + document.getElementById('recon').style.visibility='visible'; + } + else { + console.log("B0XX Found") + console.log(port) + console.log(port.vendorId) + console.log(comport) + var comport = port.path; + + try{ + var myPort = new SerialPort({ + path: comport, + baudRate: 115200 + //delimiter: '\n' + //parser: SerialPort.parsers.readline('\n') + }); + + const parser = myPort.pipe(new ReadlineParser({delimiter: '\n'})) + parser.on('data', onData); + myPort.on('close', onClose); + document.getElementById('recon').style.visibility='hidden'; + } + + catch (err){ + console.log("issue opening comport"); + } + + } + }) +} + +document.getElementById("recon").addEventListener("click", reconButton); +serialCon(); + +function reconButton(){ + serialCon(); +} + +function onData(data){ + //console.log(data); + //if(data.charAt(0) === '1')document.getElementById('abtn').style.visibility='visible'; + //else document.getElementById('abtn').style.visibility='hidden'; + showhide('stbtn', data.charAt(0)); + showhide('ybtn', data.charAt(1)); + showhide('xbtn', data.charAt(2)); + showhide('bbtn', data.charAt(3)); + showhide('abtn', data.charAt(4)); + showhide('lbtn', data.charAt(5)); + showhide('rbtn', data.charAt(6)); + showhide('zbtn', data.charAt(7)); + showhide('upbtn', data.charAt(8)); + showhide('dnbtn', data.charAt(9)); + showhide('rtbtn', data.charAt(10)); + showhide('ltbtn', data.charAt(11)); + showhide('m1btn', data.charAt(12)); + showhide('m2btn', data.charAt(13)); + showhide('clbtn', data.charAt(14)); + showhide('crbtn', data.charAt(15)); + showhide('cubtn', data.charAt(16)); + showhide('cdbtn', data.charAt(17)); + showhide('lsbtn', data.charAt(18)); + showhide('msbtn', data.charAt(19)); + showhide('r2', data.charAt(23)); +} + +function showhide(imgname, vis){ + if(vis === '1')document.getElementById(imgname).style.visibility='visible'; + else document.getElementById(imgname).style.visibility='hidden'; +} + +function onClose(){ + //console.log('Closed') + document.getElementById('recon').style.visibility='visible'; +} diff --git a/style.css b/style.css new file mode 100644 index 0000000..b855fb2 --- /dev/null +++ b/style.css @@ -0,0 +1,32 @@ +body { + background-color: black; + overflow-x: hidden; +} + +img { + width: 100%; + height: auto; + + position: absolute; + top:0; + + margin-left: auto; + margin-right: auto; +} + +.button { + background-color: aqua; + border: none; + color: white; + padding: 15px 25px; + text-align: center; + font-size: 16px; + cursor: pointer; + top:0; + left:0; + position: absolute; +} + +.button:hover { + background-color: #0099cc; +}