{"size": 923, "ext": "js", "max_stars_repo_path": "js/led_managers/led_manager.js", "max_stars_repo_name": "Pimentoso/mini4wdchrono", "max_stars_repo_stars_event_min_datetime": "2019-08-20T19:32:00.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-11T21:38:45.000Z", "max_issues_repo_path": "js/led_managers/led_manager.js", "max_issues_repo_name": "Pimentoso/mini4wdchrono", "max_issues_repo_issues_event_min_datetime": "2019-06-30T14:46:06.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-25T18:29:38.000Z", "max_forks_repo_path": "js/led_managers/led_manager.js", "max_forks_repo_name": "Pimentoso/mini4wdchrono", "max_forks_repo_forks_event_min_datetime": "2020-07-15T21:48:02.000Z", "max_forks_repo_forks_event_max_datetime": "2020-07-15T21:48:02.000Z"}
{"max_stars_count": 6, "max_issues_count": 57, "max_forks_count": 1, "avg_line_length": 17.4150943396, "max_line_length": 77, "alphanum_fraction": 0.6359696641}
'use strict';

const j5 = require('johnny-five');
const utils = require('../utils');
const storage = require('../storage');

class LedManager {
	constructor(board, pinBuzzer) {
		this.board = board;
		this.pinBuzzer = pinBuzzer;
	}

	connected() {
		this.board.pinMode(this.pinBuzzer, j5.Pin.OUTPUT);
		this.beep(100);
	}

	disconnected() {
		try {
			this.board.digitalWrite(this.pinBuzzer, 0);
		} catch (e) { }
	}

	roundStart() {
		throw 'not implemented';
	}

	roundFinish(cars) {
		throw 'not implemented';
	}

	lap(lane) {
		throw 'not implemented';
	}

	beep(millis) {
		this.board.digitalWrite(this.pinBuzzer, 1);
		utils.delay(() => { this.board.digitalWrite(this.pinBuzzer, 0); }, millis);
	}

	greenDelay() {
		if (storage.get('raceMode') == 1) {
			// if final mode, delay is random between 0.25/4 sec
			return 250 + (Math.random() * 3750);
		}
		else {
			return 1500;
		}
	}
}

module.exports = LedManager;
