<commit_before>'use strict';
const inquirer = require('inquirer');
const prg = require('./lib/program');
const img = require('./lib/image');
const show = require('./lib/show');
const ctrl = require('./lib/control');
const utils = require('./lib/utils');

let client = null;

var mainMenu = [
  {
    type: 'rawlist',
    name: 'selection',
		message: 'Poi Commander',
		pageSize: 12,
    	choices: [
		 	{ 
	      		name: 'Connect',
				value: 'connect'
			},
			{ 
	      		name: 'Disconnect',
				value: 'disconnect'
			},
			{
				name: 'Upload show', 
			 	value:'up_show'
		 	} ,
			{
	   			name: 'Upload image with id 0', 
		    	value:'up_image'
			} ,
			{
	   			name: 'Upload program', 
		    	value:'up_prog'
			} ,
			{
				 name: 'Connect poi to wifi', 
				 value:'wifi_connect'
			},
			{
				name: 'Disconnect poi from wifi', 
				value:'wifi_disconnect'
		    } ,
			{
				 name: 'Start program', 
				 value:'start_prog'
			} ,
			{
	   			name: 'Stop program', 
				value:'stop_prog'
			} ,
			{
	   			name: 'Sync', 
		    	value:'sync'
			},
			{
				name: 'Exit', 
			 	value:'exit'
		 	} 
		]
  },
  {
    type: 'input',
    name: 'filename',
    message: 'Filename:',
    when: function(answers) {
      return (["up_image", "up_prog", "up_show"].includes(answers.selection));
    }
  },
  {
    type: 'input',
    name: 'ip_incr',
    message: 'IP increment:',
    default: '0',
    when: function(answers) {
      return (answers.selection == "wifi_connect");
	}
  },
  {
    type: 'input',
    name: 'sync_point',
    message: getSyncs,
    default: '0',
    when: function(answers) {
      return (answers.selection == "sync");
	}
  }
]

function getSyncs(){
	var str = "Choose sync point: ";
	const syncs = prg.getSyncMap();
	for (let i in syncs) {
		str = str.concat(i + ":" + syncs[i] + " ");
	}
	
	return str;
}

function handleError(err) {
	console.log("Error: " + err.message);
	main();
}

