Java Code Examples for org.pmw.tinylog.Logger#info()

The following examples show how to use org.pmw.tinylog.Logger#info() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GsonAnimationTest.java    From diozero with MIT License 6 votes vote down vote up
private static void animate(Collection<OutputDeviceInterface> targets, int fps, EasingFunction easing, float speed,
		String... files) throws IOException {
	Animation anim = new Animation(targets, fps, easing, speed);

	Gson gson = new Gson();
	for (String file : files) {
		try (Reader reader = new InputStreamReader(GsonAnimationTest.class.getResourceAsStream(file))) {
			AnimationInstance anim_obj = gson.fromJson(reader, AnimationInstance.class);

			anim.enqueue(anim_obj);
		}
	}
	
	Logger.info("Starting animation...");
	Future<?> future = anim.play();
	try {
		Logger.info("Waiting");
		future.get();
		Logger.info("Finished");
	} catch (CancellationException | ExecutionException | InterruptedException e) {
		Logger.info("Finished {}", e);
	}
}
 
Example 2
Source File: Hexapod.java    From diozero with MIT License 6 votes vote down vote up
private void testRange() {
	Logger.info("Testing servo ranges for all servos");
	int delay = 10;
	float delta = 5;
	for (OutputDeviceCollection servos : Arrays.asList(l2, r2, l3, coxae, femura, tibiae, legs)) {
		for (float angle=trim.getMidAngle(); angle<trim.getMaxAngle(); angle+=delta) {
			servos.setValue(angle);
			SleepUtil.sleepMillis(delay);
		}
		for (float angle=trim.getMaxAngle(); angle>trim.getMinAngle(); angle-=delta) {
			servos.setValue(angle);
			SleepUtil.sleepMillis(delay);
		}
		for (float angle=trim.getMinAngle(); angle<trim.getMidAngle(); angle+=delta) {
			servos.setValue(angle);
			SleepUtil.sleepMillis(delay);
		}
	}
}
 
Example 3
Source File: LedBarGraphTest.java    From diozero with MIT License 6 votes vote down vote up
private static void test(int[] gpios) {
	int delay = 10;
	
	int duration = 4000;
	float[] cue_points = new float[] { 0, 0.5f, 1 };
	List<KeyFrame[]> key_frames = KeyFrame.fromValues(new float[][] { {0}, {1f}, {0} });
	try (MCP23008 expander = new MCP23008();
			LedBarGraph led_bar_graph = new LedBarGraph(expander, gpios)) {
		Animation anim = new Animation(Arrays.asList(led_bar_graph), 50, Sine::easeIn, 1f);
		anim.setLoop(true);
		anim.enqueue(duration, cue_points, key_frames);
		anim.play();
		
		Logger.info("Sleeping for {} seconds", Integer.valueOf(delay));
		SleepUtil.sleepSeconds(delay);
	}
}
 
Example 4
Source File: PCF8591App.java    From diozero with MIT License 6 votes vote down vote up
private static void test(int adcPin) {
	try (PCF8591 adc = new PCF8591()) {
		adc.setOutputEnabledFlag(true);
		float[] v = new float[4];
		boolean high = true;
		while (true) {
			if (high) {
				adc.setValue(0, 1);
				high = false;
			} else {
				adc.setValue(0, 0);
				high = true;
			}
			for (int i=0; i<v.length; i++) {
				v[i] = adc.getValue(i);
			}
			Logger.info(String.format("Pin 0: %.2f; Pin 1: %.2f; Pin 2: %.2f; Pin 3: %.2f",
					Float.valueOf(v[0]), Float.valueOf(v[1]), Float.valueOf(v[2]), Float.valueOf(v[3])));
			
			SleepUtil.sleepSeconds(1);
		}
	}
}
 
Example 5
Source File: BeagleBoneBoardInfoProvider.java    From diozero with MIT License 6 votes vote down vote up
@Override
public int getPwmChip(int pwmNum) {
	// FIXME How to work this out? Temporarily hardcode to GPIO 50 (EHRPWM1A, P9_14)
	String chip = "48302000";
	String address = "48302200";
	
	Path chip_path = Paths.get("/sys/devices/platform/ocp/" + chip + ".epwmss/" + address + ".pwm/pwm");
	int pwm_chip = -1;
	// FIXME Treat as a stream
	try (DirectoryStream<Path> dirs = Files.newDirectoryStream(chip_path, "pwm*")) {
		for (Path p : dirs) {
			String dir = p.getFileName().toString();
			Logger.info("Got {}" + dir);
			pwm_chip = Integer.parseInt(dir.substring(dir.length()-1));
			Logger.info("Found pwmChip {}", Integer.valueOf(pwm_chip));
		}
	} catch (IOException e) {
		Logger.error(e, "Error: " + e);
	}
	
	return pwm_chip;
}
 
