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

The following examples show how to use org.pmw.tinylog.Logger#warn() . 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: FirmataDeviceFactory.java    From diozero with MIT License 6 votes vote down vote up
public FirmataDeviceFactory() {
	Logger.warn("*** Do NOT use this device factory for servo control; not yet implemented!");
	
	String port_name = PropertyUtil.getProperty("FIRMATA_SERIAL_PORT", null);
	if (port_name == null) {
		throw new IllegalArgumentException("Error, FIRMATA_SERIAL_PORT not set");
	}
	ioDevice = new FirmataDevice(port_name);
	
	try {
		ioDevice.start();
		Logger.info("Waiting for Firmata device '" + port_name + "' to initialise");
		ioDevice.ensureInitializationIsDone();
		Logger.info("Firmata device '" + port_name + "' successfully initialised");
	} catch (IOException | InterruptedException e) {
		throw new RuntimeIOException(e);
	}
}
 
Example 2
Source File: MqttTestClient.java    From diozero with MIT License 6 votes vote down vote up
@Override
public void messageArrived(String topic, MqttMessage message) throws Exception {
	if (topic.equals(MqttProviderConstants.RESPONSE_TOPIC)) {
		// TODO How to handle different response types?
		DiozeroProtos.Response response = DiozeroProtos.Response.parseFrom(message.getPayload());
		Logger.info("Got response message: {}", response);

		String correlation_id = response.getCorrelationId();
		responses.put(correlation_id, response);

		Condition condition = conditions.remove(correlation_id);
		if (condition == null) {
			Logger.error("No condition for correlation id {}", correlation_id);
		} else {
			lock.lock();
			try {
				condition.signalAll();
			} finally {
				lock.unlock();
			}
		}
	} else {
		Logger.warn("Unrecognised topic {}", topic);
	}
}
 
Example 3
Source File: NativeI2CDeviceSMBus.java    From diozero with MIT License 5 votes vote down vote up
@Override
public short readWordData(int registerAddress) {
	if ((funcs & NativeI2C.I2C_FUNC_SMBUS_READ_WORD_DATA) == 0) {
		Logger.warn("Function I2C_FUNC_SMBUS_READ_WORD_DATA isn't supported for device i2c-{}-0x{}",
				Integer.valueOf(controller), Integer.toHexString(deviceAddress));
		// TODO Throw an exception now or attempt anyway?
	}
	int rc = NativeI2C.readWordData(fd, registerAddress);
	if (rc < 0) {
		throw new RuntimeIOException("Error in SMBus.readWordData for device i2c-" + controller + "-0x"
				+ Integer.toHexString(deviceAddress) + ": " + rc);
	}

	return (short) rc;
}
 
Example 4
Source File: PigpioJDigitalInputDevice.java    From diozero with MIT License 5 votes vote down vote up
@Override
public void enableListener() {
	disableListener();
	if (edge == PigpioConstants.NO_EDGE) {
		Logger.warn("Edge was configured to be NO_EDGE, no point adding a listener");
		return;
	}
	
	int rc = pigpioImpl.enableListener(gpio, edge, this);
	if (rc < 0) {
		throw new RuntimeIOException("Error calling pigpioImpl.setISRFunc(), response: " + rc);
	}
}
 
Example 5
Source File: HTS221.java    From diozero with MIT License 5 votes vote down vote up
/**
 * Get temperature (degrees C).
 * @return Temperature in degrees C.
 */
@Override
public float getTemperature() {
	byte status = device.readByte(STATUS_REG);
	if ((status & SR_T_DA) == 0) {
		Logger.warn("Temperature data not available");
		return -1;
	}
	
	// Read raw temperature
	int temp_raw = device.readShort(TEMP_OUT | READ);
	
	return (t1DegC - t0DegC) * (temp_raw - t0Out) / (t1Out - t0Out) + t0DegC;
}
 
Example 6
Source File: MFRC522.java    From diozero with MIT License 5 votes vote down vote up
@Deprecated
public void dumpToConsole(UID uid, byte[] key) {	
	// Dump UID, SAK and Type
	dumpDetailsToConsole(uid);
	
	// Dump contents
	PiccType piccType = uid.getType();
	switch (piccType) {
	case MIFARE_MINI:
	case MIFARE_1K:
	case MIFARE_4K:
		// All keys are set to FFFFFFFFFFFFh at chip delivery from the factory.
		dumpMifareClassicToConsole(uid, key);
		break;
		
	case MIFARE_UL:
		dumpMifareUltralightToConsole();
		break;
		
	case ISO_14443_4:
	case MIFARE_DESFIRE:
	case ISO_18092:
	case MIFARE_PLUS:
	case TNP3XXX:
		Logger.warn("Dumping memory contents not implemented for that PICC type.");
		break;
		
	case UNKNOWN:
	case NOT_COMPLETE:
	default:
		break; // No memory dump here
	}
	
	haltA(); // Already done if it was a MIFARE Classic PICC.
}
 
