Digital Me

Random contributions to digital noise

Archived Posts

Displaying posts 1 - 10 of 36

Recently I got D-Link DNS-320 ShareCenter and enabled UPnP on it so I could stream videos to my Xbox 360. I was getting the following error for some videos:

Unplayable Content

Can’t play this content because it may not be supported.

Status code: 69-C00D36BE

But it was working for other videos, and when I tried playing them from USB storage, it worked just fine. What I figured out is that videos in parent folder worked just fine and they all used the same encoding for both video and audio. I moved problematic videos so to parent folder and, guess what – they played just fine. I might investigate further why is this happening, but seems that path to the videos might’ve been to long or something.

Other error I’ve encountered is:

Uplayable Content

Can’t play this content because it contains audio or video with unsupported codec.

Status code: 80-C00DF242

Now, this is actually unsupported codecs. The videos in question were encoded with DivX 3 and 4 which are unsupported – only DivX 5 and later are supported on Xbox. I’ll see later on how to transcode them with ffmpeg and I’ll update here (should be easy).

Oh, yes, nearly forgot, when I was getting the latter error Xbox would say openning media or similar, in the case of the former it wasn’t even trying to open it.

Recently I got D-Link DNS-320 ShareCenter. Seems very good value for the money, and I already had 2 disks I wanted to put in a RAID. Anyway, there’s there was a bug in the firmware that would only allow printing as admin user (once custom users are added to the NAS printer cannot be accessed as a guest I suppose anymore but new useres don’t have permissions to access it).

That’s not a bother in Linux – it asks for permissions and you can print, but on Windows it just says the printer cannot be connected or something. So after some digging solution is to redirect the printer to a local port and manually add credentials under which to connect. So in general case this can be used:

net use LPT1 \\servername\printername password /user:username

Or in case of DNS-320, since using admin user is required and the printer shows as lp it goes like this:

net use LPT1 \\you_nas_machine_name_or_ip\lp put_admins_password_here /user:admin

After doing this from Harward and Sound -> Printers do Add Printer -> Add Local Printer -> LPT1, it’ll ask to choose drivers (TIP: pre-install them) and after that printer’s ready for printing.

For more info on net use command go here

Using JavaScript Modules - A Catch

Thursday January 13, 2011 @ 12:44 PM (PST)

I’m sure I saw somewhere an example how to use JavaScript modules in Firefox extensions and I just used that snippet. Anyway, I was recently caught by a conflict between New Tab Jumpstart extension and NetVideoHunter Basically they could not work together and whichever was loaded first was working properly, second loaded wasn’t.

