mirror of
https://github.com/zyphlar/LanternPowerMonitor.git
synced 2024-03-08 14:07:47 +00:00
Turns out we don't actually need 30MB of bloated jars to make a single HTTP post to get a Google SSO auth token. Don't need them for Firebase either. And not for Apple SSO. Shoot while we're at it, might as well get rid of pi4j too since making a JNI wrapper for PiGPio is easy enough.
This commit is contained in:
@@ -23,14 +23,9 @@
|
||||
<version>1.2.3</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.pi4j</groupId>
|
||||
<artifactId>pi4j-core</artifactId>
|
||||
<version>2.2.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.pi4j</groupId>
|
||||
<artifactId>pi4j-plugin-pigpio</artifactId>
|
||||
<version>2.2.0-SNAPSHOT</version>
|
||||
<groupId>com.lanternsoftware.pigpio</groupId>
|
||||
<artifactId>lantern-pigpio</artifactId>
|
||||
<version>${pigpio.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.hypfvieh</groupId>
|
||||
@@ -63,7 +58,7 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.2</version>
|
||||
<version>3.10.1</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
@@ -83,7 +78,7 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<version>3.2.1</version>
|
||||
<version>3.3.0</version>
|
||||
<configuration>
|
||||
<createDependencyReducedPom>false</createDependencyReducedPom>
|
||||
<filters>
|
||||
|
||||
@@ -6,12 +6,9 @@ import com.lanternsoftware.datamodel.currentmonitor.Breaker;
|
||||
import com.lanternsoftware.datamodel.currentmonitor.BreakerHub;
|
||||
import com.lanternsoftware.datamodel.currentmonitor.BreakerPolarity;
|
||||
import com.lanternsoftware.datamodel.currentmonitor.BreakerPower;
|
||||
import com.lanternsoftware.pigpio.PiGpioFactory;
|
||||
import com.lanternsoftware.util.CollectionUtils;
|
||||
import com.lanternsoftware.util.concurrency.ConcurrencyUtils;
|
||||
import com.pi4j.Pi4J;
|
||||
import com.pi4j.context.Context;
|
||||
import com.pi4j.io.spi.Spi;
|
||||
import com.pi4j.io.spi.SpiMode;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@@ -28,26 +25,17 @@ public class CurrentMonitor {
|
||||
private static final Logger LOG = LoggerFactory.getLogger(CurrentMonitor.class);
|
||||
private static final int BATCH_CNT = 4;
|
||||
private final ExecutorService executor = Executors.newCachedThreadPool();
|
||||
private Context pi4j;
|
||||
private final Map<Integer, MCP3008> chips = new HashMap<>();
|
||||
private Sampler sampler;
|
||||
private PowerListener listener;
|
||||
private boolean debug = false;
|
||||
|
||||
public void start() {
|
||||
pi4j = Pi4J.newAutoContext();
|
||||
}
|
||||
|
||||
public void stop() {
|
||||
stopMonitoring();
|
||||
ConcurrencyUtils.sleep(1000);
|
||||
executor.shutdown();
|
||||
ConcurrencyUtils.sleep(1000);
|
||||
for (MCP3008 mcp : chips.values()) {
|
||||
mcp.shutdown(pi4j);
|
||||
}
|
||||
ConcurrencyUtils.sleep(1000);
|
||||
pi4j.shutdown();
|
||||
PiGpioFactory.shutdown();
|
||||
chips.clear();
|
||||
LOG.info("Power Monitor Service Stopped");
|
||||
}
|
||||
@@ -139,9 +127,7 @@ public class CurrentMonitor {
|
||||
if (chip == null) {
|
||||
String id = "SPI" + _chip;
|
||||
LOG.info("Creating chip {}", id);
|
||||
Spi spi = pi4j.create(Spi.newConfigBuilder(pi4j).mode(SpiMode.MODE_0).id(id).name("MCP3008_" + _chip).address(_chip).baud(810000).build());
|
||||
LOG.info("is open {}", spi.isOpen());
|
||||
chip = new MCP3008(spi);
|
||||
chip = new MCP3008(PiGpioFactory.getSpiChannel(_chip, 810000, false));
|
||||
chips.put(_chip, chip);
|
||||
}
|
||||
return chip;
|
||||
|
||||
@@ -214,7 +214,6 @@ public class MonitorApp {
|
||||
if (NullUtils.isNotEmpty(config.getHost()))
|
||||
host = NullUtils.terminateWith(config.getHost(), "/");
|
||||
monitor.setDebug(config.isDebug());
|
||||
monitor.start();
|
||||
LEDFlasher.setLEDOn(false);
|
||||
if (NullUtils.isNotEmpty(config.getAuthCode()))
|
||||
authCode = config.getAuthCode();
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
package com.lanternsoftware.currentmonitor.adc;
|
||||
|
||||
import com.pi4j.context.Context;
|
||||
import com.pi4j.io.spi.Spi;
|
||||
import com.lanternsoftware.pigpio.Spi;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class MCP3008 {
|
||||
private static final Logger LOG = LoggerFactory.getLogger(MCP3008.class);
|
||||
protected static final Logger LOG = LoggerFactory.getLogger(MCP3008.class);
|
||||
private static final byte[][] pins = new byte[8][];
|
||||
|
||||
private final Spi spi;
|
||||
@@ -22,15 +21,9 @@ public class MCP3008 {
|
||||
spi = _spi;
|
||||
}
|
||||
|
||||
public void shutdown(Context _pi4j) {
|
||||
spi.close();
|
||||
spi.shutdown(_pi4j);
|
||||
}
|
||||
|
||||
public int readPin(int _pin) {
|
||||
if (spi.transfer(pins[_pin], resp) > 2) {
|
||||
if (spi != null && spi.transfer(pins[_pin], resp) > 2)
|
||||
return ((resp[1] & 0x03) << 8) + (resp[2] & 0xFF);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,12 +2,6 @@
|
||||
<configuration>
|
||||
<property name="log.pattern" value="%date %-5level %logger{0} - %message%n"/>
|
||||
|
||||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<encoder>
|
||||
<pattern>${log.pattern}</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||
<file>/opt/currentmonitor/log/log.txt</file>
|
||||
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
|
||||
|
||||
Reference in New Issue
Block a user