function main(){
	inquirer.prompt(mainMenu).then(answer => {
		// console.log(answer);
		if (answer.selection === "connect") {
			utils.checkNotConnected(client) 
			.then(() => {
				console.log("Connecting...");
				const SerialClient = require("./lib/serialclient");
				client = new SerialClient("COM4");
				return client.connect();
			})
			.then(main)
			.catch(handleError);
		}

		else if (answer.selection === "disconnect") {
			utils.checkConnected(client) 
			.then((client) => {
				return client.disconnect();
			})
			.then(main)
			.catch(handleError);

		}
		else if (answer.selection === "up_show") {
			utils.checkConnected(client) 
			.then(() => {
				return show.uploadShow(client, answer.filename);
			})
			.then(main)
			.catch(handleError);
		}
		else if (answer.selection === "up_prog") {
			utils.checkConnected(client) 
			.then(() => {
				return prg.uploadPrograms(client, [answer.filename]);
			})
			.then(main)
			.catch(handleError);
		}
		else if (answer.selection === "up_image") {
			utils.checkConnected(client) 
			.then(() => {
				return img.uploadImage(client, 0, answer.filename);
			})
			.then(main)
			.catch(handleError);
		}
		else if (answer.selection === "wifi_connect") {
			utils.checkConnected(client) 
			.then((client) => {
		  		return ctrl.connectWifi(client, parseInt(answer.ip_incr));
			})<commit_msg>add default fikenames<commit_after>'use strict';
const inquirer = require('inquirer');
const prg = require('./lib/program');
const img = require('./lib/image');
const show = require('./lib/show');
const ctrl = require('./lib/control');
const utils = require('./lib/utils');

let client = null;
const config = {};

var mainMenu = [
  {
    type: 'rawlist',
    name: 'selection',
		message: 'Poi Commander',
		pageSize: 12,
    	choices: [
		 	{ 
	      		name: 'Connect',
				value: 'connect'
			},
			{ 
	      		name: 'Disconnect',
				value: 'disconnect'
			},
			{
				name: 'Upload show', 
			 	value:'up_show'
		 	} ,
			{
	   			name: 'Upload image with id 0', 
		    	value:'up_image'
			} ,
			{
	   			name: 'Upload program', 
		    	value:'up_prog'
			} ,
			{
				 name: 'Connect poi to wifi', 
				 value:'wifi_connect'
			},
			{
				name: 'Disconnect poi from wifi', 
				value:'wifi_disconnect'
		    } ,
			{
				 name: 'Start program', 
				 value:'start_prog'
			} ,
			{
	   			name: 'Stop program', 
				value:'stop_prog'
			} ,
			{
	   			name: 'Sync', 
		    	value:'sync'
			},
			{
				name: 'Exit', 
			 	value:'exit'
		 	} 
		]
  },
  {
    type: 'input',
    name: 'filename',
    message: 'Filename:',
    default: getDefaultFilename,
    when: function(answers) {
      return (["up_image", "up_prog", "up_show"].includes(answers.selection));
    }
  },
  {
    type: 'input',
    name: 'ip_incr',
    message: 'IP increment:',
    default: '0',
    when: function(answers) {
      return (answers.selection == "wifi_connect");
	}
  },
  {
    type: 'input',
    name: 'sync_point',
    message: getSyncs,
    default: '0',
    when: function(answers) {
      return (answers.selection == "sync");
	}
  }
]

function getDefaultFilename(answers) {
	switch (answers.selection) {
		case "up_image":
			return config.image;
		case "up_prog":
			return config.prog;
 		case "up_show":
			return config.show;
		default:
			return "";
	}
}


function getSyncs(){
	var str = "Choose sync point: ";
	const syncs = prg.getSyncMap();
	for (let i in syncs) {
		str = str.concat(i + ":" + syncs[i] + " ");
	}
	
	return str;
}

function handleError(err) {
	console.log("Error: " + err.message);
	main();
}

function main(){
	inquirer.prompt(mainMenu).then(answer => {
		// console.log(answer);
		if (answer.selection === "connect") {
			utils.checkNotConnected(client) 
			.then(() => {
				console.log("Connecting...");
				const SerialClient = require("./lib/serialclient");
				client = new SerialClient("COM4");
				return client.connect();
			})
			.then(main)
			.catch(handleError);
		}

		else if (answer.selection === "disconnect") {
			utils.checkConnected(client) 
			.then((client) => {
				return client.disconnect();
			})
			.then(main)
			.catch(handleError);

		}
		else if (answer.selection === "up_show") {
			utils.checkConnected(client) 
			.then(() => {
				return show.uploadShow(client, answer.filename);
			})
			.then(() => {
				config.show = answer.filename;
			})
			.then(main)
			.catch(handleError);
		}
		else if (answer.selection === "up_prog") {
			utils.checkConnected(client) 
			.then(() => {
				return prg.uploadPrograms(client, [answer.filename]);
			})
			.then(() => {
				config.prog = answer.filename;
			})
			.then(main)
			.catch(handleError);
		}
		else if (answer.selection === "up_image") {
			utils.checkConnected(client) 
			.then(() => {
				return img.uploadImage(client, 0, answer.filename);
			})
			.then(() => {
				config.image = answer.filename;
			})
			.then(main)
			.catch(handleError);
		}
		else if (answer.selection === "wifi_connect") {
			utils.checkConnected(client) 
			.then((client) => {
		  		return ctrl.connectWifi(client, parseInt(answer.ip_incr));
			})
{'fraction_non_alphanumeric': 0.1766628766344514, 'fraction_numerical': 0.001989766913018761, 'mean_word_length': 2.651790347690711, 'pattern_counts': {'":': 5, '<': 3, '<?xml version=': 0, '>': 20, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1734500', 'n_tokens_mistral': 2987, 'n_tokens_neox': 2493, 'n_words': 475}