This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
OReezy's profile picture

Touch Screen openblocks Radio Controller v1.1.2

Started by OReezy, 06 March 2014 - 06:33 AM
OReezy #1
Posted 06 March 2014 - 07:33 AM
Here is a small program I wrote to control the radios from openblocks.

Version 1.1.1

Setup
  • For the actual build you just need the radio and chest to be adjacent to each other and you need an advanced monitor. When you run the program, it will set itself up and find all other information on its own. If something was set up incorrectly it will also tell you what went wrong.
  • For volume control, radio must be next to computer
  • CODE: http://pastebin.com/gfdZzLtv
  • pastebin get gfdZzLtv radio
Features
  • Automatically detects peripherals
  • Automatically indexes all disks in chest
  • Scrolling buttons in case there are more disks than screen space
  • Remembers which disk is being played and displays it in a different color
  • Volume control
  • Features only appear if they need to or if they are working (if radio is not next to computer it cannot control volume or if there are fewer disks than screen space)
  • Can specify which monitor to use
  • Can use Advanced Terminal
  • Prints setup info to terminal if in debug mode (see arguments)
  • Remembers custom settings entered with arguments
Arguments:
  • help Displays arguments in game on terminal
  • -t Terminal mode (Not available while using monitor mode)
  • -d Debug mode
  • -nd Non-daemon mode
  • -m<side or name> Specify which monitor to use (Only one monitor at a time for now)
  • -s<.5-5> Change scale of monitor (not available for terminals)
  • -v<1-15> Changes initial volume
Example: radio -mmonitor_5 -s3 -d

Possible Future Updates
  • Options menu for customization
  • Multi-monitor support
Screenshots


Changelogv1.0.1
  • Added an additional check for wrong disk type
  • Updated initialEmpty() to find the first open slot in a chest instead of attempting all slots until it comes across an empty slot
  • Removed unnecessary function getRadioDisk()
v1.1.0
  • Advanced Terminal support
  • Can specify which monitor to use
  • Now runs in background
  • Accepts arguments (-t, -nd, -d, -m, -s)
v1.1.1
  • Added -v<1-15> argument for setting initial volume
  • Radio now remembers custom settings when you start with arguments
  • "OFF" button now changes to "ON" when music is playing
  • Fixed a bug that caused radio to not turn on initially and after pushing "OFF"
v1.1.2
  • Fixed a bug when connecting with cable

If you find bugs, please post them here.

How to Add Stations1. The first thing you need to do is find the openblocks config. Then locate the part of the config that deals with radios. By default, it will look like this:

2. Next you need some stations. For this you need the IP address or the url address and the port. Once you have this information you need to add it between the <> in the config:
# List any radio stations you want
S:radioStations <
--#add radio stations here
>
3. You have three pieces, the address/port, the name that it will show in game, and the color of the radio disk. Each part much be seperated my a semicolon ( ; ) and the entire thing must be in double quotes (")
  • The format is: "address:port;Display Name;Color"
4. When you are finished it should look something like this:

5. Now start up minecraft and go find your radio disks!

Note: If you are getting an in-game error "Unknown Stream Type" you need an optional client side mod called "NotEnoughCodecs" that can be downloaded here:
OpenMods
Direct Download
Edited on 11 September 2014 - 12:39 AM
unobtanium #2
Posted 06 March 2014 - 11:13 AM
This is very well made :)/>
theoriginalbit #3
Posted 06 March 2014 - 12:09 PM
I agree with UNOBTANIUM; looks quite nice and solid coding behind the scenes. If there was something that I'd pick on it would be a few minor things here and there and most are only for readability reasons

for example line 25

if not radio or not chest or not mon then
I'd make it

if not (radio and chest and mon) then

or the function detectRadioDisk

local function detectRadioDisk()
  local t = radio.getStackInSlot(1)
  return t and t.name or false
end

EDIT: Actually on second look that function isn't even used.
Edited on 06 March 2014 - 11:09 AM
OReezy #4
Posted 07 March 2014 - 06:00 AM
I agree with UNOBTANIUM; looks quite nice and solid coding behind the scenes. If there was something that I'd pick on it would be a few minor things here and there and most are only for readability reasons