Example 6
Source File: MilliNanoTest.java    From diozero with MIT License 6 votes vote down vote up
@Test
public void test() {
	double secs = 0.005123;
	
	long millis = Math.round(secs * SleepUtil.MS_IN_SEC);
	long nanos = Math.round(secs * SleepUtil.NS_IN_SEC % SleepUtil.NS_IN_MS);
	
	Logger.info(String.format("Seconds = %.9f, millis = %d, nanos = %d",
			Double.valueOf(secs), Long.valueOf(millis), Long.valueOf(nanos)));
	
	secs = 0.099789;
	
	millis = Math.round(secs * SleepUtil.MS_IN_SEC);
	nanos = Math.round(secs * SleepUtil.NS_IN_SEC % SleepUtil.NS_IN_MS);
	
	Logger.info(String.format("Seconds = %.9f, millis = %d, nanos = %d",
			Double.valueOf(secs), Long.valueOf(millis), Long.valueOf(nanos)));
	
	secs = 99.099789;
	
	millis = Math.round(secs * SleepUtil.MS_IN_SEC);
	nanos = Math.round(secs * SleepUtil.NS_IN_SEC % SleepUtil.NS_IN_MS);
	
	Logger.info(String.format("Seconds = %.9f, millis = %d, nanos = %d",
			Double.valueOf(secs), Long.valueOf(millis), Long.valueOf(nanos)));
}
 
Example 7
Source File: PigpioJDeviceFactory.java    From diozero with MIT License 6 votes vote down vote up
private int setPwmFrequency(int gpio, int pwmFrequency) {
	int old_freq = pigpioImpl.getPWMFrequency(gpio);
	int old_range = pigpioImpl.getPWMRange(gpio);
	int old_real_range = pigpioImpl.getPWMRealRange(gpio);
	pigpioImpl.setPWMFrequency(gpio, pwmFrequency);
	pigpioImpl.setPWMRange(gpio, pigpioImpl.getPWMRealRange(gpio));
	int new_freq = pigpioImpl.getPWMFrequency(gpio);
	int new_range = pigpioImpl.getPWMRange(gpio);
	int new_real_range = pigpioImpl.getPWMRealRange(gpio);
	Logger.info(
			"setPwmFrequency({}, {}), old freq={}, old real range={}, old range={},"
					+ " new freq={}, new real range={}, new range={}",
			Integer.valueOf(gpio), Integer.valueOf(pwmFrequency), Integer.valueOf(old_freq),
			Integer.valueOf(old_real_range), Integer.valueOf(old_range), Integer.valueOf(new_freq),
			Integer.valueOf(new_real_range), Integer.valueOf(new_range));

	return new_range;
}
 
Example 8
Source File: MFRC522Test.java    From diozero with MIT License 6 votes vote down vote up
private static void waitForCard(int controller, int chipSelect, int resetPin) {
		try (MFRC522 mfrc522 = new MFRC522(controller, chipSelect, resetPin)) {
//			if (mfrc522.performSelfTest()) {
//				Logger.debug("Self test passed");
//			} else {
//				Logger.debug("Self test failed");
//			}
			// Wait for a card
			MFRC522.UID uid = null;
			while (uid == null) {
				Logger.info("Waiting for a card");
				uid = getID(mfrc522);
				Logger.debug("uid: {}", uid);
				SleepUtil.sleepSeconds(1);
			}
		}
	}
 
Example 9
Source File: SysFsPwmOutputDevice.java    From diozero with MIT License 5 votes vote down vote up
protected void setPolarity(Polarity polarity) {
	Logger.info("setPolarity(" + polarity + ")");
	try (FileWriter writer = new FileWriter(pwmRoot.resolve("polarity").toFile())) {
		writer.write(polarity.getValue());
		writer.flush();
	} catch (IOException e) {
		Logger.error(e, "Error setting polarity to {}: {}", polarity.getValue(), e);
	}
}
 
