A world in dk(decay/denmark) » program http://rotand.dk Just another pointless weblog Sat, 30 Nov 2013 21:03:48 +0000 en-US hourly 1 https://wordpress.org/?v=4.3.18 DTMF dialer http://rotand.dk/2008/03/20/dtmf-dialer/ http://rotand.dk/2008/03/20/dtmf-dialer/#comments Thu, 20 Mar 2008 20:23:54 +0000 http://rotand.dk/blog/2008/03/20/dtmf-dialer/ UPDATE : see  dtmf-dialer-got-new-features

I got around to hacking some code together for a simple DTMF dialer on the mobile.

Its functional and simple. Enter a number, click ok and it will play the correct sequence of tones. It’s even possible to tweak the duration and pauses.

I have only tested it on my own Nokia 6300, but as far as I can tell it should run on most java enabled mobile phones.

dtmf logo

Here are the jad and jar files. If you want to run the program download them to your mobile and have fun.

At the moment it converts + to 00 and removes +45, as this is appropriate for a danish setting.

Here is the sourcecode if you need to make changes.

DTMF sourcecode

Using Netbeans

I used netbeans 6.0.1 and it was a mixed pleasure. Creating the the flow using a drag’n’drop interface, is well nice for something small and simple as this, but I found that it soon got frustrating. There’s no API to look in, and you have to use the mouse all the time.

dtfmFlow

This is the basic flow of the midlet. It was very quick to set this up, and it were indeed a pleasure to start with. Somewhere along the way a made a mistake, which the flowdesigner and codegenerator couldn’t handle. And no matter what I tried I couldn’t get rid of it, I knew exactly what i was. I had misnamed a variable and managed to let the generated code go into a never-ending recursion. (something along the lines of: private TextField foo() { return new TextField(Foo);} ). But no matter what I tried it just wouldn’t get back to normal. In the end I just created a new project, remade the flow stuff to what you see above, and copied a few functions over.

And the flowdesigner is quick to work with, but I get a nagging suspicion that if you are going to make something a little more complicated than this it will be an annoyance. You might know exactly where and what to change in the source code, but do you remember where to point, click and edit in the designerinterface? Another critique is that even when you know what to do, your workflow gets abruptted by having to constantly shift hands between keyboard and mouse.

To Netbeans defence i must say that I am used to using Eclipse, and changing to another IDE is in it self a frustrating experience. Whats the shortcut for blah, where do I set this. And its quite possible that I just didn’t know enough about Netbeans structure and shortcuts to feel at home.

Credit goes out to : openclipart.org for the image of the phone and dialabc for the soundfiles.

]]>
http://rotand.dk/2008/03/20/dtmf-dialer/feed/ 1
Retro insane asylum telephone http://rotand.dk/2008/03/18/retro-insane-asylum-telephone/ http://rotand.dk/2008/03/18/retro-insane-asylum-telephone/#comments Tue, 18 Mar 2008 20:15:51 +0000 http://rotand.dk/blog/2008/03/18/retro-insane-asylum-telephone/ I recently bought an oldskool rotary phone. I saw it at an auction and it looked nice, but its history was even more fascinating. In its youth it was doing service at the local insane asylum.

insane asylum

image from the museum.

From the leaflet: “Welcome as a patient to the Psychiatric Hospital”
About the Psychiatric Hospital

The highly regarded Copenhagen architect, Gotlieb Bindsboll, built the Jyske Asylum in the middle of the 19th Century. The inspiration for the building, with its crow step gables and many beautiful courtrooms, was taken from the typical Danish manor houses. Its position, with views over the Århus bay was in keeping with the contemporary view of the healing benefits of beauty. The hospital became known as a model institution for the treatment of the mentally ill, also on a European scale. The first part of the hospital was completed in 1852 and it was extended several times over the next fifty years.

kirk phone

The phone is from 1951 1955 and the “electronics” looks aged but in surprisingly good condition. My first plan for it were to gut it, and put a more modern telephone inside, so I could use it for voip. But when I saw that it were in good condition, I thought it would be a shame to kill it entirely.

So I wanted to see whether it would be possible to use it as it is.

For the voip connection i have a PAP2T linksys adaptor (pap), its quite simple to work with. Plug in power and ethernet cable and configure it with a voip service-provider. Initially I used a normal phone to make sure that i had a working setup, before trying to get the rotary phone to work. The normal phone were quite easy to setup and it “just works”.

For the rotary phone there is still some difficulties. But i have managed to get something to work, and I am working on the rest.

First of all i had to change to paps power output to maximum, else it wouldn’t ring the bells. I am still in the process of fiddling with settings for impedance and/or input gain. The problem is that the microphone volume is very low, and if I just turn the input gain up it turns up for the noise as well. It isn’t a problem for me as i have a crisp and clear sound, but apparently it’s a pain to whomever I am talking to. So something has to be done.

