Unoffical empeg BBS

Quick Links: Empeg FAQ | RioCar.Org | Hijack | BigDisk Builder | jEmplode | emphatic
Repairs: Repairs

Topic Options
#373285 - 14/04/2021 09:07 Button commands to Serial to control an external DAB/FM Radio
johnjore
new poster

Registered: 14/07/2020
Posts: 9
Hi all!

I have a DAB/FM board which outputs its audio to the empeg's AUX input, and its controlled using a USB interface. For this I currently use a Raspberry Pi Zero and a single button on a GPIO pin whos sole purpose is to tune to the next audio station.

I have this working in my car, and it works. I could add more buttons, and make it a "proper" head-unit with a dot matrix display etc. However, a better approach would be to integrate this with the empeg so I get IR control and a single unit to control audio.

Ideally I would like the empeg to control the radio by sending commands over the serial interface, and I can use the Pi to capture the commands and "translate" into something the radio understands.

I found documentation on how to send commands to the empeg using the serial interface, but I need the other way around. I hooked up a serial cable to the empeg and fiddled around in the menu, like switching between AUX and Player, but nothing was written to the the serial interface:

Code:
kftpd: listening on port 21
khttpd: listening on port 80
ktelnetd: listening on port 23

Prolux 4 empeg car - 2.1434 Jul  5 2004

  spindown_chunk_cache_runner.cpp: 294:Filling up space (-20)
ktelnetd: 192.168.1.228 connection from 192.168.1.100
ktelnetd: 192.168.1.228 connection from 192.168.1.100
  spindown_chunk_cache_runner.cpp: 294:Filling up space (-20)
  spindown_chunk_cache_runner.cpp: 294:Filling up space (-16)


I also had a look at the /proc folder, but nothing jumped out at me.

1)
Is anyone able to share something that I can use to make the empeg send all commands, including when audio source is changed (AUX vs Player) over the serial port so I can process it on the Pi side?

2)
I am assuming that all IR commands are passed through, even when AUX is the source?
I.e. the "Next" command would be captured and sent over the serial interface, despite AUX not really having the concept of "Next".


Disclaimer: I am not a developer, but I can muck around and I sometimes get there. In the end...

John

Top
#373286 - 14/04/2021 13:06 Re: Button commands to Serial to control an external DAB/FM Radio [Re: johnjore]
mlord
carpal tunnel

Registered: 29/08/2000
Posts: 14489
Loc: Canada
First, ensure your empeg is using the Hijack kernel.