Example 7
Source File: HCSR04UsingEvents.java    From diozero with MIT License 5 votes vote down vote up
@Override
public void valueChanged(DigitalInputEvent event) {
	if (state == State.STARTING_UP || state == State.FINISHED) {
		// Ignore
		return;
	}

	if (event.getValue() && state == State.WAITING_FOR_ECHO_ON) {
		state = State.WAITING_FOR_ECHO_OFF;
		echoOnTimeNs = event.getNanoTime();
	} else if (! event.getValue() && state == State.WAITING_FOR_ECHO_OFF) {
		state = State.FINISHED;
		echoOffTimeNs = event.getNanoTime();
		lock.lock();
		try {
			condition.signal();
		} finally {
			lock.unlock();
		}
	} else {
		// Error unexpected event...
		Logger.warn("valueChanged({}), unexpected event for state {}", event, state);
		state = State.ERROR;
		lock.lock();
		try {
			condition.signal();
		} finally {
			lock.unlock();
		}
	}
}
 
Example 8
Source File: WifiTracker.java    From trackworktime with GNU General Public License v3.0 5 votes vote down vote up
private void tryPebbleNotification(String message) {
	try {
		externalNotificationManager.notifyPebble(message);
	} catch (Exception e) {
		Logger.warn("Pebble notification failed");
	}
}
 
Example 9
Source File: CassandraStatement.java    From cassandra-jdbc-driver with Apache License 2.0 5 votes vote down vote up
protected void replaceCurrentResultSet(CassandraCqlStatement parsedStmt, ResultSet resultSet) {
    this.cqlStmt = parsedStmt;

    if (currentResultSet != null) {
        try {
            if (!currentResultSet.isClosed()) {
                currentResultSet.close();
            }
        } catch (Throwable t) {
            Logger.warn(t, "Not able to close the old result set: {}", currentResultSet);
        }
    }

    currentResultSet = new CassandraResultSet(this, parsedStmt, resultSet);
}
 
Example 10
Source File: NativeI2CDeviceSMBus.java    From diozero with MIT License 5 votes vote down vote up
@Override
public byte readByte() {
	if ((funcs & NativeI2C.I2C_FUNC_SMBUS_READ_BYTE) == 0) {
		Logger.warn("Function I2C_FUNC_SMBUS_READ_BYTE isn't supported for device i2c-{}-0x{}",
				Integer.valueOf(controller), Integer.toHexString(deviceAddress));
		// TODO Throw an exception now or attempt anyway?
	}
	int rc = NativeI2C.readByte(fd);
	if (rc < 0) {
		throw new RuntimeIOException("Error in SMBus.readByte for device i2c-" + controller + "-0x"
				+ Integer.toHexString(deviceAddress) + ": " + rc);
	}

	return (byte) rc;
}
 
Example 11
Source File: LocationTracker.java    From trackworktime with GNU General Public License v3.0 5 votes vote down vote up
private void tryPebbleNotification(String message) {
	try {
		externalNotificationManager.notifyPebble(message);
	} catch (Exception e) {
		Logger.warn("Pebble notification failed");
	}
}
 
Example 12
Source File: Basics.java    From trackworktime with GNU General Public License v3.0 5 votes vote down vote up
public void unregisterThirdPartyReceiver() {
	if(thirdPartyReceiver == null) {
		Logger.warn(ThirdPartyReceiver.class.getSimpleName() + " not registered, skipping.");
		return;
	}

	context.unregisterReceiver(thirdPartyReceiver);
	thirdPartyReceiver = null;
	Logger.debug("Unregistered " + ThirdPartyReceiver.class.getSimpleName());
}
 
Example 13
Source File: Basics.java    From trackworktime with GNU General Public License v3.0 5 votes vote down vote up
private void registerThirdPartyReceiver() {
	if(thirdPartyReceiver != null) {
		Logger.warn(ThirdPartyReceiver.class.getSimpleName() + " already registered, skipping.");
		return;
	}

	thirdPartyReceiver = new ThirdPartyReceiver();
	IntentFilter intentFilter = new IntentFilter();
	intentFilter.addAction("org.zephyrsoft.trackworktime.ClockIn");
	intentFilter.addAction("org.zephyrsoft.trackworktime.ClockOut");
	context.registerReceiver(thirdPartyReceiver, intentFilter);
	Logger.debug("Registered " + ThirdPartyReceiver.class.getSimpleName());
}
 
Example 14
Source File: RemoteDigitalInputDevice.java    From diozero with MIT License 4 votes vote down vote up
@Override
public void setDebounceTimeMillis(int debounceTime) {
	Logger.warn("Debounce not implemented");
}
 
