import * as vscode from 'vscode' ; import * as fs from 'fs' ; export function activate ( context ) { console . log ( 'Congratulations, your extension "spikeprime" is now active!' ) ; let NEXT_TERM_ID = 1 ; const terminal = vscode . window . createTerminal ( 'SPIKE PRIME' ) ; let serial = "" ; let disposable = vscode . commands . registerCommand ( 'spikeprime.upload' , async ( ) => { const slot = await vscode . window . showInputBox ( { prompt : 'Which slot should I upload to? (0-19)' } ) ; if ( serial === "" ) { serial = await vscode . window . showInputBox ( { prompt : 'Which port is the hub on? (e.g. COM3, /dev/ttyACM0, /dev/tty.usbserialABC, etc.)' } ) as string ; } console . log ( serial ) ; vscode . window . showInformationMessage ( 'Uploading to hub at ' + serial + ' on slot ' + slot + '.' ) ; var currentlyOpenTabfilePath = vscode . window . activeTextEditor ?. document . uri . fsPath ; terminal . show ( ) ; terminal . show ( true ) ; if ( fs . existsSync ( "/bin/sh" ) ) { vscode . window . showInformationMessage ( "UNIX" ) ; terminal . sendText ( "python3 ~/spiketools/spikejsonrpc.py -t " + serial + " upload '" + currentlyOpenTabfilePath + "' " + slot ) ; } else { vscode . window . showInformationMessage ( "WINDOWS" ) ; terminal . sendText ( "python C:\\\spiketools\\\spikejsonrpc.py -t " + serial + " upload \"" + currentlyOpenTabfilePath + "\" " + slot ) ; } } ) ; let disposable2 = vscode . commands . registerCommand ( 'spikeprime.list' , async ( ) => { if ( serial === "" ) { serial = await vscode . window . showInputBox ( { prompt : 'Which port is the hub on? (e.g. COM3, /dev/ttyACM0, /dev/tty.usbserialABC, etc.)' } ) as string ; } console . log ( serial ) ; vscode . window . showInformationMessage ( 'Working on hub at ' + serial + '.' ) ; var currentlyOpenTabfilePath = vscode . window . activeTextEditor ?. document . uri . fsPath ; terminal . show ( ) ; terminal . show ( true ) ; if ( fs . existsSync ( "/bin/sh" ) ) { vscode . window . showInformationMessage ( "UNIX" ) ; terminal . sendText ( "python3 ~/spiketools/spikejsonrpc.py -t " + serial + " list" ) ; } else { vscode . window . showInformationMessage ( "WINDOWS" ) ; terminal . sendText ( "python C:\\\spiketools\\\spikejsonrpc.py -t " + serial + " list" ) ; } } ) ; let disposable3 = vscode . commands . registerCommand ( 'spikeprime.delete' , async ( ) => { const slot = await vscode . window . showInputBox ( { prompt : 'Which slot should I delete? (0-19)' } ) ; if ( serial === "" ) { serial = await vscode . window . showInputBox ( { prompt : 'Which port is the hub on? (e.g. COM3, /dev/ttyACM0, /dev/tty.usbserialABC, etc.)' } ) as string ; } console . log ( serial ) ; var currentlyOpenTabfilePath = vscode . window . activeTextEditor ?. document . uri . fsPath ; vscode . window . showInformationMessage ( 'Deleting program at hub at ' + serial + ' on slot ' + slot + '.' ) ; terminal . show ( ) ; terminal . show ( true ) ; if ( fs . existsSync ( "/bin/sh" ) ) { vscode . window . showInformationMessage ( "UNIX" ) ; terminal . sendText ( "python3 ~/spiketools/spikejsonrpc.py -t " + serial + " rm " + slot ) ; } else { vscode . window . showInformationMessage ( "WINDOWS" ) ; terminal . sendText ( "python C:\\\spiketools\\\spikejsonrpc.py -t " + serial + " rm " + slot ) ; } } ) ; let disposable4 = vscode . commands . registerCommand ( 'spikeprime.start' , async ( ) => { const slot = await vscode . window . showInputBox ( { prompt : 'Which program slot should I start? (0-19)' } ) ; if ( serial === "" ) { serial = await vscode . window . showInputBox ( { prompt : 'Which port is the hub on? (e.g. COM3, /dev/ttyACM0, /dev/tty.usbserialABC, etc.)' } ) as string ; } console . log ( serial ) ; var currentlyOpenTabfilePath = vscode . window . activeTextEditor ?. document . uri . fsPath ; vscode . window . showInformationMessage ( 'Starting program at hub at ' + serial + ' on slot ' + slot + '.' ) ; terminal . show ( ) ; terminal . show ( true ) ; if ( fs . existsSync ( "/bin/sh" ) ) { vscode . window . showInformationMessage ( "UNIX" ) ; terminal . sendText ( "python3 ~/spiketools/spikejsonrpc.py -t " + serial + " start " + slot + "; python3 ~/spiketools/readserial.py " + serial ) ; } else { vscode . window . showInformationMessage ( "WINDOWS" ) ; terminal . sendText ( "python C:\\\spiketools\\\spikejsonrpc.py -t " + serial + " start " + slot + "; python C:\\\spiketools\\\readserial.py " + serial ) ; } } ) ; let disposable5 = vscode . commands . registerCommand ( 'spikeprime.stop' , async ( ) => { if ( serial === "" ) { serial = await vscode . window . showInputBox ( { prompt : 'Which port is the hub on? (e.g. COM3, /dev/ttyACM0, /dev/tty.usbserialABC, etc.)' } ) as string ; } var currentlyOpenTabfilePath = vscode . window . activeTextEditor ?. document . uri . fsPath ; vscode . window . showInformationMessage ( 'Stopping program at hub at ' + serial + '.' ) ; terminal . show ( ) ; terminal . show ( true ) ; if ( fs . existsSync ( "/bin/sh" ) ) { vscode . window . showInformationMessage ( "UNIX" ) ; terminal . sendText ( "python3 ~/spiketools/spikejsonrpc.py -t " + serial + " stop" ) ; } else { vscode . window . showInformationMessage ( "WINDOWS" ) ; terminal . sendText ( "python C:\\\spiketools\\\spikejsonrpc.py -t " + serial + " stop" ) ; } } ) ; let disposable6 = vscode . commands . registerCommand ( 'spikeprime.move' , async ( ) => { const slot = await vscode . window . showInputBox ( { prompt : 'Which program slot should I move? (0-19)' } ) ; const slot2 = await vscode . window . showInputBox ( { prompt : 'Which program slot should I move it to? (0-19)' } ) ; if ( serial === "" ) { serial = await vscode . window . showInputBox ( { prompt : 'Which port is the hub on? (e.g. COM3, /dev/ttyACM0, /dev/tty.usbserialABC, etc.)' } ) as string ; } var currentlyOpenTabfilePath = vscode . window . activeTextEditor ?. document . uri . fsPath ; terminal . show ( ) ; terminal . show ( true ) ; vscode . window . showInformationMessage ( 'Moving program at hub at ' + serial + ' on slot ' + slot + ' to slot ' + slot2 + '.' ) ; if ( fs . existsSync ( "/bin/sh" ) ) { vscode . window . showInformationMessage ( "UNIX" ) ; terminal . sendText ( "python3 ~/spiketools/spikejsonrpc.py -t " + serial + " mv " + slot + " " + slot2 ) ; } else { vscode . window . showInformationMessage ( "WINDOWS" ) ; terminal . sendText ( "python C:\\\spiketools\\\spikejsonrpc.py -t " + serial + " mv " + slot + " " + slot2 ) ; } } ) ; let disposable7 = vscode . commands . registerCommand ( 'spikeprime.fwinfo' , async ( ) => { if ( serial === "" ) { serial = await vscode . window . showInputBox ( { prompt : 'Which port is the hub on? (e.g. COM3, /dev/ttyACM0, /dev/tty.usbserialABC, etc.)' } ) as string ; } var currentlyOpenTabfilePath = vscode . window . activeTextEditor ?. document . uri . fsPath ; vscode . window . showInformationMessage ( 'Working on hub at ' + serial + '.' ) ; terminal . show ( ) ; terminal . show ( true ) ; if ( fs . existsSync ( "/bin/sh" ) ) { vscode . window . showInformationMessage ( "UNIX" ) ; terminal . sendText ( "python3 ~/spiketools/spikejsonrpc.py -t " + serial + " fwinfo" ) ; } else { vscode . window . showInformationMessage ( "WINDOWS" ) ; terminal . sendText ( "python C:\\\spiketools\\\spikejsonrpc.py -t " + serial + " fwinfo" ) ; } } ) ; let disposable8 = vscode . commands . registerCommand ( 'spikeprime.new' , async ( ) => { const name = await vscode . window . showInputBox ( { prompt : 'What is the name of the file? (e.g. myprogram.py, etc.)' } ) ; var folderpath = vscode . window . activeTextEditor ?. document . uri . fsPath ; vscode . window . showInformationMessage ( 'Creating new program ' + name ) ; terminal . show ( ) ; terminal . show ( true ) ; if ( fs . existsSync ( "/bin/sh" ) ) { vscode . window . showInformationMessage ( "UNIX" ) ; terminal . sendText ( "cp ~/spiketools/hub/program_template.py '" + name + "'" ) ; } else { vscode . window . showInformationMessage ( "WINDOWS" ) ; terminal . sendText ( "copy C:\\\spiketools\\\hub\\\program_template.py \"" + name + "\"" ) ; } } ) ; let disposable9 = vscode . commands . registerCommand ( 'spikeprime.getos' , async ( ) => { if ( fs . existsSync ( "/bin/sh" ) ) { vscode . window . showInformationMessage ( "UNIX" ) ; } else { vscode . window . showInformationMessage ( "WINDOWS" ) ; } } ) ; let disposable10 = vscode . commands . registerCommand ( 'spikeprime.setport' , async ( ) => { serial = await vscode . window . showInputBox ( { prompt : 'Which port is the hub on? (e.g. COM3, /dev/ttyACM0, /dev/tty.usbserialABC, etc.)' } ) as string ; } ) ; context . subscriptions . push ( disposable ) ; context . subscriptions . push ( disposable2 ) ; context . subscriptions . push ( disposable3 ) ; context . subscriptions . push ( disposable4 ) ; context . subscriptions . push ( disposable5 ) ; context . subscriptions . push ( disposable6 ) ; context . subscriptions . push ( disposable7 ) ; context . subscriptions . push ( disposable8 ) ; context . subscriptions . push ( disposable9 ) ; context . subscriptions . push ( disposable10 ) ; } export function deactivate ( ) { }