for example line 25

if not radio or not chest or not mon then
I'd make it

if not (radio and chest and mon) then

or the function detectRadioDisk

local function detectRadioDisk()
  local t = radio.getStackInSlot(1)
  return t and t.name or false
end

EDIT: Actually on second look that function isn't even used.

Thanks for the tips. That function was left over from I was testing to find the best ways to do things.
Godkyra #5
Posted 08 March 2014 - 10:13 PM
Hi there. :)/> I made an account just to say thank you for this. I found the radio the other day and immediately wanted to make a CC volume control for it (with no LUA knowledge). I look on here for info and found that you'd already done it. :P/> Thank you muchly.

I did have some issues though. For the entire script to work, the chest must be next to both the Computer and the Radio. If the chest and Radio are next to the Computer, they can't touch each other, so the script fails. Is this intended?

I got around it by placing the chest behind the Radio, and using a preripheral proxy to link the chest to the Computer. The script ran beautifully then. (Pics below)

https://www.dropbox.com/s/svaml2udohw4i1p/Radio1.png
https://www.dropbox.com/s/bcgydj0bf5fbnfq/Radio2.png

Once again: Much Appreciated.
Dog #6
Posted 09 March 2014 - 04:40 AM
I'm having the same issue as Godkyra, but using the peripheral proxy isn't working for me - the program still says the chest isn't next to the radio even though it is :\ Any suggestions?
OReezy #7
Posted 09 March 2014 - 05:53 AM
I'm having the same issue as Godkyra, but using the peripheral proxy isn't working for me - the program still says the chest isn't next to the radio even though it is :\ Any suggestions?

Make sure there is a disk in the chest or radio. It you do have a disk in the chest, make sure it is in the first slot as that is the slot my program uses to test if the chest and radio are adjacent. If this doesn't help, could you send me a picture of your setup?

Also, you can get the chest/radio/computer all touching if you use a vanilla double chest. From a top down view it would look like this:
C = chest, R = radio, U = computer
CC
UR


Hi there. :)/> I made an account just to say thank you for this. I found the radio the other day and immediately wanted to make a CC volume control for it (with no LUA knowledge). I look on here for info and found that you'd already done it. :P/> Thank you muchly.

I did have some issues though. For the entire script to work, the chest must be next to both the Computer and the Radio. If the chest and Radio are next to the Computer, they can't touch each other, so the script fails. Is this intended?

I got around it by placing the chest behind the Radio, and using a preripheral proxy to link the chest to the Computer. The script ran beautifully then. (Pics below)

https://www.dropbox....4i1p/Radio1.png
https://www.dropbox....bnfq/Radio2.png

Once again: Much Appreciated.

Thanks, glad I could help. It was quite fun to code. I also plan to add some new features once I am not so busy. (Probably after this next week)

With a single chest it is impossible to have all three touching. There isn't a way around this as that is simply how the game works. I use a vanilla double chest for mine so I can keep it compact.
Dog #8
Posted 09 March 2014 - 05:39 PM
Got it working - was using the wrong 'disks' (facepalm)
Edited on 09 March 2014 - 09:25 PM
Godkyra #9
Posted 09 March 2014 - 08:22 PM
I tried removing the Modems and Proxy, then replacing them with a double chest. The setup worked perfectly as OReezy said it would.

I don't know what texture pack you're using, but you don't appear to be working with an Advanced computer. Likewise you will want the advanced monitors (If you are using both then my bad, ignore that).

Also, you say you're using discs? Try using a tuner card (you will need to put a radio station in your configs for one to show up, if you haven't already).
willwac #10
Posted 10 March 2014 - 12:19 AM
This is great! I recomend changing the color of the scroll buttons and changing the "OFF" button to "QUIT" or "EXIT" when nothing is playing.
Or how about a debian?
OReezy #11
Posted 10 March 2014 - 02:57 AM
Got it working - was using the wrong 'disks' (facepalm)

I was thinking about asking this but it felt silly, sorry :P/>

This is great! I recomend changing the color of the scroll buttons and changing the "OFF" button to "QUIT" or "EXIT" when nothing is playing.
Or how about a debian?

