stationeers.de Mod workshop · Dominik1199
DE Sign in
  1. Home
  2. IC10 academy
  3. Day 34

Day 34 of 365 · Beginner · Month 2: Order and data network

Project: clean up old code

Project: an old lab chip with pins, raw numbers and a line jump is rebuilt in the workshop style – without its behaviour changing.

Project 30 min Week 5

What you learn today

  • Replace pins with lbn/sbn
  • move numbers into defines
  • Keep the behaviour unchanged

In the lab there is a chip somebody wrote months ago. It works, but nobody dares to touch it. On top of that the lab is being rebuilt, and devices should be addressed by name instead of pins in future. Today you rebuild it – and the most important part is that afterwards it does exactly the same.

The old code

start:
yield
l r0 d0 Temperature
slt r1 r0 291.15
s d1 On r1
sgt r2 r0 297.15
s d2 On r2
sub r3 r0 273.15
s d3 Setting r3
j 1

What it does: below 18 °C the heater runs, above 24 °C the cooler, and the display shows the temperature in °C.

The new devices

oldDeviceName on the network
d0gas sensor“Labor”
d1wall heater“Laborheizung”
d2wall cooler“Laborkuehler”
d3LED display“Labortemp”

The device names stay German – they are names in the game.

How to go about it

  1. Add a header and sections.
  2. One define per device type with HASH("prefab") and a comment.
  3. The three numbers into defines: 291.15 K (18 °C), 297.15 K (24 °C), 273.15 as CELSIUSOFFSET.
  4. Every register gets an alias.
  5. l and s with pins become lbn and sbn with HASH("name"), batch mode Average.
  6. j 1 becomes j start.

Run the tests after every step. A rebuild that stays green along the way is a safe rebuild.

Milestones

  1. Cold: heater on.
  2. Warm: cooler on.
  3. The display shows °C.
  4. In the band between 18 and 24 °C: both off.
Tip

The checker shows you pins, bare registers and line jumps when you switch on the style hints in the “Checker” tab. Work through the list until it is empty.

Warning

Device names in ASCII only: “Laborkuehler”, not “Laborkühler”. With an umlaut the hash no longer matches the name you gave in the game.

Diagram

Program layout in the proven style # --- Heat warning --- define LIMIT 303.15 # 30 C define SENSOR HASH("…") alias temp r0 alias hot r1 start: yield … j start 1 · define everything tunable 2 · alias names for registers 3 · main loop with yield, endless
Settings, names, main loop: after the rebuild everything tunable sits at the top.

Project task

Task

Rebuild the lab chip in the workshop style without changing what it does:

  • Devices through lbn/sbn with the names “Labor”, “Laborheizung”, “Laborkuehler”, “Labortemp” – no pins.
  • None of the numbers 291.15, 297.15, 273.15 in the body, everything in defines.
  • An alias for every register, jump to a label.

Prefabs: StructureGasSensor, StructureWallHeater, StructureWallCooler, StructureConsoleLED5.

Milestones

  1. Milestone 1: cold – heater on
  2. Milestone 2: warm – cooler on
  3. Milestone 3: display in °C
  4. Milestone 4: in the band both off

Hints

Hint 1

Four prefab defines, three number defines – then the body is free of numbers.

Hint 2

l r0 d0 Temperature becomes lbn temp SENSOR HASH("Labor") Temperature Average.

Hint 3

s d1 On r1 becomes sbn HEATER HASH("Laborheizung") On heat.

Quiz

2 questions. You pass from 60 % – the server does the grading.

Complete the day

  • Passed all milestones of the project
  • Passed the quiz with at least 60 %

Without an account progress is saved in this browser only.

Report a mistake in this lesson

Please sign in to report. Sign in

Esc
↑ ↓ selectEnter open/ opens search anywhere