It turns out that conflict was due to both extensions registering modules folder with the same alias modules. Both extensions would thus import their files with a similar uri: Components.utils.import(“resource://modules/some_module.js”);

The reason why this was failing is resource://modules will be registered for the first loaded extension so for one of the extensions some_module.js file will not be found in the registered location (or even worse it will be found but would be completely wrong).

It was simply fixed by changing registration in chrome.manifest to: resource jumpstart content/modules/ and replacing resource://modules to resource://jumpstart in all files.

Now when I look at it it’s completely logical but you do it once, don’t think about it at the time and you forget about it but it comes back to bite you later. All in all, if you plan on using modules in your extension do not register your modules folder with modules alias or similar, use your extension’s alias.

Experimental HexWax expandIO-USB Library on Git

Saturday November 20, 2010 @ 12:19 PM (PST)

I have added experimental library for HexWax expandIO-USB to GitHub . It should work fine for official evaluation board as well as it works for mine custom made one. The library is still in early stage so some significant changes are to be expected to both code and code structure.

Read only repository is here: git://github.com/mlalevic/HexWax-expandIO-Python-Library.git

Nearly all commands from the firmware are covered, and I have added two examples – one single threaded and one multi-threaded – the same example – blinking LEDs.

See how simple it is:

All commands are created like SetBit(“TRISC”, 6, 0), method pack() is used to get byte array representation for sending to device. Unpacking is done by a corresponding unpack class – like SetBitUnpack, and it unpacks input packet into member attributes.

Here’s multi-threaded version which is even simpler:

UsbBackgroundRead spawns a thread to read data from USB device in background. This is useful if the device can have external events – interrupts.

Anyway, got to do some more documentation on it and add more examples soon.

In my earlier post I was using libhid however due to it’s alleged problems with multi-threading I decided to use PyUSB instead. The code is a bit different, however a little shorter and simpler.

One notable thing to be aware of is that device I’m using is HID device and Linux is automatically loading HID drivers for it so it needs to be unloaded for PyUSB to continue working. That’s done by calling dev.detachkernel_driver(0)_ I suppose the device is used as vendor-specific device then, but who cares.

Anyway, here’s the code, should be a bit simpler than before:




Using PyUSB with NetBeans

Wednesday November 03, 2010 @ 05:49 AM (PDT)

I’m going to rewrite my previous example on programming USB with Python on Linux. libhid I’m using at the moment is using old version of libusb and that version seems not to be behaving best in multi-threading environment. The new version of libusb has completely different API, so I decided to use PyUSB a Python library wrapped around libusb.

“This should be straightforward” I thought to myself, however I had trouble making it work with NetBeans I installed PyUSB according to instructions and it seemed installation was successful, but no joy in NetBeans. Even import usb.core was throwing error ImportError: No module named core That was strange since at least import usb.core worked fine in IDLE.

Anyway, to cut the long story short, PyUSB was installed in /usr/local/lib/python2.6/dist-packages, when adding it to path, and other experiments did not yield expected results, I just copied files to /usr/lib/python2.6/dist-packages where I have other libraries installed and I know them working. After doing that everything was fine, I could actually do some coding. Why it did not work in the first place? I don’t have a clue, however I won’t be investigating it any further.

Linux USB Programming with Python

Wednesday October 13, 2010 @ 04:14 PM (PDT)

Recently I started doing some hardware design, just for fun. Anyway, I got my hands on one microcontroller with USB interface so I wanted to see how I can control it from my Linux box. It turns out to be quite easy and with this any general USB HID class device can be controlled (USB rocket launchers, USB toys and such I suppose).
Anyway, this post just lays out basics on how these devices can be used with Python on Linux. (Mind though that I’m Python, USB and Linux noob so don’t take this for granted – and of course no warranties whatsoever.)
First of all we need some library to access USBlibhid there should be Python bindings with it. I got both the library and the bindings with the following command (on my Ubuntu):

sudo apt-get install libhid-dev python-hid 

Then we need some hardware. I suppose any suitable Hid device can be used as long as communication protocol is known. I created my own device using HexWax expandIO-USB which is just a fancy name for (in my case) PIC18F2455 with HexWax’s firmware. I got mine from Farnell . The chip supports 10-bit A/D, digital I/O, counter input, interrupts, comparators, CCP, SPI, I2C so we can control loads of different peripherals if we wanted to.

The board is very simple and I used simplest reference schema from the documentation. It doesn’t follow any good USB design practices, I’m sure, but it can be assembled on a breadboard . Here’s the schema:

USB board schema

mind though, I used PIC18F2455 but it’s the same thing
And as I said it can be assembled on a bread board:

HexWax on breadboard

This image was made in Fritzing

Very simple – only 6 capacitors, 2 resistors, a LED, a crystal, the chip itself, USB connector and few wires. I assembled it quickly, and instead of using USB connector I cut one USB cable I wasn’t using and stripped off wires and plugged them into the breadboard – it looked ugly but it worked (of course use this approach on your own risk, as with anything else). Here’s USB pinout . Btw, I added a LED and one resistor just so I have some kind of a peripheral to play with.

After I finished testing the design on breadboard I used stripboard to create a more permanent board:

HexWax on stripboard

Basically the same thing, I just added some receptacles on both sides of the chip so I can connect other peripherals later.

Oh yes, since there’s HexWax firmware preloaded there’s no need to do any microcontroller programming, all’s done from PC.

Off to programming part and Python. First of all lets see how this board shows up to our system when we plug it in. Here’s output of lsusb command:

HexWax plugged in

It shows up as a device with ID 0b40:0132. This can be changed in code but I couldn’t be bothered. So lets put libhid into action. Here’s code that is initializing the library, finding the device, reading it’s details (so far all standard code from libhid), then reading device’s firmware, setting our LED pin to be output, and blink 10 times with it with 1 second pause. Simple. Comments are in the code :





This was a quick run through. Hopefully I get some time to play more with this in the near future, and will follow up with new posts.

Custom notification box in Firefox

Tuesday September 28, 2010 @ 02:38 PM (PDT)

Out of the box notifications in Firefox as far as extension developers are concerned are pretty blend. You can only set icon and text, which is enough in most of the cases; however while working on New Tab JumpStart extension I wanted to show more than that.

I wanted to show list of all search engines in Firefox. One of the suggested solutions requires manual control over animation, persistence counting, styling, etc. So I tried to see if there was a simpler or at least more elegant solution. And, I might have found it.

1) Get notification box and add notification
2) Replace notification body with custom binding

Should be simple as that. So here’s a short snippet for doing that (see below for the full code reference, this is just a cut out showing principle):

var nb = getBrowserWindow().getNotificationBox(window);
var n = nb.getNotificationWithValue('jumpstart_searchnotice');
if(!n){
    nb.appendNotification('', 'jumpstart_searchnotice',
                              'chrome://jumpstart/skin/img/JumpStart32.png',
                               nb.PRIORITY_INFO_HIGH, []);
    n = nb.getNotificationWithValue('jumpstart_searchnotice');

    var p = n.ownerDocument.getAnonymousElementByAttribute(n, 'anonid', 'details');

    var bx = n.ownerDocument.createElement('hbox');
    bx.setAttribute('style', '-moz-binding: url("chrome://jumpstart/content/bindings/thumbnail.xml#searchEngines");');
    bx.setAttribute('flex', '1');

    p.parentNode.replaceChild(bx, p);
}