Edit the config.ini file from the empeg (might be able to do this from the emplode program, or jemplode, or otherwise ftp it from the player to a PC, edit, and ftp it back again.

Ensure the file has these two lines (add them if missing):

[output]
notify=1


And for good measure, also ensure it has these:

[hijack]
suppress_notify=0


You can experiment with slightly simpler and easier-to-parse output by changing that line above to this:

[hijack]
suppress_notify=2


Cheers

Top
#373287 - 14/04/2021 13:11 Re: Button commands to Serial to control an external DAB/FM Radio [Re: johnjore]
mlord
carpal tunnel

Registered: 29/08/2000
Posts: 14489
Loc: Canada
It has been a while, so I don't remember everything that is and is not sent across the serial line from the basic settings above. Once you get that much working, you can ask again for items that you need but don't see there. I'll have a look then.

Cheers
Mark

Top
#373288 - 14/04/2021 13:13 Re: Button commands to Serial to control an external DAB/FM Radio [Re: johnjore]
mlord
carpal tunnel

Registered: 29/08/2000
Posts: 14489
Loc: Canada
Ah.. you will probably also want this:

[hijack]
suppress_notify=2
ir_debug=1

Top
#373289 - 14/04/2021 14:39 Re: Button commands to Serial to control an external DAB/FM Radio [Re: johnjore]
tfabris
carpal tunnel

Registered: 20/12/1999
Posts: 31592
Loc: Seattle, WA
In addition to the things Mark said, you might also want this in the config.ini:

[serial]
car_rate=115200

This will allow the serial port output to run at full speed both in home mode and car mode (normally serial runs at a slower rate in car). Also remember that all of these config.ini statements are case sensitive - that has tripped me up before.

Here are some more details about editing the config.ini file.

I don't know what output you'll see for the radio; I know what the output is for the MP3 player. Here is some example code that parses the output for the MP3 player.
_________________________
Tony Fabris

Top
#373290 - 15/04/2021 00:12 Re: Button commands to Serial to control an external DAB/FM Radio [Re: johnjore]
johnjore
new poster

Registered: 14/07/2020
Posts: 9
Thanks guys!

This is a very good start and I'll test it out tonight. Bit exciting if I can enhance the empeg with DAB and add back FM as my empeg tuner has died.

Top
#373292 - 15/04/2021 10:04 Re: Button commands to Serial to control an external DAB/FM Radio [Re: johnjore]
johnjore
new poster

Registered: 14/07/2020
Posts: 9
Had a tinker, and used both suppress_notify=2 and suppress_notify=0.

This is the output when an action is preformed; "Previous Track"
Code:
  serial_notify_thread.cpp: 116:@@ N1475
  serial_notify_thread.cpp: 117:@@ F0x8010
  serial_notify_thread.cpp: 118:@@ TThe 'in' Crowd
  serial_notify_thread.cpp: 119:@@ ABryan Ferry & Roxy Music
  serial_notify_thread.cpp: 120:@@ GRock/Pop
50943: IA1:00000004,dk=00ffffff,dr=0,lk=0
50943: IA2:00000004.P,dk=00ffffff,dr=0,lk=0
50943: ENQ.I: @c0125740: 00000004.0
50944: DEQ.I: @c0125740: 00000004.0
50944: ENQ.P: @c01258cc: 00000004.0
Poll ok
50945: DEQ.P: @c01258cc: 00000004.0
Poll wait
Poll fail
50963: IA1:00000005,dk=00000004,dr=0,lk=0
50963: IA2:00000005.R,dk=00000004,dr=0,lk=0
50963: ENQ.I: @c0125748: 00000005.0
50965: DEQ.I: @c0125748: 00000005.0
50965: ENQ.P: @c01258d4: 00000005.0
Poll ok
50966: DEQ.P: @c01258d4: 00000005.0
Poll wait
Poll fail
  serial_notify_thread.cpp: 116:@@ N1474
  serial_notify_thread.cpp: 117:@@ F0x2a40
  serial_notify_thread.cpp: 118:@@ TTougher than the rest
  serial_notify_thread.cpp: 119:@@ ABruce Springsteen
  serial_notify_thread.cpp: 120:@@ G
  spindown_chunk_cache_runner.cpp: 294:Filling up space (-16)


This is the output when using the menu, no action performed (i.e. browsing the menu items)
Code:
63046: IA1:00000004,dk=00ffffff,dr=0,lk=0
63046: IA2:00000004.P,dk=00ffffff,dr=0,lk=0
63046: ENQ.I: @c0125790: 00000004.0
63047: DEQ.I: @c0125790: 00000004.0
63048: ENQ.P: @c012591c: 00000004.0
Poll ok
63048: DEQ.P: @c012591c: 00000004.0
Poll wait
Poll fail
63056: IA1:00000005,dk=00000004,dr=0,lk=0
63056: IA2:00000005.R,dk=00000004,dr=0,lk=0
63056: ENQ.I: @c0125798: 00000005.0
63058: DEQ.I: @c0125798: 00000005.0
63058: ENQ.P: @c0125924: 00000005.0
Poll ok
63059: DEQ.P: @c0125924: 00000005.0
Poll wait
Poll fail


From what I can tell 00000004 is pressing left button, and 00000005 is releasing left button, and hijack is outputting that the button was pressed and released, not the action performed by the button (i.e. the context or result of pressing the buttons) ?

I assume this is why there is no "real" output on the Serial interface when audio is changed from Aux to Player?

I did notice that one of the files in /proc has active audio source, but using it would require "something" to poll that file every n seconds and output on the same serial interface (can they be shared?!?) when the audio source changes?


Waiting for a new battery to power the IR remote as I suspect it will work better as it will output "actions", like prev and next. However, the radio will have no way of knowing if its the active audio source or not and any IR actions when in Player mode will also be performed by the Radio.

So... the question is, how hard is it to add "actions" to the serial output?

Top
#373293 - 15/04/2021 13:19 Re: Button commands to Serial to control an external DAB/FM Radio [Re: johnjore]
mlord
carpal tunnel

Registered: 29/08/2000
Posts: 14489
Loc: Canada
The Linux kernel ("hijack") sits between the hardware and the closed-source "player" app. Hijack can only see the inputs and outputs, and modify those to a degree.

The "player" is what interprets and assigns "context/meaning" and "actions" to events like buttons (including the IR remote buttons).

So we have a bit of a limitation in what can happen there. I thought there was something already that would output the current "source" (FM/AM/AUX/MP3..) and similar info. Or at least the player would output a line for it whenever it changed.

But.. it's been a while.

If after looking more you don't find it, then perhaps I'll have a look too. I think we could have the current source ID just periodically dumped to the serial port if need be.

Top
#373294 - 15/04/2021 13:35 Re: Button commands to Serial to control an external DAB/FM Radio [Re: johnjore]
mlord
carpal tunnel

Registered: 29/08/2000
Posts: 14489
Loc: Canada
Try hijack_suppress_notify=0 and then look for lines from the player which have a 'M' prefix ("mixer source").

Top
#373295 - 16/04/2021 09:26 Re: Button commands to Serial to control an external DAB/FM Radio [Re: johnjore]
johnjore
new poster

Registered: 14/07/2020
Posts: 9
Success. I think.

I used fake_tuner=1 to get FM/AM mode, or FM/DAB for my usage.

Player:
Code:
serial_notify_thread.cpp: 160:@@ M2


FM:
Code:
serial_notify_thread.cpp: 160:@@ M1


AM (DAB for me):
Code:
serial_notify_thread.cpp: 160:@@ M4


Aux:
Quote:
serial_notify_thread.cpp: 160:@@ M3


I think I can work with this. Buttons on the player dont really do much, but using the remote I should be able to capture actions, vs button pressed / released.

Thanks for all your help. Without the source for the player, there is only so much integration that can be done.

When this works, having a way to send strings of information from the DAB/FM board to the hijack kernel would be great, but not seen anything in this that can be used: https://www.empeg.mars.org/devel/software/player.php. Having the hijack kernel overwride the LCD with information from the DAB board, like channel and RDS text would have been awsome. Worst case, an external $10 2x line LCD will need to be wired up for this.

Top
#373296 - 16/04/2021 15:25 Re: Button commands to Serial to control an external DAB/FM Radio [Re: johnjore]
mlord
carpal tunnel

Registered: 29/08/2000
Posts: 14489
Loc: Canada
Should be easy enough to have something put the DAB info onto the display. One can hack it into Hijack without too much fuss. That can also be done from a userspace app or script, I believe.

But there's also a quite fancy "skin" thing that Tony developed that can customize just about anything. It might be applicable here, if only I could remember the name of the thing! Tony?

Top
#373297 - 16/04/2021 15:26 Re: Button commands to Serial to control an external DAB/FM Radio [Re: mlord]
mlord
carpal tunnel

Registered: 29/08/2000
Posts: 14489
Loc: Canada
Originally Posted By: mlord
Try hijack_suppress_notify=0 and then look for lines from the player which have a 'M' prefix ("mixer source").


Note that this may also work with hijack_suppress_notify=2 so give that a try. The output is easier to deal with if it works.

Top
#373298 - 16/04/2021 22:41 Re: Button commands to Serial to control an external DAB/FM Radio [Re: mlord]
tfabris
carpal tunnel

Registered: 20/12/1999
Posts: 31592
Loc: Seattle, WA
Are you referring to "Emphatic", developed by empegBBS member "TonyC"?

Oh hey look what I found: https://empegbbs.com/ubbthreads.php/ubb/showflat/Number/335055/
_________________________
Tony Fabris

Top
#373299 - 17/04/2021 01:13 Re: Button commands to Serial to control an external DAB/FM Radio [Re: johnjore]
mlord
carpal tunnel

Registered: 29/08/2000
Posts: 14489
Loc: Canada
Mmmm.. got the two Tonys merged in my memories! Sorry about that!

Top
#373301 - 21/04/2021 04:30 Re: Button commands to Serial to control an external DAB/FM Radio [Re: johnjore]
johnjore
new poster

Registered: 14/07/2020
Posts: 9
Latest update is that my C# code (I can't write C/C++ to save my life) is working when using empeg's AM/FM mode. Will not work when in car, as it needs to use AUX mode to get the audio itself, or use an external mixer.

Anyway, it captures the IR remote keys by looking for <code>.P or M? values. It starts up in DAB mode as it has no idea what mode the empeg starts up (Player, Radio, or what Radio mode it should be using). Basic Next and Prev and "Scan for DAB" are working correctly. Maybe I'll get around to add capture and save / restore state information at some point.

Compiles using both dotnet and mono on a RPI 4. Ordered a MAX232 to TTL to connect empeg's RS232 to the RPI Zero's GPIO pins (Using RS232 to USB adapter on the bench, but a Zero only has a single USB port, need that to talk to the radio), and RPI 4 is too power hungry for my tiny car.

Thanks for the emphatic idea. Need to see if I can get it to send bits of information from the Radio to empeg. Makes it a bit more user friendly if I can see what DAB or FM frequency is being played etc.


Edited by johnjore (21/04/2021 04:31)

Top
#373302 - 27/04/2021 09:30 Re: Button commands to Serial to control an external DAB/FM Radio [Re: johnjore]
johnjore
new poster

Registered: 14/07/2020
Posts: 9
Ok, so I've had a look at Emphatic and the library it uses to draw text (and lines etc) on the display.

I may get the terminology wrong here, but if I understand the gist of it, there are a number of framebuffers?, and the empeg player is writing to one of them, and 3rd parties write to a different one, and tell the kernel which to make active?

The 3rd party app needs to monitor the key presses and IR input to switch the active frame buffer. I.e. I would "take control" when in AM(DAB), FM and AUX mode to overlay my text etc, and flip back to the empeg when playing MP3's.

Is this more or less the gist of it?

Here are some of the bits needed to make this work:
Quote:

vfdlib_registerFont("/empeg/lib/fonts/medium.bf", 0);
fd = open("/dev/display", O_RDWR);
rc = ioctl(fd, EMPEG_HIJACK_WAIT_FOR_PLAYER, NULL);
rc = ioctl(fd, EMPEG_HIJACK_TAKEOVER, NULL);
pthread_mutex_lock(&mutPlayerStarted);
pthread_cond_signal(&cvPlayerStarted);
pthread_mutex_unlock(&mutPlayerStarted);

Top
#373303 - 27/04/2021 13:05 Re: Button commands to Serial to control an external DAB/FM Radio [Re: johnjore]
mlord
carpal tunnel

Registered: 29/08/2000
Posts: 14489
Loc: Canada
I am actually not familiar with emphatic, but I did write the Hijack Linux kernel extensions. smile

I think the ioctl sequence to write the display is something like this:

EMPEG_HIJACK_WAIT_FOR_PLAYER
EMPEG_HIJACK_TAKEOVER // give the display to userland
...
EMPEG_HIJACK_DISPCLEAR // clear the userland display (maybe not needed)
...
EMPEG_HIJACK_DISPTEXT // write text to the display, hijack does the font.
EMPEG_HIJACK_DISPWRITE // write complete display contents (2048 bytes)
...

The actual receiving end of those ioctls is in hijack/arch/arm/special/hijack.c

Cheers


Edited by mlord (27/04/2021 13:07)

Top