Example 15
Source File: MPU9150Driver.java    From diozero with MIT License 4 votes vote down vote up
/**
 * Set sampling rate.
 *  Sampling rate must be between 4Hz and 1kHz.
 *  @param  rate	Desired sampling rate (Hz).
 * @throws RuntimeIOException if an I/O error occurs
 * @return status
 */
public boolean mpu_set_sample_rate(int rate) throws RuntimeIOException {
	Logger.debug("mpu_set_sample_rate({})", rate);
	if (sensors == 0) {
		return false;
	}

	if (dmp_on) {
		Logger.warn("mpu_set_sample_rate() DMP is on, returning");
		return false;
	}

	if (lp_accel_mode) {
		if (rate != 0 && (rate <= 40)) {
			/* Just stay in low-power accel mode. */
			Logger.debug("Just setting lp_accel_mode to {}", rate);
			mpu_lp_accel_mode(rate);
			return true;
		}
		
		/* Requested rate exceeds the allowed frequencies in LP accel mode,
		 * switch back to full-power mode.
		 */
		Logger.debug("Setting lp_accel_mode to 0");
		mpu_lp_accel_mode(0);
	}
	int new_rate = rate;
	if (new_rate < 4) {
		new_rate = 4;
	} else if (new_rate > 1000) {
		new_rate = 1000;
	}

	int data = 1000 / new_rate - 1;
	Logger.debug("Setting sample rate to {}", data);
	// rate_div == 0x19 == MPU9150_RA_SMPL_RATE_DIV
	i2cDevice.writeByte(MPU9150_RA_SMPL_RATE_DIV, data);

	sample_rate = 1000 / (1 + data);

	mpu_set_compass_sample_rate(Math.min(compass_sample_rate, MAX_COMPASS_SAMPLE_RATE));

	Logger.debug("Automatically setting LPF to {}", sample_rate >> 1);
	/* Automatically set LPF to 1/2 sampling rate. */
	mpu_set_lpf(sample_rate >> 1);
	
	return true;
}
 
Example 16
Source File: PiconZero.java    From diozero with MIT License 4 votes vote down vote up
@Override
public void setBoardPwmFrequency(int pwmFrequency) {
	// Not supported
	Logger.warn("Cannot change PWM frequency for the Piconzero");
}
 
Example 17
Source File: TinkerBoardMmapGpio.java    From diozero with MIT License 4 votes vote down vote up
@Override
public void setMode(int gpio, DeviceMode mode) {
	IntBuffer mux_int_buffer = (gpio < 24) ? pmuIntBuffer : grfIntBuffer;
	int iomux_offset = getIoMuxOffsetForGpio(gpio);
	if (iomux_offset == UNKNOWN) {
		Logger.warn("Unknown IOMUX offset for GPIO #{}", Integer.valueOf(gpio));
		return;
	}
	// Configure mode
	int config_val = mux_int_buffer.get(iomux_offset);
	switch (mode) {
	case DIGITAL_INPUT:
	case DIGITAL_OUTPUT:
		if (gpio == 238 || gpio == 239) {
			config_val = (config_val | (0x0f<<(16+(gpio%8-4)*4))) & (~(0x0f<<((gpio%8-4)*4)));
		} else {
			config_val = (config_val | (0x03<<((gpio%8)*2+16))) & (~(0x03<<((gpio%8)*2)));
		}
		mux_int_buffer.put(iomux_offset, config_val);
		
		// Set digital direction
		int bank;
		int shift;
		if (gpio < 24) {
			bank = gpio / 32;
			shift = gpio % 32;
		} else {
			bank = (gpio + 8) / 32;
			shift = (gpio + 8) % 32;
		}
		int gpio_val = gpioBanks[bank].gpioIntBuffer.get(GPIO_SWPORTA_DDR_INT_OFFSET);
		if (mode == DeviceMode.DIGITAL_INPUT) {
			gpio_val &= ~(1<<shift);
		} else {
			gpio_val |= (1<<shift);
		}
		gpioBanks[bank].gpioIntBuffer.put(GPIO_SWPORTA_DDR_INT_OFFSET, gpio_val);
		break;
	case PWM_OUTPUT:
		Logger.warn("Mode {} not yet implemented for GPIO #{}", mode, Integer.valueOf(gpio));
		return;
	default:
		Logger.warn("Invalid mode ({}) for GPIO #{}", mode, Integer.valueOf(gpio));
		return;
	}
}
 
Example 18
Source File: MqttTestClient.java    From diozero with MIT License 4 votes vote down vote up
@Override
public void connectionLost(Throwable cause) {
	Logger.warn(cause, "Lost connection to MQTT Server: {}", cause);
}
 
Example 19
Source File: WifiScanner.java    From trackworktime with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Make a request to scan wifi networks.
 *
 * Results will be returned with {@link WifiScanListener}. Callback can happen instant or
 * delayed (usually a few seconds).
 */