Thanks. I am thinking of adding an options menu for changing all the colors. I don't know if I will make the "OFF" button change to "EXIT" because it seems like it could be clicked on accident on small monitor setups pretty easily. If I do make an options menu though, I will probly add it as an option to turn that on.

And whats a debian?
Edited on 10 March 2014 - 02:01 AM
OReezy #12
Posted 10 March 2014 - 07:25 PM
Update: v1.0.1
  • Added an additional check for wrong disk type
  • Updated initialEmpty() to find the first open slot in a chest instead of attempting all slots until it comes across an empty slot
  • Removed unnecessary function getRadioDisk()
willwac #13
Posted 12 March 2014 - 02:31 PM
And whats a debian?
Sorry, I ment daemon.
Basiclly, run it on the monitor, yet allow users to use the shell.
Also, I had a few ideas.
SpoilerRun "radio" with arguments, i.e.
radio -d
Prints debug info on terminal, does not run in daemon mode.
radio -s
Runs radio program on the terminal, does not print debug info, does not run in daemon mode.
radio -m <side>
Specifies a monitor to run it on, can be combined with "-d," runs in daemon mode.
radio -l
Runs radio in a "lite" mode, does not output color, does not use touch, can be combined with "-d" or "-m." Otherwise runs in daemon mode.
Edited on 30 September 2014 - 11:42 PM
OReezy #14
Posted 12 March 2014 - 08:18 PM
And whats a debian?
Sorry, I ment daemon.
Basiclly, run it on the monitor, yet allow users to use the shell.
Also, I had a few ideas.
SpoilerRun "rdio" with arguments, i.e.
radio -d
Prints debug info on terminal, does not run in daemon mode.
radio -s
Runs radio program on the terminal, does not print debug info, does not run in daemon mode.
radio -m <side>
Specifies a monitor to run it on, can be combined with "-d," runs in daemon mode.
radio -l
Runs radio in a "lite" mode, does not output color, does not use touch, can be combined with "-d" or "-m." Otherwise runs in daemon mode.

I really like this idea. Going to have to look into daemons. I am already planning to make a terminal version as well.
willwac #15
Posted 12 March 2014 - 09:23 PM
Basicly, to do a daemon, you just do this:
local function myProg()
  --code--
end

local function shellMe()
  shell.run("/rom/programs/shell") --You don't have to use the direct path, but it clears up some confusion.'
end

parallel.waitForAll(myProg(),shellMe())
Edited on 12 March 2014 - 08:24 PM
theoriginalbit #16
Posted 12 March 2014 - 10:14 PM
Also, I had a few ideas.
SpoilerRun "rdio" with arguments, i.e.
radio -d
Prints debug info on terminal, does not run in daemon mode.
radio -s
Runs radio program on the terminal, does not print debug info, does not run in daemon mode.
radio -m <side>
Specifies a monitor to run it on, can be combined with "-d," runs in daemon mode.
radio -l
Runs radio in a "lite" mode, does not output color, does not use touch, can be combined with "-d" or "-m." Otherwise runs in daemon mode.
I really like this idea. Going to have to look into daemons. I am already planning to make a terminal version as well.
Personally this is what I've found to be the best method of implementing runtime args like willwac has suggested (+ one of my own thoughts)
code

--# this is the table of options for your program to check
local options = {
  daemon = true; --# run as a daemon
  monitor = {}; --# table of monitors to render on, using table incase they want multiple output
  dualcontrol = false; --# display the GUI on both the terminal and any monitors
  advanced = term.isColor and term.isColor(); --# run the program with colours and clicking, this cannot be forced, `lite` arg removes this
  debug = false; --# print debug information to the screen or a file
}

