Trying to assign to an un-named type #254
Replies: 30 comments
-
Posted at 2014-04-06 by mattbrailsford Strange! If I use dictionary notation when defining my additional methods, everything seems to work. Does this mean the first way of doing it has a bug?
|
Beta Was this translation helpful? Give feedback.
-
Posted at 2014-04-07 by @gfwilliams Hmm. I think it's doing the right thing - maybe Rick can say for sure. It fails because of writing There are some other things though:
|
Beta Was this translation helpful? Give feedback.
-
Posted at 2014-04-07 by mattbrailsford @gordon thanks for the tips. A few things:
|
Beta Was this translation helpful? Give feedback.
-
Posted at 2014-04-07 by @gfwilliams Hmm... I did try it out - I deleted that function definition and it worked... I just saw the fillRect issue - I'll look into it...
You could do something a bit like:
... assuming you have the buffer - but unfortunately right now graphics can only do 1,8,16,24,32 bits. It'd be good to add more options though. at the moment you can use 'ArrayBufferViews' to re-interpret array data very efficiently though:
|
Beta Was this translation helpful? Give feedback.
-
Posted at 2014-04-09 by mattbrailsford Hey @gordon Regarding switching the callbacks for an array buffer, can you suggest a way to handle the bit of code at line 40? Basically, I wire the LED matrix on the opposite side you are supposed to (the chip is meant to be on the back, but I make it so it sits under the LED matrix leaving me a flat back to mount easily) which means I have to do some shifting. Basically what happens is, think of the image being in for segments, top left, top right, bottom right and bottom left, well with this wiring, the top left square swaps with bottom right, and top right swaps with bottom left. So you end up with 4 lots of 4x4 squares rendering correctly, but in the wrong order. In my original code then, I just shift things by 4 pixels, however once it's been converted to a uintarray, I don't know the right way to do this? I'm assuming it'll use some bitshifting, but after playing around with it before, I couldn't come up with the right shift (especially when you take the colours into account aswell). You got any suggestions? (Likewise for the rotation too) Matt |
Beta Was this translation helpful? Give feedback.
-
Posted at 2014-04-09 by @gfwilliams Argh. so you have to send one byte for 8 pixels of green, and one byte for 8 pixels of red? I actually updated graphics to handle 2 bit colour (if you try one of the pre-release binaries), but that does the bits all next to each other. So... If you assume that we'd use Graphics, and the bits are
And then you 'just' have to figure out a way of un-interleaving each pair of bytes - from: There are some fun bit hacks that can do things like this using multiply, & and shift - although I only see a way to interleave on that site - not un-interleave. It should be possible. Assuming we start with
And you have 64 bits to play with, so you should be able to do at least 8 pixels in red and green at once (maybe 16 ;). All good fun - if you're into that kind of stuff :) |
Beta Was this translation helpful? Give feedback.
-
Posted at 2014-04-09 by mattbrailsford Ok, I'm confused :) I must confess, this stuff doesn't come naturally to me, but if you look at my drawPixel method, and how it handles colours, this is how I currently understand this, see attached (correct me if I'm wrong). So I believe it builds up a matrix where for every Y position, it stores a 16byte value, the bits in that value dictate whether an LED should be on or off. I think the first 8 bytes are for green, and the second 8 are for red, or maybe the other way, I can't tell :) if they are both on at the same time thought, you get yellow. Now when I'm talking segments getting mixed up, see the black lines on the picture, each 4x4 square renders as it should, but each black square is in the wrong location, so the top left green one, is in the bottom right green one and vica-versa for the other opposite corner / colours. So, is that how you understood me? and do your examples hold true for this? and also, looking at my code, is my assumption of how this work correct? :) Cheers Matt Attachments: |
Beta Was this translation helpful? Give feedback.
-
Posted at 2014-04-09 by mattbrailsford Holy heck, I think I've just learnt something :) So, playing with the buffer array I have, it's seems I was wrong about the order, it's red, then green, but the rest is true :) And I've also figured out how to bitshift the segments in an array entry (so the 1st and 3rd block of 4 shift right 4, and the 2nd and 4th shift left 4).
Woo hoo! :) So what would be the most performant way to do this within my updateDisplay method? My natural instinct would be to create a new array, and loop the other creating new (shifted) values, then do what I'm currently doing now to render it. Would that be the way to go? |
Beta Was this translation helpful? Give feedback.
-
Posted at 2014-04-09 by DrAzzy
The first thing I would do is print the data being sent to the display (in the form it's being sent) to the console before sending to display, then convert that to binary and draw out what you'd "expect" based on that on graph paper, and compare it to the pattern on the display. That way, you'll know if the issue is that the display doesn't work the way you think it does, or just an issue with the JS that prepares the data to send it. Edit: Note - this was posted before your most recent post - it sounds like you've made some progress, so this may not be useful anymore. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2014-04-10 by @gfwilliams Right, so what I meant is that while your display accepts the data as you say, the Graphics library in 1v61 will interleave red and green (like it would for any other bit depth). I'm not going to do a fancy colour diagram, but the data will look like:
So the code I had with the crazy shifting stuff will turn that into what you had (eventually). If you don't want to use graphics and just want to carry on as you are, and you want to do it quickly, I'd suggest just repeating the code you have 16 times (once for each nibble):
You might find that putting it into a Uint16Array and doing a view of it was easier, but to be honest you'd have to benchmark:
PS. Multiply-AND tricks are fun. If you think about what is going on with a multply, it's like a repeated shift-add:
So if you multiply by 5 (0b0101) you've got:
So it's potentially 64 shift and adds in a single operation :) |
Beta Was this translation helpful? Give feedback.
-
Posted at 2014-04-10 by mattbrailsford Thanks @gordon, I get what you mean now with the interleaving. I'll do what you said and take a look at the values being rendered and see what I can come up with. Haven't quite got my head around the multiply-AND yet, so I think some experimenting with that is in order too. Sounds powerful though :) Matt |
Beta Was this translation helpful? Give feedback.
-
Posted at 2014-04-10 by mattbrailsford @gordon looking at converting the callback to a graphics array then. If I switch the callback to be a buffer array, when I debug out the contents of the buffer, I have an array as follows:
If I format this a little, you'll see it is meant to print out an E with the E in red, and the background yellow:
So, if I look at what was previously being sent down the line, it needs an array with the buffer:
Which should be the buffer of:
But with an extra Converting the Uint16 array to binary, we can see that it is:
(Not sure whether the E being backwards is something I've done, or just the way it is, but I'll figure that bit out later). So, should I loop through the buffer array and construct a Uint16Array (handling each entry one at a time, kinda like the drawPixel method currently but all in one go at the point of render) and then do what I'm currently doing to create the array buffer with the extra
With all of this though, I'm not sure where the interleaved colour handling you were talking about in buffer array comes into play as I can't see it? Am I missing something there? Matt |
Beta Was this translation helpful? Give feedback.
-
Posted at 2014-04-10 by @gfwilliams If you update to 1v61 now, you can get 2 bit graphics:
Does that help? That's why you'd want to un-interleave... |
Beta Was this translation helpful? Give feedback.
-
Posted at 2014-04-10 by mattbrailsford Awesome, yea, that's what I was trying to get to :) I've got this code now which should do the un-interleaving (per row)
Matt |
Beta Was this translation helpful? Give feedback.
-
Posted at 2014-04-10 by @gfwilliams
and then it all got a bit ridiculous:
And to swap the quadrants around, all you've got to do is swap the |
Beta Was this translation helpful? Give feedback.
-
Posted at 2014-04-10 by @gfwilliams Ahh, I didn't see your last post - I was getting carried away. If I'm honest your un-interleaving looks a lot less insane than mine. In the code above, instead of I'm unsure if it really is faster than a simple for loop - but it looks like it is :) In both our cases we could actually do more bits in an operation than we have - but then we're back to the problem of swapping the quadrants. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2014-04-10 by mattbrailsford Ok, haven't fully read your posts yet, which I will now, but here is what I have currently, which does work:
the 'k' and 'shift' part of the sequence do the fixing of quadrents ('k' shifts up / down and the 'shift' code, shifts horizontally). Because I need to write one coordinates value to a different location, that is why I needed the 'b' array otherwise I'd overwrite values in 'a' I hadn't processed yet if I just tried to update 'a'. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2014-04-10 by @gfwilliams C00l - to be honest for 8 iterations that's going to be more than fast enough, and it's actually readable :) So you can actually write text with the graphics lib and have it display on the matrix? |
Beta Was this translation helpful? Give feedback.
-
Posted at 2014-04-10 by mattbrailsford Ok, I've had a read of yours. I guess it comes down to performance vs readability. What kind of performance hit does adding a loop create? What's the best way to test performance of a method? |
Beta Was this translation helpful? Give feedback.
-
Posted at 2014-04-10 by mattbrailsford oops, missed your reply. But seems you were of the same mind as me anyway :) And in answer to your question, yes, yes you can :) Check out the demo http://www.youtube.com/watch?v=rkK0aqxzk-M&feature=youtu.be |
Beta Was this translation helpful? Give feedback.
-
Posted at 2014-04-10 by @gfwilliams Probably best to remove the I2C write, and then just do:
For 8 iterations the performance hit of a loop won't be that great at all - I was just getting carried away :) |
Beta Was this translation helpful? Give feedback.
-
Posted at 2014-04-10 by @gfwilliams That looks great! So did you hack it onto the existing game shield? |
Beta Was this translation helpful? Give feedback.
-
Posted at 2014-04-10 by mattbrailsford Yup :) I did a write up for the creators here (need to update my project page with the same), but I basically removed the original matrix, stuck the adafruit shield in place, and hot wired it the the relevant pins. Works a treat :) The great thing is, it's got it's own internal oscilator, so I only have to send it something when I want it to update, not like the previous one that required every line updating every ms. Matt |
Beta Was this translation helpful? Give feedback.
-
Posted at 2014-04-10 by mattbrailsford @gordon regarding rotation, would this be something easy enough to add to arrayBuffer? or should I implement my own solution for now? (I've created an issue for it on GitHub) |
Beta Was this translation helpful? Give feedback.
-
Posted at 2014-04-11 by @gfwilliams It shouldn't be too hard. It needs doing anyway for lots of different cases so I'll take a look at it :) |
Beta Was this translation helpful? Give feedback.
-
Posted at 2014-04-11 by @gfwilliams Done. Try from here http://www.espruino.com/binaries/git/commits/7731c5766500ebf664f99339b56298d1dac9e2ce/ @jumjum might be interested in this too, as it should work with his display driver |
Beta Was this translation helpful? Give feedback.
-
Posted at 2014-04-11 by mattbrailsford Hmm, doesn't seem to be rotating. Does it physically rotate the data in the buffer so that the buffer order is the order you want to render in? |
Beta Was this translation helpful? Give feedback.
-
Posted at 2014-04-11 by mattbrailsford Doh! Ignore me, it would help if I removed my setRotation method :) Removed and works a treat :) |
Beta Was this translation helpful? Give feedback.
-
Posted at 2014-04-11 by mattbrailsford Something that might be handy is in the constructor of the createArrayBuffer if we could maybe pass in a rotationOffset? Seems I had to mount the display upside down, so could be handy to say offset rotation by '2', then any calls to setRotation would be the rotation + the offset (wrapped of course). |
Beta Was this translation helpful? Give feedback.
-
Posted at 2014-04-11 by @gfwilliams I covered this in the bug report you made - I don't think it's worth adding extra complexity for that case at the moment... I'd hoped setRotation would be used for when the display was mounted, and not for rendering fonts at different angles - if that's common I ought to do it some other way :) |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Posted at 2014-04-06 by mattbrailsford
Hey Guys,
I'm trying to write a library for my Adafruit Bi-color 8x8 matrix so that I can release it for others to use. As it is a display and so involves drawing shapes and such, I thought a good idea would be to extend off of the Graphics object and some custom methods to that and return that as my modules API, like so:
The problem is, I keep getting errors when I try to add additional methods to my
display
object. If I extend theGraphics
class viaprototype
then everything works, however I don't won't my methods available to all Graphics objects, just ones returned from my module. Anyone know what I'm doing wrong (I'm sure I saw @gordon do this kind of thing in the 123-LED demo video).Matt
Beta Was this translation helpful? Give feedback.
All reactions