public void requestWifiScanResults() {
	Logger.debug("Requested wifi scan results");

	if(wifiScanListener == null) {
		// No point in requesting scans nobody cares about...
           Logger.warn("Requesting wifi scan, but no " + WifiScanListener.class.getSimpleName()
				+ " is registered!");
		return;
	}

	if(!wifiManager.isWifiEnabled()) {
		wifiScanListener.onScanRequestFailed(Result.FAIL_WIFI_DISABLED);
		return;
	}

	// It's possible another application requested scan results, check last received scan results
	// and use them if they are not too old.
	if(areLastResultsOk()) {
		Logger.debug("Returning cached wifi scan results");
		wifiScanListener.onScanResultsUpdated(latestScanResults);
		return;
	}

	// Note: Let's be nice, and allow returning valid cached scan results. I.e. allow returning
	// cached results, before checking if we can scan again.
	if(!canScanAgain()) {
		wifiScanListener.onScanRequestFailed(Result.CANCEL_SPAMMING);
		return;
	}

	boolean success = wifiManager.startScan();
	latestScanResultTime = DateTimeUtil.getCurrentDateTime();
	Logger.debug("Wifi start scan succeeded: " + success);

	if(!success) {
		wifiScanListener.onScanRequestFailed(Result.FAIL_SCAN_REQUEST_FAILED);
		return;
	}

	scanRequested = true;
}
 
Example 20
Source File: MPU9150Driver.java    From diozero with MIT License 4 votes vote down vote up
/**
 * Reset FIFO read/write pointers.
 * @throws RuntimeIOException if an I/O error occurs
 * @return status
 */
public boolean mpu_reset_fifo() throws RuntimeIOException {
	if (sensors == 0) {
		Logger.warn("mpu_reset_fifo(), sensors==0, returning");
		return false;
	}

	byte data = 0;
	// int_enable == 0x38 == MPU9150_RA_INT_ENABLE
	i2cDevice.writeByte(MPU9150_RA_INT_ENABLE, data);
	// fifo_en == 0x23 == MPU9150_RA_FIFO_EN
	i2cDevice.writeByte(MPU9150_RA_FIFO_EN, data);
	// user_ctrl == 0x6a == MPU9150_RA_USER_CTRL for MPU-6050
	i2cDevice.writeByte(MPU9150_RA_USER_CTRL, data);

	if (dmp_on) {
		data = BIT_FIFO_RST | BIT_DMP_RST;
		// user_ctrl == 0x6a == MPU9150_RA_USER_CTRL for MPU-6050
		i2cDevice.writeByte(MPU9150_RA_USER_CTRL, data);
		SleepUtil.sleepMillis(50);
		data = BIT_DMP_EN | BIT_FIFO_EN;
		if ((sensors & INV_XYZ_COMPASS) != 0) {
			data |= BIT_AUX_IF_EN;
		}
		// user_ctrl == 0x6a == MPU9150_RA_USER_CTRL for MPU-6050
		i2cDevice.writeByte(MPU9150_RA_USER_CTRL, data);
		if (int_enable) {
			data = BIT_DMP_INT_EN;
		} else {
			data = 0;
		}
		// int_enable == 0x38 == MPU9150_RA_INT_ENABLE
		i2cDevice.writeByte(MPU9150_RA_INT_ENABLE, data);
		data = 0;
		// fifo_en == 0x23 == MPU9150_RA_FIFO_EN
		i2cDevice.writeByte(MPU9150_RA_FIFO_EN, data);
	} else {
		data = BIT_FIFO_RST;
		// user_ctrl == 0x6a == MPU9150_RA_USER_CTRL for MPU-6050
		i2cDevice.writeByte(MPU9150_RA_USER_CTRL, data);
		if ((bypass_mode != null && bypass_mode.booleanValue()) || ((sensors & INV_XYZ_COMPASS) == 0)) {
			data = BIT_FIFO_EN;
		} else {
			data = BIT_FIFO_EN | BIT_AUX_IF_EN;
		}
		// user_ctrl == 0x6a == MPU9150_RA_USER_CTRL for MPU-6050
		i2cDevice.writeByte(MPU9150_RA_USER_CTRL, data);
		SleepUtil.sleepMillis(50);
		if (int_enable) {
			data = BIT_DATA_RDY_EN;
		} else {
			data = 0;
		}
		// int_enable == 0x38 == MPU9150_RA_INT_ENABLE
		i2cDevice.writeByte(MPU9150_RA_INT_ENABLE, data);
		// fifo_en == 0x23 == MPU9150_RA_FIFO_EN
		i2cDevice.writeByte(MPU9150_RA_FIFO_EN, fifo_enable);
	}
	
	return true;
}