Skip to content

Commit

Permalink
Merge pull request #1 from rostriano/main
Browse files Browse the repository at this point in the history
Added PowerMonitor, Clock and BackupPowerSupply
  • Loading branch information
Panakotta00 authored Sep 8, 2024
2 parents 7bd172e + 1504596 commit bf98424
Show file tree
Hide file tree
Showing 28 changed files with 1,419 additions and 18 deletions.
50 changes: 50 additions & 0 deletions Packages/BackupPowerSupply/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# The Backup Power Supply
The Ficsit Backup Power Supply manages backup power - sort of like a UPS but too slow to
guarantee uninterrupted power. Or is it?

## Setup
To use the Ficsit BPS, you will need one or more power storages, plus two power switches and of course a computer.
The switches must be hooked up as shown below:

mains power load power storage
| | |
| | |
+-----/ ----+----/ -----+

mains power storage
switch switch


A demonstration setup is shown below:

![Example setup of the Ficsit Backup Power Supply](https://raw.githubusercontent.com/Panakotta00/FicsIt-Networks-Repository/main/Packages/BackupPowerSupply/preview1.jpg "Example setup of the Ficsit BPS")
<sub>Example setup of the Ficsit Backup Power Supply</sub>

Please observe the following:
- the mains switch must have the following nick: "BPS mainsSwitch"
- the power storage switch must have the following nick: "BPS powerStorageSwitch"
- the computer needs to have a network connection to both switches and a power storage.

## Operation and functioning
Once operational, the Ficsit Backup Power Supply will not need any attention from the employee.

The Ficsit BPS will monitor the grid and the connected power storage(s). When the overall load on the grid exceeds the production, it will disconnect itself from the grid and engage the power storage(s) so you can continue operating from the power storage(s) as long as there is any charge left in the power storage(s). Then, when the grid is balanced again, it will start charging the power storage(s).

![Normal operation](https://raw.githubusercontent.com/Panakotta00/FicsIt-Networks-Repository/main/Packages/BackupPowerSupply/preview2.jpg "The Ficsit BPS during Normal operation")
<sub>The Ficsit BPS during Normal operation</sub>

![Charging](https://raw.githubusercontent.com/Panakotta00/FicsIt-Networks-Repository/main/Packages/BackupPowerSupply/preview3.jpg "The Ficsit BPS while Charging")
<sub>The Ficsit BPS while Charging</sub>

![Providing backup power](https://raw.githubusercontent.com/Panakotta00/FicsIt-Networks-Repository/main/Packages/BackupPowerSupply/preview4.jpg "The ficsit BPS providing backup power")
<sub>The ficsit BPS providing backup power</sub>

## Considerations for designing your grid
To guarantee grid stability, Ficsit advises to have a minimum of one power storage connected
directly to the grid. This ensures there will be enough power available for the limited
amount of time it takes for your Backup Power Supply management system to flip its switches.

Please note that while the charge rate of a power storage is limited to 100 MW, its
discharge rate is unlimited. This means that for the maximum of five seconds it takes
for the BPS to provide backup power, a single power storage can supply as much
as 72,000 MW of power.
4 changes: 4 additions & 0 deletions Packages/BackupPowerSupply/metadata.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
name = "Backup Power Supply"
short_description = "Manages backup power - sort of like a UPS but too slow to guarantee uninterrupted power"
tags = ["backup", "power", "UPS"]
authors = ["Rostriano"]
Binary file added Packages/BackupPowerSupply/preview1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Packages/BackupPowerSupply/preview2.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Packages/BackupPowerSupply/preview3.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Packages/BackupPowerSupply/preview4.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
146 changes: 146 additions & 0 deletions Packages/BackupPowerSupply/v0.0.1/EEPROM.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
---
--- Ficsit Backup Power Supply
---
--- Created by Rostriano, with code by 1000101
--- Date: 2024-07-04
---

local POLL_INTERVAL <const> = 5
local CATEGORY <const> = "BPS"

local MODE <const> = { NORMAL="1", DISCHARGING="2", CHARGING="3" }


---Find and return a table of all the NetworkComponent proxies that are of the given class[es]
---@param class any Class name or table (of tables) of class names
---@param boolean Return only one
---@return table | nil | proxy: indexed table of all NetworkComponents found
function getComponentsByClass( class, getOne )
local results = {}

if ( getOne == nil ) then
getOne = false
end

if type( class ) == "table" then

for _, c in pairs( class ) do
local proxies = getComponentsByClass( c, getOne )
if not getOne then
tableConcat( results, proxies )
else
if( proxies ~= nil ) then
return proxies
end
end
end

elseif type( class ) == "string" then

local ctype = classes[ class ]
if ctype ~= nil then
local comps = component.findComponent( ctype )
for _, c in pairs( comps ) do
local proxy = component.proxy( c )
if getOne and proxy ~= nil then
return proxy
elseif not tableHasValue( results, proxy ) then
table.insert( results, proxy )
end
end
end

end

if ( getOne ) then
return {}
end

return results
end


local powerStorage = getComponentsByClass( { "PowerStorage" }, true )
or computer.panic( "Power storage not found" )
local powerStorageSwitch = component.proxy( component.findComponent(CATEGORY .. " powerStorageSwitch" )[1] )
or computer.panic( "Power storage switch not found" )
local mainsSwitch = component.proxy( component.findComponent(CATEGORY .. " mainsSwitch" )[1] )
or computer.panic( "Mains switch not found" )
local connectors = mainsSwitch:getPowerConnectors()
or computer.panic( "Mains switch power connectors not found" )
local circuit1, circuit2, currMode

function hasTrippedFuse( circuits )
for _, circuit in pairs( circuits ) do
if circuit.isFuesed then
return true
end
end

return false
end

function getGridSurplus( gridCircuit )
gridProduction = ( gridCircuit and gridCircuit.production ) or 0
gridConsumption = gridCircuit.consumption or 0
gridSurplus = gridProduction - gridConsumption

print( "production, consumption, surplus:", gridProduction, gridConsumption, gridSurplus )

return gridSurplus
end

-- Set switches to default settings and then enter loop to figure out where we stand
powerStorageSwitch:setIsSwitchOn( false )
mainsSwitch:setIsSwitchOn( true )

while( true ) do

-- We get the circuits inside the loop so that we can see a wire being attached
circuit1, circuit2 = connectors[1]:getCircuit(), connectors[2]:getCircuit()

-- Determine if the grid has power
if circuit1 and circuit1.production > 0 then
gridCircuit = circuit1
else
gridCircuit = circuit2
end

-- Determine what to do
if gridCircuit ~= nil and gridCircuit.production > 0 then
if powerStorage.powerStore == 100 and not hasTrippedFuse( { circuit1, circuit2 } ) then

-- We got mains power and the power storage doesn't need to charge, all is well
if currMode ~= MODE.NORMAL then
print( "Switching to normal mode" )
powerStorageSwitch:setIsSwitchOn( false )
mainsSwitch:setIsSwitchOn( true )
currMode = MODE.NORMAL
end
elseif
not hasTrippedFuse( { circuit1, circuit2 } )
and getGridSurplus( gridCircuit ) > 0 -- Make sure we won't accidentally discharge the power storage
then
-- We got mains power; charge power storage
if currMode ~= MODE.CHARGING then
print( "Charging power storage" )
mainsSwitch:setIsSwitchOn( true )
powerStorageSwitch:setIsSwitchOn( true )
currMode = MODE.CHARGING
end
print( "Power storage charge", powerStorage.powerStore, "MWh" )
end
else -- gridCircuit.production == 0
-- Mains power down; run on power storage
if currMode ~= MODE.DISCHARGING then
print( "Running on power storage" )
currMode = MODE.DISCHARGING
end
mainsSwitch:setIsSwitchOn( false )
powerStorageSwitch:setIsSwitchOn( true )
print( "Power storage charge", powerStorage.powerStore, "MWh" )
end

::continue::
event.pull( POLL_INTERVAL )
end
6 changes: 6 additions & 0 deletions Packages/BackupPowerSupply/v0.0.1/metadata.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
fin_version = ">= 0.3.19"

[[EEPROM]]
name = "EEPROM.lua"
title = "EEPROM"
description = "The main EEPROM used when installing this package. The name is not relevant."
23 changes: 23 additions & 0 deletions Packages/Clock/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# The Ficsit multi-screen and multi-timezone clock
The Ficsit multi-screen and multi-timezone clock displays the time on one or multiple screens.

![Example setup of the Ficsit Clock](https://raw.githubusercontent.com/Panakotta00/FicsIt-Networks-Repository/main/Packages/Clock/preview1.jpg "Example setup of the Ficsit Clock")
<sub>Example setup of the Ficsit multi-screen and multi-timezone clock</sub>

## Setup and installation
Please consider the following when installing your clocks:
- one GPU T1 per screen is required
- your screens should optimally have the smallest height possible and one click wider than the minimum possible width
- each screen needs to have its nick configured as follows:
- clock
- tz="\<desired time zone\>"

A complete nick would look like this:
`clock tz="UTC"`

### Available timezones
Currently, two timezones are available; the aforementioned UTC, plus M2CT. This stands for Massage-2(A-B)b Coordinated Time. When the tz has not been set, it will default to M2CT.

### Alternative screen nick
If you would like to give your screens a nick other than "clock", you can do so via the computer's nick:
`screen="mystring"`
4 changes: 4 additions & 0 deletions Packages/Clock/metadata.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
name = "Clock"
short_description = "Displays Massage-2(A-B)b Coordinated Time or UTC on one or multiple screens"
tags = ["clock", "time", "UTC", "M2CT"]
authors = ["Rostriano"]
Binary file added Packages/Clock/preview1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit bf98424

Please sign in to comment.