--# argument validation, we use a `do` block so that all the variables we use (except for `options`) fall out of scope and don't unnecessarily use space in RAM
do
  --# get the runtime args
  local args = {...}

  --# make a table of the valid computer sides for easier monitor arg checking
  local sides = {}
  for _,v in pairs(rs.getSides()) do
	sides[v] = true
  end

  --# loop through all the args and check them
  for i = 1, #args do
	local opt = args[i]
	if opt == "--no-daemon" or opt == "-nd" then
	  options.daemon = false
	elseif sides[opt] or peripheral.getType(opt) == "monitor" then
	  table.insert(options.monitor, peripheral.wrap(opt))
	elseif opt == "--mirror" or opt = "-m" then
	  options.dualcontrol = true
	elseif opt == "--lite" or opt == "-l" then
	  options.advanced = true
	elseif opt == "--debug" or opt = "-d" then
	  options.debug = true
	else
	  error("Unknown runtime argument: "..opt)
	end
  end

  --# run some validation on the args, for example don't allow certain args to be on given certain conditions, I'll provide one example
  if options.daemon and #options.monitor == 0 then
	error("Monitor output must be enabled to enable daemon mode", 0)
  end
end

--# program body the only variable you have access in the body is `options`
if options.debug then
  print("Debug mode is enabled!")
end
Edited on 12 March 2014 - 09:15 PM
Fenric #17
Posted 16 March 2014 - 10:32 PM
Hello,

I found this thread while searching for a way to control the volume on OpenBlocks radio stations in game. Since it's quite recent I wanted to register and post as it's not working for me.

Here's how I placed everything:
http://imgur.com/a/2dDNI#0

I'm returning to Minecraft and learning mods so not sure if I'm missing something obvious. I'm using The MadPack if that matters.

Hi again,

My last post still hasn't shown up as I just registered on the site and it has to be approved. I'm hoping this post will at least get through.

I figured out why it was not working. MadPack did not have the OpenBlocks Peripheral Addons included.

It's working great now, thanks a lot for posting this.
FuzzyPurp #18
Posted 17 March 2014 - 10:49 AM
Here's how I placed everything:
http://imgur.com/a/2dDNI#0

Here is a way to fix that spacing and dot on CC screens while using Sphax texture pack.
http://bdcraft.net/community/pbdc-help/incompatible-computercraft-dot-spacing-bug-t773.html
OReezy #19
Posted 18 March 2014 - 01:02 AM
It's working great now, thanks a lot for posting this.

I'm glad you like it.

Udate: 1.1.0
  • Advanced Terminal support
  • Can specify which monitor to use
  • Now runs in background
  • Accepts arguments
Arguments:
  • -t Terminal mode
  • -nd Non-Daemon mode
  • -d Debug mode
  • -m<side or name> Specify a monitor to use
  • -s<.5-5> Sets scale of monitor (not available for terminal)
Edited on 18 March 2014 - 01:32 AM
Ballistic Buddha #20
Posted 21 March 2014 - 10:40 AM
Hah, wow. I actually just made myself a program for radio control, I knew I should have checked the forums first :P/>. However, I've got to say yours is much better. Not only does your main monitor output look better, but you also included cli flags and the ability to swap out crystals.

This is what mine looks like

Now, Since I'm still a fan of the big ass vertical monitor for volume control, I feel inclined to merge my code with yours. I took a quick peek at your code and it looks pretty neat and organized, so it shouldn't be all that hard to do.

So thank you for this, thanks a lot :)/>
Edited on 21 March 2014 - 09:41 AM
Doom6197 #21
Posted 21 March 2014 - 04:00 PM
Thanks for this, really makes life easier.
OReezy #22
Posted 21 March 2014 - 07:30 PM
Thanks for this, really makes life easier.

I'm happy I could help.

Hah, wow. I actually just made myself a program for radio control, I knew I should have checked the forums first :P/>.

I always encourage people to try to do things themselves too. I love to see how different people handle the same issues.

Now, Since I'm still a fan of the big ass vertical monitor for volume control, I feel inclined to merge my code with yours. I took a quick peek at your code and it looks pretty neat and organized, so it shouldn't be all that hard to do.

Feel free to pick apart my code. If you have any questions about how the code works, I would be more than happy to answer them.

Off Topic: Your base setup in that picture looks awesome.
punchin #23
Posted 20 April 2014 - 12:20 AM
Not sure if this is intended, but when the radio is off, the red Off is there, but when it's on, the red Off is still showing. Shouldn't that change to a green On? Also, I can't turn it back on by hitting it. As an interesting note, how hard would it be to manually build the typical power button symbol (circle with a bar going through the top) and make that change colors to indicate on/off?

