techhunter
techhunter

Reputation: 693

How to check sense hat screen on|off using node.js

I am working in raspberry pi using sense-hat . Now i am using sense hat simulator in node-red. Now I have to check what is the status of sense-hat screen. How can I do this?

I have tried by using:

msg.payload.screen=="on"

and

msg.screen=="on"

but didnt work. can any one please help me?

I have also tried: msg.background=="off|on" and msg.device=="off|on"

Upvotes: 0

Views: 627

Answers (1)

Mark Setchell
Mark Setchell

Reputation: 207465

Not at all sure what you are actually trying to do, but this should help.

The SenseHat frame buffer is an 8x8 matrix of LEDs. That means there are 64 LED's and you write a 16-bit RGB565 value to each address in /dev/fb1 to make the LED come on a certain colour. 64 LEDs at 2 bytes each makes 128 bytes.

So, to turn off all the LEDs, you can send a bunch (128 bytes) of zeroes:

dd if=/dev/zero of=/dev/fb1 bs=128 count=1

And to turn on the first few LEDs with random colours:

echo AnyJunk > /dev/fb1

So, if you want to check all the LEDs are off, you need to compare the 128 bytes in the framebuffer to zero. You can do that by generating 128 bytes of zeroes and then running cmp like this:

cmp <(cat /dev/fb1) <(dd if=/dev/zero bs=128 count=1)

So, for an example:

echo AnyJunk > /dev/fb1      # Turn some LEDs on

# Check all zero, but they are not so the comparison fails
cmp <(cat /dev/fb1) <(dd if=/dev/zero bs=128 count=1)
1+0 records in
1+0 records out
128 bytes (128 B) copied, 0.000237917 s, 538 kB/s
/dev/fd/63 /dev/fd/62 differ: byte 1, line 1

echo $?
1

Turn all LEDs off and check again:

dd if=/dev/zero of=/dev/fb1 bs=128 count=1

cmp <(cat /dev/fb1) <(dd if=/dev/zero bs=128 count=1)
1+0 records in
1+0 records out
128 bytes (128 B) copied, 0.000289063 s, 443 kB/s

echo $?
0

Keywords: Raspberry Pi, RPi, SenseHat, Sense Hat, framebuffer, /dev/fb, RGB565, LED, matrix, commandline, command-line

Upvotes: 1

Related Questions