Example 10
Source File: Pi4jPwmOutputDevice.java    From diozero with MIT License 5 votes vote down vote up
@Override
public void setValue(float value) throws RuntimeIOException {
	this.value = value;
	switch (pwmType) {
	case HARDWARE:
		Logger.info("Pi4j Hardware PWM write " + (Math.round(value * range)));
		Gpio.pwmWrite(gpio, Math.round(value * range));
		break;
	case SOFTWARE:
		SoftPwm.softPwmWrite(gpio, Math.round(value * range));
		break;
	}
}
 
Example 11
Source File: HCSR04Test.java    From diozero with MIT License 5 votes vote down vote up
@Test
public void test() {
	try (HCSR04 hcsr04 = new HCSR04(26, 4)) {
		for (int i=0; i<6; i++) {
			float distance = hcsr04.getDistanceCm();
			Logger.info("Distance={}", Float.valueOf(distance));
			SleepUtil.sleepSeconds(0.5);
		}
	}
}
 
Example 12
Source File: WiringPiPwmOutputDevice.java    From diozero with MIT License 5 votes vote down vote up
@Override
public void setValue(float value) throws RuntimeIOException {
	this.value = value;
	int dc = (int) Math.floor(value * range);
	switch (pwmType) {
	case HARDWARE:
		Logger.info("setValue({}), range={}, dc={}", Float.valueOf(value), Integer.valueOf(range), Integer.valueOf(dc));
		Gpio.pwmWrite(gpio, dc);
		break;
	case SOFTWARE:
	default:
		SoftPwm.softPwmWrite(gpio, dc);
		break;
	}
}
 
Example 13
Source File: WiringPiDeviceFactory.java    From diozero with MIT License 5 votes vote down vote up
private void setHardwarePwmFrequency(int pwmFrequency) {
	// TODO Validate the requested PWM frequency
	hardwarePwmRange = DEFAULT_HARDWARE_PWM_RANGE;
	Gpio.pwmSetRange(hardwarePwmRange);
	int divisor = PI_PWM_CLOCK_BASE_FREQUENCY / hardwarePwmRange / pwmFrequency;
	Gpio.pwmSetClock(divisor);
	Gpio.pwmSetMode(Gpio.PWM_MODE_MS);
	this.boardPwmFrequency = pwmFrequency;
	Logger.info("setHardwarePwmFrequency({}) - range={}, divisor={}",
			Integer.valueOf(pwmFrequency), Integer.valueOf(hardwarePwmRange), Integer.valueOf(divisor));
}
 
Example 14
Source File: ButtonControlledLed.java    From diozero with MIT License 5 votes vote down vote up
public static void test(int buttonPin, int ledPin) {
	try (Button button = new Button(buttonPin, GpioPullUpDown.PULL_UP); LED led = new LED(ledPin)) {
		button.whenPressed(led::on);
		button.whenReleased(led::off);
		
		Logger.info("Waiting for 10s - *** Press the button connected to pin {} ***", Integer.valueOf(buttonPin));
		SleepUtil.sleepSeconds(10);
	} catch (RuntimeIOException e) {
		Logger.error(e, "Error: {}", e);
	}
}
 
Example 15
Source File: CLIMain.java    From dragonite-java with Apache License 2.0 5 votes vote down vote up
private static void checkUpdate() {
    final UpdateChecker updateChecker = new UpdateChecker(ProxyGlobalConstants.UPDATE_API_URL);

    Logger.info("Checking for updates...");

    final String remoteVersion = updateChecker.getVersionString(ProxyGlobalConstants.UPDATE_API_PRODUCT_NAME);
    if (remoteVersion != null && remoteVersion.equals(ProxyGlobalConstants.APP_VERSION)) {
        Logger.info("You are already using the latest version.");
    } else if (remoteVersion != null && remoteVersion.length() > 0) {
        Logger.info("** New version available! v{} **", remoteVersion);
    }
}
 
Example 16
Source File: HCSR04UsingWaitTest.java    From diozero with MIT License 5 votes vote down vote up
@Test
public void test() {
	try (HCSR04UsingWait hcsr04 = new HCSR04UsingWait(26, 4)) {
		for (int i=0; i<6; i++) {
			float distance = hcsr04.getDistanceCm();
			Logger.info("Distance={}", Float.valueOf(distance));
			SleepUtil.sleepSeconds(0.5);
		}
	}
}
 
