libraryextensions/blender/demos/KeysRun.xtl
KeysRun.xtl -- HEX1000-keys-leds: the complete Nano 1K calculator driven by physical contacts, from checked board simulation. Geometry and animation keys are X_eTaL arrays. The keypad/display layout is the pinned Panel library's scene units, not measured dimensions. Import: "kr:" u_se< "KeysRun"
ˡsubtitle : Char
subtitle: the source of every animated value
ˡsubtitle ← "physical keys and MAX7219 LEDs on a Tang Nano 1K; full board simulation"
ˡframes : Float
frames: seconds sampled at 30 frames per second
ˡframes ← (f̲loat o̲ffsets 1081) ÷ 30.0
ˡm̲ap : Num a => a -> Float
l:m_ap landmarks: actual VCD picoseconds to video seconds, explicit slow motion for bounce, first-key acceptance and one serial word
ˡm̲ap ← { points → 2 1 t̲ranspose 2 14 r̲eshape (0.0 c̲at f̲loat points) c̲at 0.0 3.0 6.0 8.0 10.0 15.0 16.5 24.0 26.0 26.5 30.0 31.0 34.0 35.0 }
ˡt̲imes : Num a => a -> Int
l:t_imes landmarks: VCD time of each video frame; hold at the end
ˡt̲imes ← { points → m ← ˡm̲ap points f̲loor (f̲loat f̲irst -1 t̲ake points) m̲in 0.0 m̲ax ((2 1 s̲elect₂ m, ˡframes) ᵛᵈr̲etime 0) }
ˡcueTexts : Char
cueTexts: narration and on-screen captions, in chronological order
ˡcueTexts ← ˡtitle c̲at ": " c̲at ˡsubtitle c̲at "|Startup: the level shifter enables, and real MAX7219 writes light DEADBEEF.|Slow motion: a short bouncing contact is rejected. The startup banner stays.|First key C: rows scan, columns synchronize, eight stable scans accept one press. Holding it does not repeat.|Time-lapse: release between keys. The circuit and X_eTaL agree; C0DE+BEEF= ends at 17FCD.|Slow motion: one actual 16-bit MAX7219 word, DIN sampled on clock rises, LOAD latching the LEDs.|Press equals again: Front translates it to Clear. The physical display returns to zero."
ˡcueTable : Float
cueTable: start and end of each cue
ˡcueTable ← 7 2 r̲eshape 0 2.6 2.8 6 6 9.8 10 16.4 16.5 26.4 26.5 30.5 31 36
ʰs̲teps : Num a => a -> Float
ʰs̲teps ← { g → n ← 1 s̲elect s̲hape g m ← 2 s̲elect s̲hape g keep ← r̲avel 2 1 t̲ranspose ((1 c̲at m) r̲eshape 1 = 1) c̲at n̲ot (1 d̲rop g) = -1 d̲rop g obj ← r̲avel 2 1 t̲ranspose (n c̲at m) r̲eshape f̲loat r̲ange m at ← r̲avel (m c̲at n) r̲eshape ˡframes val ← r̲avel 2 1 t̲ranspose f̲loat g k ← '+ r̲/ keep 2 1 t̲ranspose (3 c̲at k) r̲eshape (keep r̲eplicate obj) c̲at (keep r̲eplicate at) c̲at keep r̲eplicate val }
ʰl̲it : (Num a, Num b, Any c) => (Char, a, b) -> c -> Char
ʰl̲it ← { (name, boxes, on) z → ((name, boxes) ᵛᵈb̲oxes 0) c̲at (name, "glow", ʰs̲teps 0.06 + 2.5 × f̲loat on) ᵛᵈs̲teps 0 }
ʰb̲oxes : Any a => (Float, Float, Float) -> a -> Float
ʰb̲oxes ← { (p, dims, color) z → p c̲at₂ (((t̲ally p) c̲at 3) r̲eshape dims) c̲at₂ (((t̲ally p) c̲at 4) r̲eshape color c̲at 0.06) }
ʰj̲oin : Box Char -> Box Char -> Box Char
ʰj̲oin ← { a b → e̲nclose (d̲isclose a) c̲at "|" c̲at d̲isclose b }
ˡs̲cene : (Num a, Any b) => (a, Int, Int) -> b -> Char
(size, samples, word) l:s_cene 0: schematic panel and Nano 1K, glows from the checked VCD samples. Samples are time, contacts, scan/sync/debounce/handshake, machine, serial pins, eight decoded display registers, stage and actual serial-bit count.
ˡs̲cene ← { (size, samples, word) z → w ← 1 s̲elect size h ← 2 s̲elect size n ← t̲ally samples ts ← n t̲ake ˡframes d ← (w, h, 35, 13.0, 11.0) ᵛᵈf̲it 0 xy ← ᵖⁿk̲eyAt o̲ffsets 20 keyAt ← 2 1 t̲ranspose 3 20 r̲eshape ((1 s̲elect₂ xy) − 3.0) c̲at (20 r̲eshape -0.2) c̲at 2 s̲elect₂ xy contacts ← (2 s̲elect₂ samples) + 65536 × 15 − 3 s̲elect₂ samples positions ← (ᶠʳMap i̲ndexOf o̲ffsets 20) − 1 down ← (contacts 'd̲iv t̲able 2 ^ positions) m̲od 2 legendAt ← (keyAt + 20 3 r̲eshape 0.0 -0.35 0.0) c̲at₂ 20 4 r̲eshape 0.26 245 245 255 strokes ← ʰs̲trokes ᵖⁿd̲igits 8 r̲eshape 24 lines ← (1 s̲elect₂ strokes) − 3.0 segs ← (2 1 t̲ranspose 6 56 r̲eshape lines c̲at (56 r̲eshape -0.25) c̲at (2 s̲elect₂ strokes) c̲at ((3 s̲elect₂ strokes) − 3.0) c̲at (56 r̲eshape -0.25) c̲at 4 s̲elect₂ strokes) c̲at₂ 56 4 r̲eshape 100 250 160 0.025 digit ← (o̲ffsets 56) d̲iv 7 ⍝ MAX7219 a..g are bits 6..0; the Panel strokes are a..g. dg ← (1 + digit) s̲elect₂ 8 t̲ake₂ 16 d̲rop₂ samples on ← (dg d̲iv ((n c̲at 56) r̲eshape 2 ^ 6 − (o̲ffsets 56) m̲od 7)) m̲od 2 rowAt ← 2 1 t̲ranspose 3 4 r̲eshape (4 r̲eshape -5.55) c̲at (4 r̲eshape -0.25) c̲at 0.55 − 0.95 × f̲loat o̲ffsets 4 rowOn ← ((4 s̲elect₂ samples) 'd̲iv t̲able 2 ^ o̲ffsets 4) m̲od 2 colAt ← 2 1 t̲ranspose 3 4 r̲eshape (-5.0 + 0.95 × f̲loat o̲ffsets 4) c̲at (4 r̲eshape -0.25) c̲at 4 r̲eshape 1.3 colOn ← ((15 − 5 s̲elect₂ samples) 'd̲iv t̲able 2 ^ o̲ffsets 4) m̲od 2 board ← 3 10 r̲eshape 3.0 0.1 0.9 2.4 0.3 3.4 20 105 70 1 3.0 -0.2 0.9 1.25 0.25 1.25 25 28 40 1 3.0 -0.1 2.3 1.1 0.4 0.5 180 185 200 1 t ← ((ᵛᵈhead c̲at ((w, h, 30, ˡlength, 8 10 18, 35) ᵛᵈs̲tage 0)) c̲at ((0.0 36.0, 2 3 r̲eshape 0.0 c̲at (n̲eg d) c̲at 0.0, 2 3 r̲eshape 0.0) ᵛᵈc̲amera 0) c̲at ((("panel", 2 10 r̲eshape -3.0 0.2 0.25 5.5 0.4 6.7 35 45 65 1 -3.0 -0.05 2.3 4.9 0.1 1.1 12 25 18 1) ᵛᵈb̲oxes 0)) c̲at (("keys", (keyAt, 0.78 0.3 0.78, 50 130 210) ʰb̲oxes 0, down) ʰl̲it 0) c̲at (("legends", "0|1|2|3|4|5|6|7|8|9|A|B|C|D|E|F|+|-|*|=", legendAt) ᵛᵈl̲abels 0) c̲at (("segments", segs) ᵛᵈl̲ines 0) c̲at (("segments", "glow", ʰs̲teps 0.04 + 3.0 × f̲loat on) ᵛᵈs̲teps 0) c̲at (("rows", (rowAt, 0.14 0.08 0.14, 255 170 65) ʰb̲oxes 0, rowOn) ʰl̲it 0) c̲at (("columns", (colAt, 0.14 0.08 0.14, 255 170 65) ʰb̲oxes 0, colOn) ʰl̲it 0) c̲at ("Nano 1K", board) ᵛᵈb̲oxes 0) flags ← (6 s̲elect₂ samples) ≠ 0 spiAt ← 3 3 r̲eshape 1.7 -0.2 -2.2 3.0 -0.2 -2.2 4.3 -0.2 -2.2 spiOn ← 3 t̲ake₂ 12 d̲rop₂ samples texts ← "Nano 1K (schematic)|accepted|DIN|CLK|LOAD|physical contacts / row scan|MAX7219 LEDs" words ← 7 7 r̲eshape 3 -0.6 3.0 0.34 230 235 255 3 -0.6 -1.65 0.25 230 235 255 1.7 -0.6 -2.65 0.23 230 235 255 3 -0.6 -2.65 0.23 230 235 255 4.3 -0.6 -2.65 0.23 230 235 255 -3 -0.6 -3.5 0.28 230 235 255 -3 -0.6 3.3 0.34 230 235 255 bitAt ← 2 1 t̲ranspose 3 16 r̲eshape (0.6 + 0.3 × f̲loat o̲ffsets 16) c̲at (16 r̲eshape -0.2) c̲at 16 r̲eshape -3.35 bits ← (word d̲iv 2 ^ 15 − o̲ffsets 16) m̲od 2 sent ← (26 s̲elect₂ samples) '> t̲able o̲ffsets 16 bitOn ← (f̲loat sent) × (n c̲at 16) r̲eshape 0.2 + 0.8 × f̲loat bits withAccepted ← ((t c̲at ("accepted", 1 10 r̲eshape 3.0 -0.3 -1.2 0.25 0.1 0.25 100 250 160 0.06, (n c̲at 1) r̲eshape flags) ʰl̲it 0) c̲at (("SPI pins", (spiAt, 0.22 0.1 0.22, 250 190 70) ʰb̲oxes 0, spiOn) ʰl̲it 0) c̲at (("labels", texts, words) ᵛᵈl̲abels 0) c̲at (("word", (bitAt, 0.23 0.07 0.3, 100 220 250) ʰb̲oxes 0, bitOn) ʰl̲it 0) c̲at ("word", 16 2 r̲eshape 26.5 30.0) ᵛᵈs̲hown 0) clockText ← d̲isclose 'ʰj̲oin r̲/ '{ i → e̲nclose (3 ᵛᵈf̲ixed (f̲loat i s̲elect 1 s̲elect₂ samples) ÷ 1000000000.0) c̲at " ms A " c̲at (f̲ormat i s̲elect 10 s̲elect₂ samples) c̲at " PC " c̲at (f̲ormat i s̲elect 11 s̲elect₂ samples) c̲at " stable " c̲at f̲ormat i s̲elect 7 s̲elect₂ samples } e̲ach r̲ange n ((withAccepted c̲at ("state", 0.0 0.84 0.09 255 230 150, clockText, ts) ᵛᵈr̲eadout 0) c̲at (((ˡtitle, ˡsubtitle, 1 8 r̲eshape 0 2.6 255 255 255 18 22 44) ᵛᵈc̲ards 0)) c̲at (ˡcueTexts, ˡcueTable c̲at₂ 7 3 r̲eshape 255 255 255) ᵛᵈc̲aptions 0) }