Skip to content

Commit

Permalink
Merge pull request #34 from goblingift/dev
Browse files Browse the repository at this point in the history
Merge DEV to Master for Release 1.7.1
  • Loading branch information
goblingift authored May 11, 2020
2 parents 26b08ab + 0eafe5f commit ae33aee
Show file tree
Hide file tree
Showing 7 changed files with 194 additions and 101 deletions.
2 changes: 1 addition & 1 deletion HayRackController/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<groupId>gift.goblin</groupId>
<artifactId>HayRackController</artifactId>

<version>1.7.0</version>
<version>1.7.1</version>

<packaging>war</packaging>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import gift.goblin.HayRackController.controller.model.LoadCellSettings;
import gift.goblin.HayRackController.controller.model.SoundSettings;
import gift.goblin.HayRackController.controller.model.Soundtitle;
import gift.goblin.HayRackController.database.embedded.repo.weight.TareMeasurementRepository;
import gift.goblin.HayRackController.database.model.weight.TareMeasurement;
import gift.goblin.HayRackController.service.configuration.ConfigurationService;
import gift.goblin.HayRackController.service.event.TemperatureMeasurementService;
import gift.goblin.HayRackController.service.io.ApplicationState;
Expand Down Expand Up @@ -72,6 +74,9 @@ public class SettingsController {
@Autowired
private MaintenanceManager maintenanceManager;

@Autowired
private TareMeasurementRepository tareMeasurementRepository;

/**
* Default render method for the dashboard.
*
Expand All @@ -94,7 +99,7 @@ public String renderSettings(Model model) {
SoundSettings soundSettings = configurationService.getSoundSettings();
LoadCellSettings loadCellSettings = configurationService.getLoadCellSettings();
logger.info("got loadcell settings successful:" + loadCellSettings);

model.addAttribute("maintenance_mode", maintenanceManager.getApplicationState() == ApplicationState.MAINTENANCE);
model.addAttribute("soundSettings", soundSettings);
model.addAttribute("loadCellSettings", loadCellSettings);
Expand Down Expand Up @@ -197,18 +202,7 @@ public String saveLoadCellSettings(@ModelAttribute LoadCellSettings settings, Bi

if (!oldSettings.isEnabled() && settings.isEnabled()) {
logger.info("Load-cells were activated, initialize load-cells now...");
if (settings.getAmount() >= 4) {
iOController.initializeLoadCell4(settings);
}
if (settings.getAmount() >= 3) {
iOController.initializeLoadCell3(settings);
}
if (settings.getAmount() >= 2) {
iOController.initializeLoadCell2(settings);
}
if (settings.getAmount() >= 1) {
iOController.initializeLoadCell1(settings);
}
initializeLoadCells(settings);
}

if (oldSettings.isEnabled() && !settings.isEnabled()) {
Expand All @@ -224,6 +218,50 @@ public String saveLoadCellSettings(@ModelAttribute LoadCellSettings settings, Bi
return renderSettings(model);
}

private void initializeLoadCells(LoadCellSettings loadCellSettings) {

Optional<TareMeasurement> optTareMeasurement = Optional.empty();
try {
logger.info("Try to read the last tare-measurement, to initialize load-cells correctly...");
optTareMeasurement = tareMeasurementRepository.findTop1ByOrderByMeasuredAtDesc();
} catch (Exception e) {
logger.error("Exception while try to read the last tare measurement entry!", e);
}

if (optTareMeasurement.isPresent()) {
if (loadCellSettings.getAmount() >= 4) {
iOController.initializeLoadCell4(loadCellSettings);
if (optTareMeasurement.isPresent()) {
iOController.setTareValueLoadCell4(optTareMeasurement.get().getTareLoadCell4());
}
}
if (loadCellSettings.getAmount() >= 3) {
iOController.initializeLoadCell3(loadCellSettings);
if (optTareMeasurement.isPresent()) {
iOController.setTareValueLoadCell3(optTareMeasurement.get().getTareLoadCell3());
}
}
if (loadCellSettings.getAmount() >= 2) {
iOController.initializeLoadCell2(loadCellSettings);
if (optTareMeasurement.isPresent()) {
iOController.setTareValueLoadCell2(optTareMeasurement.get().getTareLoadCell2());
}
}
if (loadCellSettings.getAmount() >= 1) {
iOController.initializeLoadCell1(loadCellSettings);
if (optTareMeasurement.isPresent()) {
iOController.setTareValueLoadCell1(optTareMeasurement.get().getTareLoadCell1());
}
}

iOController.setLoadCellAmount(loadCellSettings.getAmount());
iOController.setLoadCellsActivated(true);
} else {
logger.warn("No tare-measurement entry found, cant initialize load-cells.");
}

}

private List<Soundtitle> generateAvailableSounds() {

List<Playlist> tracks = Playlist.getVALUES();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,10 @@ public String renderWeightOverview(Model model) {

if (!iOController.isLoadCellsActivated()) {
model.addAttribute("error_message", "weight.loadcells.deactivated");
} else {
model.addAttribute("weightDetailsDto", readLoadCells());
}

model.addAttribute("weightDetailsDto", readLoadCells());
model.addAttribute("webcam_count", webcamService.getWebcamCount());

return "weight";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,28 +287,76 @@ public void handleGpioPinDigitalStateChangeEvent(GpioPinDigitalStateChangeEvent
@RequiresRaspberry
public void releasePinsLoadCell1() {
logger.info("Releasing pins for load-cell 1...");
gpioController.unprovisionPin(pinLoadCell1Dat, pinLoadCell1Sck);

if (pinLoadCell1Dat != null) {
gpioController.unprovisionPin(pinLoadCell1Dat);
} else {
logger.warn("Cant unprovision pin load-cell 1 dat, cause its null!");
}

if (pinLoadCell1Sck != null) {
gpioController.unprovisionPin(pinLoadCell1Sck);
} else {
logger.warn("Cant unprovision pin load-cell 1 sck, cause its null!");
}

hx711LoadCell1 = null;
}

@RequiresRaspberry
public void releasePinsLoadCell2() {
logger.info("Releasing pins for load-cell 2...");
gpioController.unprovisionPin(pinLoadCell2Dat, pinLoadCell2Sck);

if (pinLoadCell2Dat != null) {
gpioController.unprovisionPin(pinLoadCell2Dat);
} else {
logger.warn("Cant unprovision pin load-cell 2 dat, cause its null!");
}

if (pinLoadCell2Sck != null) {
gpioController.unprovisionPin(pinLoadCell2Sck);
} else {
logger.warn("Cant unprovision pin load-cell 2 sck, cause its null!");
}

hx711LoadCell2 = null;
}

@RequiresRaspberry
public void releasePinsLoadCell3() {
logger.info("Releasing pins for load-cell 3...");
gpioController.unprovisionPin(pinLoadCell3Dat, pinLoadCell3Sck);

if (pinLoadCell3Dat != null) {
gpioController.unprovisionPin(pinLoadCell3Dat);
} else {
logger.warn("Cant unprovision pin load-cell 3 dat, cause its null!");
}

if (pinLoadCell3Sck != null) {
gpioController.unprovisionPin(pinLoadCell3Sck);
} else {
logger.warn("Cant unprovision pin load-cell 3 sck, cause its null!");
}

hx711LoadCell3 = null;
}

@RequiresRaspberry
public void releasePinsLoadCell4() {
logger.info("Releasing pins for load-cell 4...");
gpioController.unprovisionPin(pinLoadCell4Dat, pinLoadCell4Sck);

if (pinLoadCell4Dat != null) {
gpioController.unprovisionPin(pinLoadCell4Dat);
} else {
logger.warn("Cant unprovision pin load-cell 4 dat, cause its null!");
}

if (pinLoadCell4Sck != null) {
gpioController.unprovisionPin(pinLoadCell4Sck);
} else {
logger.warn("Cant unprovision pin load-cell 4 sck, cause its null!");
}

hx711LoadCell4 = null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,8 @@ private void initializeLoadCells() {

iOController.setLoadCellAmount(loadCellSettings.getAmount());
iOController.setLoadCellsActivated(true);
} else {
logger.warn("No tare-measurement entry found, cant initialize load-cells.");
}

}
Expand Down
4 changes: 3 additions & 1 deletion HayRackController/src/main/resources/templates/webcam.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@
<img id="camPreview" src="" />
</p>



<a class="light-grey-color" id="camNumber" th:text="${camNumber}" />

<script th:inline="javascript">

$('body').on('click', '.dropdown-item', function (e) {
Expand Down
Loading

0 comments on commit ae33aee

Please sign in to comment.