n.persistence = 10;

Full code how it’s used in the extension is in tabView.js search for showSearchNotice function.
getBrowserWindow is getting current browser window so we can get notificationbox . Then we are getting or creating the notice. Text doesn’t really matter since it’s going to be replaced anyway.

var p = n.ownerDocument.getAnonymousElementByAttribute(n, 'anonid', 'details');

This part is crucial since that is the element we are going to replace (it’s parent is container we really want but it doesn’t have a suitable attribute to get it). Note though that ownerDocument should be used to get element or create new element since it is not the same document as page’s – it’s really chrome window’s document.

bx.setAttribute('style', '-moz-binding: url("chrome://jumpstart/content/bindings/thumbnail.xml#searchEngines");');

This is also important since this way we’re adding custom binding to the notification. If XUL markup is complex this is much easier to do than adding children manually.
Note as well at the end how properties of notification can be still controlled and Firefox handles them correctly.

Here’s a snippet of the XBL binding:

<binding id="searchEngines">
    <resources>
      <stylesheet src="chrome://jumpstart/skin/tabView.css"/>
      <stylesheet src="chrome://jumpstart/skin/xbl.css"/>
      <!--<stylesheet src="chrome://jumpstart/skin/overlay.css"/>-->
    </resources>
    <content>
            <xul:hbox class="searchEngines">
               <xul:spacer flex="1" />
               <xul:arrowscrollbox anonid="searchEnginesContainer" flex="1"></xul:arrowscrollbox>
               <xul:spacer flex="1" />
               <xul:label class="customlink" value="&back;" onclick="loadURI('chrome://jumpstart/content/tabView.xul', null, null, true);" />
            </xul:hbox>
    </content>
    <implementation>
  ...

That is snippet from thumbnails.xml search for id=“searchEngines”. Basically, further in the implementation I’m just enumerating all search engines, that’s why the content doesn’t look like contains much.

And the final result of this is:
Custom Notification

Oh, yes, some final thoughts. This seems to be more elegant solution than what was suggested on MDN however this might break if Firefox developers decide to change layout of notifications in future. That being said this works in both 3.6 and 4.0 beta versions so I don’t expect it to change soon.
And another thing, CSS is applied incorrectly by Firefox so broader CSS selector is applied after more specific one. Note customlink class in content of the XBL, that was applied before label style which doesn’t make sense at all. That was effectively breaking my styling so I had to add the styling to my overlay.css which I didn’t feel like. My overlay.css is added as overlay to the browser itself so I suppose binding’s overlay is applied first regardless of specificity of CSS selectors and that seems to be completely wrong but what can you do. Anyway, just so you know and not waste hours in frustration.

Set Hard Drive Name in Ubuntu

Tuesday May 11, 2010 @ 02:49 PM (PDT)

This one is simple. Ubuntu is using volume label to show HDD name. My file system is ext3 so tool of choice is: e2label, eg. to name your disk Data use something like this:

e2label /dev/sda1 Data

For more info see Ubuntu documentation: Renaming USB Drive. Tools for other file systems are mentioned there and other useful commands.

Setting favicon for XUL pages

Friday January 22, 2010 @ 03:35 PM (PST)

This post is basically inspired by a problem I encountered with latest Firefox release (3.6). Some styling changed for no apparent reason at the end it turned out to be favicon I had set in XUL.

Basically, with favicon set my vbox stopped filling the window so my styling was off – background image was cut off, and I got some weird popup menu behavior where menu appeared to be shifted off the button.

Anyway here are a few simple examples that shows what is going on and how to solve it.

This what I want to have:

<?xml version="1.0"?>
<window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
        xmlns:html="http://www.w3.org/1999/xhtml"
         >
		 <vbox flex="1" style="background-color: red">
			<hbox height="100" style="background-color: green"></hbox>
		 </vbox>
</window>

This would look like this in browser:

Now lets try to add favicon there:

<?xml version="1.0"?>
<window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
        xmlns:html="http://www.w3.org/1999/xhtml"
         >
		 <html:link rel="icon" />
		 <vbox flex="1" style="background-color: red">
			<hbox height="100" style="background-color: green"></hbox>
		 </vbox>
</window>

Note that doesn’t really matter what icon you put there. I expected the browser to show exactly the same thing but it did not happen:

Now, that was unexpected. Basically the whole box collapsed and Firebug at the bottom shows that code is there, just not shown.

Fix for this was just to add style="display:none" and that was it:

<html:link rel="icon" style="display:none" />

And we’re back on track, browser is showing our page correctly again. This works in Firefox 3.0.x and 3.5.x without adding style attribute, but it has been changed in Firefox 3.6 for some reason so be warned. I’d suggest that if you have favicon specified like this and your page is not behaving as you expect try this fix first, my popups were shifted by the size of a spacer to the left and once I’ve applied this it was back to normal.

Copyright © 2012 Mihailo Lalevic. All rights reserved.
Powered by Thoth.