Additionally, when setting this up, the instructions say you have to have a monitor. Nothing about an advanced monitor. When I set mine up per the instructions, it kept telling me "Colour not supported". So I took all the red disks out and tried. Same thing. Took the blue out instead. Same thing. I was confused until I noticed in the pictures that you had used advanced monitors and I put the 2 together. Could you clear up that error message a little? Something like "Must use advanced monitors." would be awesome.

All that being said, I love the program and it works great!

Also, would there be a possibility of a config file being put in the program directory that we can set the default volume with? With my volumes turned way down on my computer and in minecraft, 1 volume on the radio is still very loud. I would like it to start on 1 volume and also be able to choose a default station if that's possible. Config could be edited manually or through the terminal.
Edited on 19 April 2014 - 10:25 PM
OReezy #24
Posted 28 April 2014 - 05:06 PM
-snip-

Sorry it took so long for a response. I am planning on having the program be able to save default settings. That way if you have it running on a computer with lots of other monitors and things, you won't need to enter a list of arguments every time. I will include a default volume for this too.

The way the "OFF" button works at the moment removes the disk from the radio. It shouldn't be too difficult to have it work like a real power button though. As for the power symbol, "(|)" is the best I can think of. School is ending this week so I'll try to get these updates going once everything is done.
ShadowGar #25
Posted 07 May 2014 - 09:16 AM
This is awesome. Thank you for the program, this fits perfect in any build.
OReezy #26
Posted 26 May 2014 - 11:33 PM
Does anyone think it would be better to have the radio turn off if you click the disk that is already playing?

v1.1.1
  • Added -v<1-15> argument for setting initial volume
  • Radio now remembers custom settings when you start with arguments
  • "OFF" button now changes to "ON" when music is playing
  • Fixed a bug that caused radio to not turn on initially and after pushing "OFF"
Edited on 02 June 2014 - 05:09 PM
ephys #27
Posted 29 May 2014 - 04:02 PM
Neat program good job :'3

I was rewriting the GUI to fit my base theme [http://screencloud.net/v/njsr] and I discovered a bug while testing: as you manage the disks using their name instead of an assigned numerical id (like it's chest position) you'll have a nice bug if you have two disks with the same name :3
Balverine #28
Posted 27 August 2014 - 05:47 PM
No matter which setup I use, it always tells me the peripherals are not found.
Kizz #29
Posted 27 August 2014 - 06:30 PM
Yea same here. Just released my own little jukebox. Didn't know it was possible to even check the playing music.
OReezy #30
Posted 11 September 2014 - 02:41 AM
No matter which setup I use, it always tells me the peripherals are not found.
Yea same here. Just released my own little jukebox. Didn't know it was possible to even check the playing music.

I know its been awhile, but if either of you see this which peripheral is not found? Do you get a message telling you or is it a crash?

Also, fixed a bug when connecting with network cables.
Edited on 11 September 2014 - 12:43 AM
mrfrank #31
Posted 15 September 2014 - 03:33 PM
Issue with this.

Everything works smoothly until the chest has over 8 disks in it.

The setup I am using is a 3x1 monitor (advanced). The scrolling only goes down to the 8th disk and no long scrolls down, however the rest continues to work fine.

I can see all disks in terminal mode OR if I make the monitors smaller or, even, larger. A 2x3 monitor setup will scroll through all 13 disks and display them correctly, however the scroll (down) bar continues to show even after the 13th disk is listed at the bottom. Pressing the down arrow again breaks the touch, monitor no longer responds to clicks.
willwac #32
Posted 01 October 2014 - 01:47 AM
Hm, weird.
Sorry I have not kept up to date on this program.
Could you make the list loop?
mrfrank #33
Posted 13 October 2014 - 01:35 PM
I am not sure if that question was meant for me or not, but if it was.

I can not make the list loop, once it reaches the bottom it simply breaks on the monitor.

Not sure if it matters, but the server is using Crackpack.
willwac #34
Posted 25 October 2014 - 06:04 PM
Sorry, I was asking @OReezy