Then there is the dialing. A rotary phone dials by using pulse dialing, which in essence means that it disconnects/hangs up, in short intervals as a method of counting the numbers. But any modern voip-adaptor (at least a cheap one) can only function using DTMF. That’s were sending different tones means different numbers. Which basically means that it is enough to send the correct sequence of tones into the microphone in order to dial a number.

I had seen some applets for dialling they did work with the modern telephone, but the rotary phone with its microphone troubles had to get something more. I had success using “DTMF-dial” (from the ubuntu repositories), because it was possible to tweak the duration of tones and pauses.

Next step, as holding the phone to the PC-speaker every time i need to make a phone call, is not an option, were to make a midlet, that’s a mobile applet. A java program for the mobile. Using the mobile as a dialer may seem awkward, but it already holds all my contacts and the voip is a great deal cheaper. I have a midlet at the moment that is at the proof of concept stage. It can dial and I am able to take a number from my address-book dial it using DTMF. It still needs a bit of polishing, but its mostly cosmetic, maybe a list of recent calls would be a nice feature to implement.

soon to come:

  • Nice pictures of the phone, and the electronics.
  • Some software for DTMF dialing on the mobile and a bit about devolping a simple mobile application in netbeans.
]]>
http://rotand.dk/2008/03/18/retro-insane-asylum-telephone/feed/ 2
Flash development http://rotand.dk/2008/02/09/flash-development/ http://rotand.dk/2008/02/09/flash-development/#comments Fri, 08 Feb 2008 21:21:13 +0000 http://rotand.dk/blog/2008/02/09/flash-development/ A course Im taking requires that we use flash and we are left to using specific workstations at school or download a 30 day trial for the 6-7 week project. And well either way we are supposed to be using a proprietary piece of software from Adobe.

The first flash assignment were to create a picture slide show, with captions and a soundtrack. Using the Adobe flash gui its very easy, drag and drop “programming”.

But as Richard Stallman says “its not a matter of convenience, but of ethics”. So I went looking for replacements. In another course I had no problems using octave instead of matlab, so should this be any different? Yes, unfortunately it seems that its very difficult to get the needed features in free software, well at least in the given timeframe.

HaXe is able to compile to swf, as well as doing a lot of other nifty stuff. I just learnt about it recently from this video.

I didn’t manage to make the entire assignment, (yet?) in haxe, but i did make this :
flash presentation(5MB+)

UPDATE

I did manage to add sound and captions.

So how did I do it?

Well first of all i installed haxe and swfmill. Haxe is able to use the actionsscript api and swfmill can create resources so your are able to refference them in you haxe code.Here is the recipe i used to create this slideshow.

1. create a xml file for swfmill, in order to create a resources for the haxe code.This i something like

 <movie width="480" height="480" framerate="25">
   <frame>
      <library><clip id="img1" import="library/newton001Slide_.png"/>

unfortunately swfmill isn’t able to add sound to a library, so that had to be loaded directly from a file. I had some trouble getting it to function on the server but i think that adding “-D network-sandbox” to the haxe compilation might have done something. ???

2. run swfmill, thats swfmill simple slides.xml slides.swf

now i had linkage names for the image files, and could add them to the movieClip.

3. Create file SlideShow.hx

The main part. The basic haxe syntax is pretty straightforward, but since it uses the actionscript api it were mostly a question of getting a hang of actionscript. I did however strugle a bit with making a anonymous function, for the sounds onLoad. I used “static inline function sndStart(succes){…}” , its a wee bit diffrent than what i would do in java. but it works.

3. compile.

make a “make file” for haxe, compile.hxml

-swf test.swf
-main SlideShow
-swf-lib slides.swf
-swf-header 480:480:25:FFFFFF
-D network-sandbox

The last part -D is a conditional flag and as far as i can tell it shouldn’t do anything, but a saw it in Fmp3PlayerHx and when i added it the sound seemed to work from the server, using a URL :s :s

4. run haxe compile.hxml

5. display the pretty result. (try not to go crazy when wordpress decides to help you format the html code….), at first i tried embedding the flash in this post, but wordpress kept on changing the code, apparently if you add code and have newlines between the tags it throws in a couple og <p> tags …..

Now its on a separate page, then you don’t have to download the 5 mb flash file just to view the page, and I can use wordpress with out getting too frustrated.

sourcecode slideShow.hx

The music is “the free software song” this version is by Jono Bacon , and I personally prefer it to the version by Richard Stallman

]]>
http://rotand.dk/2008/02/09/flash-development/feed/ 2
xonix mobile edition http://rotand.dk/2007/07/28/xonix-mobile-edition/ http://rotand.dk/2007/07/28/xonix-mobile-edition/#comments Sat, 28 Jul 2007 02:29:49 +0000 http://rotand.dk/blog/2007/07/28/xonix-mobile-edition/ Having toyed around with J2ME for the freeVibes, I got a bit hooked on coding for the mobile phone.