Example 17
Source File: LambdaTest.java    From diozero with MIT License 5 votes vote down vote up
public static void main(String[] args) {
	Consumer<Void> consumer = (Void v) -> System.out.println("Hello consumer");

	consumer.accept(null);

	Command c = () -> System.out.println("Hello lambda");
	c.action();
	
	carryOutWork(() -> System.out.println("In here 1"));
	
	LambdaTest t = new LambdaTest();
	
	Logger.info("Using local invoke utility");
	for (int i=0; i<10; i++) {
		invoke(t::getValue, t::setValue);
		SleepUtil.sleepSeconds(1);
	}
	
	Logger.info("Using DioZeroScheduler.invokeAtFixedRate()");
	ScheduledFuture<?> future1 = DioZeroScheduler.getDaemonInstance().invokeAtFixedRate(t::getValue, t::setValue, 100, 1000, TimeUnit.MILLISECONDS);
	for (int i=0; i<10; i++) {
		SleepUtil.sleepSeconds(1);
	}
	future1.cancel(true);
	
	Logger.info("Using ScheduledExecutorService.scheduleAtFixedRate()");
	ScheduledExecutorService executor = Executors.newScheduledThreadPool(1);
	ScheduledFuture<?> future2 = executor.scheduleAtFixedRate(t::getValue, 100, 1000, TimeUnit.MILLISECONDS);
	for (int i=0; i<10; i++) {
		SleepUtil.sleepSeconds(1);
	}
	future2.cancel(true);
	executor.shutdownNow();
}
 
Example 18
Source File: FirmataDeviceFactory.java    From diozero with MIT License 5 votes vote down vote up
@Override
public void close() {
	Logger.info("close()");
	super.close();
	if (ioDevice != null) {
		try { ioDevice.stop(); } catch (Exception e) {}
	}
}
 
Example 19
Source File: ForwarderClient.java    From dragonite-java with Apache License 2.0 4 votes vote down vote up
private void prepareUnderlyingConnection(final DragoniteSocketParameters dragoniteSocketParameters) throws IOException, InterruptedException, DragoniteException, IncorrectHeaderException, ServerRejectedException {
    dragoniteClientSocket = new DragoniteClientSocket(remoteAddress, UnitConverter.mbpsToSpeed(upMbps), dragoniteSocketParameters);

    dragoniteClientSocket.setDescription("Forwarder");

    try {
        dragoniteClientSocket.send(new ClientInfoHeader(downMbps, upMbps, SystemInfo.getUsername(), ForwarderGlobalConstants.APP_VERSION, SystemInfo.getOS()).toBytes());

        final byte[] response = dragoniteClientSocket.read();
        final ServerResponseHeader responseHeader = new ServerResponseHeader(response);

        if (responseHeader.getStatus() != 0) {
            Logger.error("The server has rejected this connection (Error code {}): {}", responseHeader.getStatus(), responseHeader.getMsg());
            throw new ServerRejectedException(responseHeader.getMsg());
        } else if (responseHeader.getMsg().length() > 0) {
            Logger.info("Server welcome message: {}", responseHeader.getMsg());
        }

    } catch (InterruptedException | IOException | DragoniteException | IncorrectHeaderException | ServerRejectedException e) {
        Logger.error(e, "Unable to connect to remote server");
        try {
            dragoniteClientSocket.closeGracefully();
        } catch (InterruptedException | SenderClosedException | IOException ignored) {
        }
        throw e;
    }

    multiplexer = new Multiplexer(bytes -> {
        try {
            dragoniteClientSocket.send(bytes);
        } catch (InterruptedException | IncorrectSizeException | IOException | SenderClosedException e) {
            Logger.error(e, "Multiplexer is unable to send data");
        }
    }, ForwarderGlobalConstants.MAX_FRAME_SIZE);

    if (muxReceiveThread != null) muxReceiveThread.interrupt();

    muxReceiveThread = new Thread(() -> {
        byte[] buf;
        try {
            while ((buf = dragoniteClientSocket.read()) != null) {
                multiplexer.onReceiveBytes(buf);
            }
        } catch (InterruptedException | ConnectionNotAliveException e) {
            Logger.error(e, "Cannot receive data from underlying socket");
        } finally {
            synchronized (connectLock) {
                try {
                    dragoniteClientSocket.closeGracefully();
                } catch (final Exception ignored) {
                }
                multiplexer.close();
            }
        }
    }, "FC-MuxReceive");
    muxReceiveThread.start();

    Logger.info("Connection established with {}", remoteAddress.toString());
}
 
Example 20
Source File: WorkTimeTrackerApplication.java    From trackworktime with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onLowMemory() {
	Logger.info("low memory for application");
	super.onLowMemory();
}