So I started to recreate the classic oldskool game Xonix, it’s a game I really like. So simple and addictive. It’s not the first time I’m coding it, I have made it as an applet about a year ago (Xonix applet). As well as being a fun game to play I find it a fun game to code too. Though I have had my share of frustrations. The basic functionality is a fillalgorithm, that has to fill an area on both sides of the line / trail you make with the ‘pilot’. This has to be fast and efficient – nobody likes a game where you have to wait for updates.

xonix screenshot

When I first made the game i found a neat fill-algorithm. (flood fill wikipedia). So it should have been a piece of cake to implement it in J2me, its java… I deliberately choose not to reuse old code, as I feared it would be horrible ugly. And a course in datastructures and algorithms should have given me some tools to make a better / cleaner implementation. Then the woes began. J2ME, has no ArrayList it has vector and a stack, and the are not generic so no typecasting. I made a version using Vector, but somehow i managed to use all the memory. When I look back I have a nagging suspicion that the Vector isn’t to blame – but rather me that somehow feed it to much data. No matter what it was I got rid of the Vector and started using arrays, and using indexing like in images or c-“double”arrays (index = x + y * WIDTH). Finally it could fit in memory.

And then I started looking for graphics, a nice game really depends on nice sprites – much more than a beautiful algorithm. I couldn’treally find any and its quite painful, at least for me, to make sprites. It gets real ugly, real fast – hmm no it gets real ugly real slow, because i’m no good at creating graphics. Well the frustrations grew and I ending up abandoning the project. The basic gameplay works, but is buggy and as mentioned the graphics sucks.

xonix screenshot 2

All in all it was quite fun programming, and some day i might give it another go.

]]>
http://rotand.dk/2007/07/28/xonix-mobile-edition/feed/ 0
FreeVibes http://rotand.dk/2007/06/27/freevibes/ http://rotand.dk/2007/06/27/freevibes/#comments Wed, 27 Jun 2007 11:57:33 +0000 http://rotand.dk/blog/2007/06/27/freevibes/ Finally the summer-holiday arrived, now its time to do some fun coding.

I bought myself a new mobile, a Nokia 6300, it’s got all the bells and whistles. Hmm well at least those I could afford. I choose this mobile because it has : Java, mp3 -player, bluetooth and memorycard.

I must admit that i might be a bit of a nerd, so I just had to code something for it. And after “hello world” I found a small and some would say useless application to code.

FreeVibes

I must say I got inspired by vibelet and the article in wired ( Hold the Phone, It’s a Sex Toy ). As the title suggest, its well vibrating. I think that vibelet – though i haven’t seen their program, must be making quite an profit. Because getting a java-enabled phone to vibrate constantly, is quite easy.

So now its Time for FreeVibes, a free software version.

FreeVibes splash ducky
That’s the fancy splash screen And when its in vibrating mode, this little duck is there. And now why a rubberduck ? ( answers )

If you want to try it out, here are the jar and jad files. Just put them on your java-enabled mobile phone. I have just tested it on my telephone, It should work on any new mobile (with java) :

Jad File
Jar File
Source code

Installation

  1. Download the jar and jad file and place them on the phone in the same directory.
  2. Run the applet
  3. Have fun

Technicalities

Getting things to work with ubuntu feisty fawn.

I use SUNs java 6 and the wireless toolkit for the J2me.

Nokia has a nice area with information about coding for their phones (forum.nokia.com). But i didn’t have any success using their eclipse plugin and carbide.j seems to be a windows application. But eclipseME worked like a charm.

When setting up a device for EclipseME i had to make sure that it was MIDP 2.0 and CLDC 1.1. It wasn’t the default and the Nokia 6300 can’t handle MIDP 2.1.

They code and design is inspired by Nokias tutorial on making MIDP 2.0 games.

The images I used are from the openclipart collection, hacked together with GiMP and Inkscape, and I use obexftp to transfer the files to the phone.

]]>
http://rotand.dk/2007/06/27/freevibes/feed/ 2
Cellular Automata II http://rotand.dk/2007/05/30/cellular-automata-ii/ http://rotand.dk/2007/05/30/cellular-automata-ii/#comments Wed, 30 May 2007 20:46:28 +0000 http://rotand.dk/blog/2007/05/30/cellular-automata-ii/ As mentioned before I’ve made a one dimensional Cellular Automata(CA). And although it was intriguing they quickly became very predictive. Actually it was in two dimensions. As the a y-coordinate represented time, but since the states were only depending an the adjacent neighbor’s to the right or left its considered to be one-dimensional.

But they are not as fascinating as CA’s where you expand the neighborhood to include all the eight adjacent cells. That’s called the Moore Neighborhood.

Representing the time dimension. As the intersting part is the evolution of the system, representing time is essential. With a two-dimensional CA it has to be done using animations, and who doesn’t like blinking pixels. This makes CA’s makes even more fun.

In order to decide the state of a cell I look at the Moore neighborhood for every cell on the grid, and count how many neighboring cells are alive. If a cell is alive, then we have to determine whether it survives or dies. If a cell is dead / empty there is the posibility of birth. By defining how many neighbors a cell has to have to survive, and hov many it takes to “give birth” it is possible to run the automata. And this is enough to define a highly complex behavior.

The ubiquitous Conway’s game of life survives if there are 2 or 3 neighbor’s alive and a cell is born if 2 cells are alive, this can be written as : S/B = 23/2. Using a notation like this makes it easy to try out new rules, just adjusting the S/B sets.

I made a small c++ program again using CImg to render these automatons. It’s a rather quick hack, and as such there are plenty off room for optimizing.

But for now it does its job and I don’t intend to develop it further, at least for now. And I think that CIimg might not be the best api for this, I need to look into SDL.

I spent way too much time hacking around to get a nice coloring scheme, and well CImgs intended users are making image manipulation, and not generating images from scratch. SDL is’t intended to generate images from scratch either, but as far as i can tell its easier to manipulate images as int arrays.

Well it does work and i were able to try out some of the rules listed at Wikipedia article about Life like cellular automatons, there online java simulators somewhere on the Internets so I won’t bother to upload any videos – as its much more fun to watch in action an play about with the settings as you go along. If you want to play with the code, well here it is : Cellular Automaton code it’s ugly and you need CImg.h

And now I’ve just downloaded EvoCell which has all the features and a lot more.

Online simulator : MJcell this is a very good implementation. Its fast and has lots of rules and patterns

]]>
http://rotand.dk/2007/05/30/cellular-automata-ii/feed/ 0
Cellular automata http://rotand.dk/2007/05/29/cellular-automata/ http://rotand.dk/2007/05/29/cellular-automata/#comments Tue, 29 May 2007 07:38:57 +0000 http://rotand.dk/blog/2007/05/29/cellular-automata/ rule 54
rule 30

Are quite fun and very intriguing.

What and how.

Generally you represent cells on a grid, and you “evolve” them using simple rules, based on how many neighbors they have.

In the simple version I so far have toyed around with. A cell is either dead or alive.

In one dimension, there are a ruleset and notation called the wolfram rules. Where you use a integer to represent a rule. Each cells faith is based on its own state and the state to its two adjacent neighbors. Here is a table from wikipedia

Rule 30 cellular automaton

current pattern 111 110 101 100 011 010 001 000
new state for center cell 0 0 0 1 1 1 1 0

Its rule 30 because 11110 is the binary representation of 30. This notation makes implementation quite easy. I implemented it this way :

  • Create an image, fill with black
  • Start with initializing the bottom row, put in cells of a different color at random
  • for the row above calculate for each position :
  • int shift =0;
    if (img( (i>0) ? i-1 : img.dimx()-1 , j, 0,0)==c[0])
    shift +=4;
    if (img(i, j, 0)==c[0])
    shift +=2;
    if (img((i+1)%img.dimx(), j, 0)==c[0])
    shift +=1;

  • basically its if left neighbor is alive shift = 4, itself is 2 and right neighbor 1. I wrap neighborhoods so its topological like a cylinder.
  • Heres the smart thing about wolfram rules, we now have the state of the neighborhood represented as an integer. And if we shift the rule with this integer, the lowest bit will represent the state of the current cell. (rule<<shift)&1.
  • continue through all rows from top to bottom.

This will generate some interesting patterns, rule 30 is a lot a triangles. And they have some interesting properties. I make them because I find them visually appealing, but the do have other merits. Look at the wikipedia entry for more

Technicalities : I made a small program in c++ using CImg. CImg is easy to use, and its quick to setup up a disply and handle events. (eg lefttclik =use same rule, initializ again, rightclik = next rule)

And though one dimensional cellular automata’s are intriguing and “fun”. They quickly get boring to look at, so I went for two dimensions. More about that in a later post.

]]>
http://rotand.dk/2007/05/29/cellular-automata/feed/ 0
another one bites the bits http://rotand.dk/2007/05/27/another-one-bites-the-bits/ http://rotand.dk/2007/05/27/another-one-bites-the-bits/#comments Sun, 27 May 2007 19:33:18 +0000 http://rotand.dk/blog/?p=3 Well it was ment to happen.

Everybody has one, so now I have to join in, with another pointless blog.

I will primarily use it to show off :

  • Code – i like programming
  • Weird links
  • I intend to stay away from political and personal rants.
]]>
http://rotand.dk/2007/05/27/another-one-bites-the-bits/feed/ 1