Openhab 2 and Icon Possibilities

In the free time that I have, I am attempting to redesign the icons for openhab. I want to stay in line somewhat with the material design google now has on their interfaces. So, I started making my own interface with tasker and designed icons to work for me using photoshop.

Not wanting to do too much work if the interface for openhab 2 is going to be updated, I asked if we could have something larger than 32x32 pixels. These look real bad on pretty much everything today. So I asked if they would be updated and was told that it has not been done yet. So, I learned illustrator and created my first set. These include the slider light icons and the on and off icons needed to replace the current ones in the directory.

The real bad part, this took 3 days to do, and I can no longer look at my designs objectively. So hopefully I can get feedback from some people out there about the current designs. I am up to change anything. One thing that would be nice, is 1% increment changes on the slider feedback icon. Then it could be more visually accurate to the actual light state.

Anyway, here is what I have.


More to come.

New Home... I Need a New Home Automation Setup

upload.png

5-6 year's ago, I attempted to create an all in one home automation system. I was capable of cobbling together several different half working setups. But quickly I realized it wasn't as capable as my mind wanted it to be. I spent months programming a custom website with custom code to send to the different systems to try to make them work together.

using event ghost on a Windows computer a touch screen computer on another Windows setup and IP cameras and X10 home automation switches and outlets as well as a barcode scanner. A usb uart ir transmitter/receiver also. I even attempted voice control using a Bluetooth speakerphone as a remote control. And even an android app with touch controls.

All i can say is that i wasted lots of time, I did learn several things about project planning and interacting between several protocols. But the technology at the time tried to lock you in to a single manufacturer. And they all pretty much sucked even when using their setups. X10 in a old house with questionable wiring schemes is flaky at best. And I eventually stopped using them all together. This was before tasker became so well improved and at the start of the IOT discussions. 

The barcode scanner was too far away from the fridge and the database was limited. The Bluetooth voice control was attempted using a combination of Windows voice service and event ghost. That never worked. And updating code on a website to add buttons was tedious.  

Two years ago i attended ces and saw at least 50 booths of automation devices. Most using zigbee or zwave and most claiming compatibility with other products in that sphere. I couldn't wait until those devices came out, and today, they are here.  

upload.jpeg

This is not to say that they are perfect. But, i now can use several systems depending on what hardware they offer, together. The bad thing this time around is the need for a cloud infrastructure to use the protocols. This must be a way to mine data for consumer behavior, because there is not a need for the cloud to run these systems. It may be easier for the end user to set up, but useless when the internet goes down.  

This is where openhab comes in and delivers more than I have time to do. Openhab, as the name implies, is open source and compatible with everything out there today and possibly everything out there tomorrow. It is built on java and can be run almost anywhere. Currently, it's successor is being developed, and it looks good. Right now, 1.6.2 is out and stable. 

I looked in to getting a smart things hub and several others before i saw the hackaday post on hacking the GE Wink hub. This hack allows local control over any of the devices connected to the hub, without the wink app or an internet connection. 

I then found the instructable on the uber home automation controller, and his addition of the wink in to it. This brought me to openhab and raspberry pi with the wink.the next day i ordered a hub and two dimmable link lights from home depot for $54 shipped. Way less than any other device and has a great offering of radios available for future use. 

I then found a deal on rfm69hw 918mhz modules and bought 10 of those. I have a large number of atmel 328p chips and all of the components to build arduinos when needed. Just had to order the 8mhz crystal and the TI switching regulator package for 3.3v because my current build uses a 5v version of the package. Just have to design the board with an array of connectors for sensors and output options to make an all in one device for each room. Not sure what I'm adding yet, but I like data. 

This board I'm making will first be for through hole components, because i don't have to purchase them. And 20 boards will cost less than 50$, I can always design it with surface mount at the same time and order them for future use. And at this point, the calculations work out to around $20 per node.  

I've already set up the wink and successfully created tasker events to trigger curl over ssh using voice commands. It has lag, but I think using openhab as an in between might trigger things faster. Not sure yet though.

 

So far I've thought about several sensors to use. 

Temperature and humidity

Light

occupancy

Window and door switches

i would also like to trigger notifications to either be played outloud or signified by flashing lights or color. 

Since some commands and devices are 1 way, with lights, i can use a light sensor to detect if the light is on. Then send an update to notify me of the status.  

A refrigerator door sensor, oven sensor, laundry sensors through an accelerometer or maybe a more simplistic method. I could even make a switch of some sort wherever the laundry baskets sit to notify me of a full basket. This could be in every bedroom as well, then instead of telling my kids to bring it to the laundry, they could just get notifications on there devices or out loud when detected in their room. 

A camera system for outside is already a given. And integrating all of this in one package to offset eventual incompatibilities with manufactured devices is going to allow me to adapt my setup as new and interesting devices come in to existence. 

As i troubleshoot and learn these systems, i will try and keep a list of links I used to set this up. I've had several problems already with spread out answers on forums that i have already gained from. There is not one single place to go yet to find all of this. Hopefully the notes I keep will allow someone to eventually set up a similar system with an easy reference to access.

ADD and the internet

Why can't I go a single day without wanting a new project. At this point, I'm up to a hundred projects that need completing. I have most of the parts, but none of the time needed to complete them. I have drawers of components with labels to entice me in to a weekend project.

I'm going to lie to myself and say that this one, this one will decrease my work flow time. Although, I'll spend a month deciding how to build it. At least i already have the components to build this. He doesn't have the exact measurement, but I'm already planning on making the hid calipers, so why not use those calipers to perform the task? I just need to purchase the digital protractor as well. 

His device is using potentiometers and servos to calculate distance moved. But this has been solved by using capacitance in the pre made devices out there.  the accuracy over distance is very good up to 6 inches, which for most tasks is good enough. I've thought about using potentiometers, optical encoders, magnetic encoders, and laser distance sensors. These all have shortcomings, in accuracy or in resolution. Off the shelf devices using capacitive sensors are accurate enough and less than $20 each. Lots of the inexpensive models have some sort of serial communication built in and taking advantage of that is my plan. 

I would like to use the same code, but modified to work with the of the shelf products and some 3d printing. ID i have time to complete this, i would love to add it to my list of tools. 

Dig ring welder

i ran across a diy spot welder and decided to build one for creating heading elements and temperature probes. I have plenty of the raw material, just needed a way to do it myself. The cost of manufactured probes is crazy. This should reduce my cost to pennies.  

I ordered the components from digikey and received them today. I'll throw it together tonight to test and then design a mini drill press like device to house it and make it portable. I'll post the links to the design and my build later. 

Sidetrack from a hackaday post

While reading hackaday, I saw that someone copper plated a 3d print using a solution of acetone and graphite powder. After quickly creating some copper acetate from a equal amount of 3% hydrogen peroxide and 6% vinegar and some copper scrubbers, I had an idea besides the obvious copper plating of 3d scans of my children. 

I have yet to try this, but it seems possible. I will test this tonight and report back later. So, design and print an object, lets give it some LED eyes for fun. I guess I could just run a couple wires through a predefined area and then connect the led in each eye. Or, I could paint on some graphite and then copper plate the traces!!!! This may not work, but the idea is sound. if the resistance is low enough and the traces are OK, I should be able to either use conductive glue or actual solder to attach the pieces. Since you would want breaks along the pathway for components, you would either have to attach the cathode to each broken section, or you could paint the mixture on to the entire pathway and scrape off the area that needs the break for the component. I will try the latter first.

 

A novel method of sensing

While listening to embedded, a podcast on embedded development, the interviewee described how he was capable of sensing the pulses emitted from the common water meter. He did a project for the recent hackaday space prize, and got to the top 50 contestants.  

The water meter uses a magnetic coupling between the flow blades and the geared counter within the meter. To avoid making any changes to the meter, he had to find a way to measure the magnetic field. This is where the idea becomes interesting, using a magnetometer . Since a magnetometer is capable of sensing magnetic north, it should be capable of sensing other magnetic fields. Sitting the magnetometer near the housing picks up the spinning magnetic field and translates in to a pulse. Although he said he had to hack it a bit to get the results and that a different setup would give better results, the proof was there.

This have me an idea for a measurement device. While researching optical encoders to find a way to measure small distances accurately, I was disheartened to see that the smallest collection slit available is .5mm and costs more than it is worth. I didn't spend too much time looking, so they could produce smaller ones. But I'm looking for a micrometer level measurement device.  

I don't have time to do this now, but i will eventually get to this one. Attach a magnet or magnets to a shaft, spaced equally, and then use gearing to spin the shaft several times per mm. Then use the magnetometer to sense the field. I'm not sure, but if it is sensitive enough, a on off touch doesn't need to be the measurement. Potentially, if the magnets are calibrated to the same magnetic output, you may be able to achieve smaller increments by sensing the edges as well as the apex of the field. 

Add this to the end of a digital caliper to roll along distances and then output as a keyboard. Possibly adding multiple buttons to label measurements and submit the text. Or use it as an accumulative measurement device. Roll, press save, roll press save, roll press save and send as output.

I had to put this thought out there, as a reminder to myself on the future.  

New Year and a New House

So, even though i have a million projects I would like to be able to dedicate myself to, I have real matters to deal with.

We are in the process of selling our home and moving to a new one. I haven't figured out machine vision to the extent that I would like to be right now, and it looks like that is going to be even further off now with the new house. Hopefully the problem is not fully solved by someone else by the time I can get back to that. i will probably have to relearn everything, but I did heavily comment my code. 

The good news, new shop and new projects that let me learn new things. Since I plan on building our new kitchen and all of the cabinets, my first task is building a table saw/ router table. I plan on converting my portable table saw, in to a fixed base saw. Maybe even making it removable if I feel like it. i picked up a 48 inch 1.5 x 3 inch t slotted aluminum extrusion for $30 and plan on making it in to a new fence for both the table saw and the router. This will be a moveable station, and at some point I may add a couple wheelchair motors for remote control down the road. 

Along with that I need to build a good woodworking bench. I also recently ordered the parts needed to make my digital calipers an HID input for measurements. I want to add an Optical encoder for measuring longer distances by rolling it down a work piece. This seems fairly straight forward, so should be a weekend project soon. I want MM accuracy at the least and sub mm if I can get that. 3d print edge guides and attachments for different measuring abilities. I would like to measure angles digitally as well.

For now, I will just fixate on the build at hand until it is finished. I will be posting whatever it is that I start with. Right now I am designing the layout of the bench and table....  

More Work With CV Positioning

upload.png

This is an early build to test positioning using the camera of my phone to track a marker for positioning. This could eliminate drift, if I can get the frame rate high enough. Right now, I max out at 7 fps. Terrible. But it's a start and gives me hope that faster devices will be able to accomplish this in the future. Now if I could only scrounge up the money for the Dev kit from Google for their CV tablet....

My Christmas Present

upload.jpeg

I have had a 3d printer for over two years now. I started with the MBot cube which at the time most printers were constructed using laser cut plywood, and still cost $1000+ to get. I spent a couple months upgrading and configuring the printer, eventually understanding the simplicity of the device. All in all, I spent $1500 dollars to get it working consistently.

About a month or so ago, i started having extrusion issues, so i took everything apart and started to replace the extruder mechanism. I printed an upgraded spring tension extruder and had a few good prints and then issues started to occur again. I then commissioned a machine class at my work to machine aluminum versions of my printed version. After a while of waiting, which I'm glad that's all it cost, i saw the davinci 1.0 on sale at micro center. $400 and the build quality out of the box was way better than my original printer. Someone returned one to the store, so I ended up getting it for $350. Less than the miter saw I just bought and less than the upgrades to my previous printer.

I still plan on getting my other printer up again after the parts are ready, but i thought that at this price i could test it and have time to return it if i had issues. This original davinci has one extruder, which is totally fine since 90% of what i do is single color and i try to design with printing in mind. 

The worst part of the davinci, the filament cartridges are stupid expensive. Good idea, but too much. The board running the printer, like most out there, is essentially an arduino. And since this is a mass produced printer that has a low barrier of entry, there is a healthy community working on replacement firmware.

My printer has the jumpers on the board to reset the ROM to a factory condition. So I jumped them and flashed lucs repetier firmware. A couple hours later after dialing in the settings, I now have a $350 printer that runs on any 3rd party filament. 

I then installed a raspberry pi running octoprint and a wireless connection. I now have a wireless printer that can go on any closet with power. Next step i am going to install a camera for a live feed, i used the ps2 camera with no luck. So now I'm going to try some other cameras.  

I have printed several times with very good results, the auto leveling feature is really just a measurement of the distance in z that the plates on the corners register. The firmware does not compensate for the differences, it just tells you in mm what it is. Pair that with a measurement device, then just raise and lower the bed so that all are equal and you're ready to go.

If you want to get in to 3d printing, but the cost and reviews of other printers out there are why you haven't. Find a early generation davinci 1 and hack it. You'll be happy with what it can do, especially for the cost. 

 

 

Anyone want to modify or improve my vr headset design?

https://drive.google.com/folder/d/0B2I6c7T2dqQ2S1hnVmhtbHI5ZXc/edit 

 

 

top view

top view

i thought this worked

i thought this worked

this works, but I don't like the tabs. They break.

this works, but I don't like the tabs. They break.

I've been rethinking the design some. So for now, my current change eliminates the front cover and I also removed the back strap alignment and replaced it with a strap connector and two straps that are thinner. Much better feel. I want the front cover to be easy to work with and prevent movement. Optimally, adding mount positions for accessories would benefit the design.

So far, this is what i have. I've been using the same original design without reprinting to make sure that i get it right before a final print. 

  

upload.jpg
upload.jpg

I really feel that this design is close to perfect. Tweaking is needed for sure and customize it for your device. 

Possible mobile vr positioning system... for any device?

I have recently stated to work with the vuforia sdk for unity. It is for ar, but it's possible to remove the camera feed used as the background to them use the markers for loading scene content.

I am able to remove the background, but i think that the processing is still being done and then just not rendered. So if i can figure out how to force it to only load the content when the marker is seen, i may be able to reduce the overhead. Maybe not, but I'm going to try. 

Qualcomm also has a beta program for ar headsets, which has a camera for vr. I have applied for the sdk, and hopefully they accept my application. There is still the issue of warping when using the vuforia sdk, and I'm working on using a combination of the cardboard sdk for warping alone and the vuforia sdk for marker recognition. I have been able to do them individually, but i think that the cardboard sdk overrides whatever vuforia is doing on the background. There has to be a way to combine them.

Maybe the new ar sdk will have warping built in, but it's built for pass through use and may not have it at all.

 

Yet Another USB Issue

Yesterday I rewrote the HID descriptors to allow for only buttons. the bits used are 0x01-0x20 and windows loads the driver fine. But for some reason the buttons do not respond at all, and I cant figure that out at all. It must be something with the bit shifting in the program. But then again, maybe not. 

As a work around so that I can actually move forward on my projects, I am using a Moga bluetooth controller that I tore apart and soldered the connections to. This is not what I want to do because of the multitude of controller ideas I have. I want to make a golf controller using the WII camera and some IR LEDs for positional tracking, which then leads to the idea that I can use the same setup for mobile positioning. This would work around the need for a more accurate IMU in the phone and can give you the ability to move within a limited field. Then again if you could attach the LEDs in some way that one is always centered, then you could lean forward and side to side with the same result.

But if I want this to work, I will have to figure out the descriptor problems and get this working in mobile. The WII remote can sense 4 IR blobs in x,y,z and it gives serial data for the position of x,y and then a size for the z. Therefore z would give distance relative to the blob.

I am going to keep at it, but for now, I need to get at least one game completed.

 

Usb woes

After all of the work put in to understanding hid usb and creating my pinball controller, I sat down today and created a simple pinball game in unity.  

I used my controller in windows the entire time.  I had to program it a bit more simplistic for now to get the physics worked out in game, but all in all I was having a great experience.  

I built the game for android and then installed it on my phone.  Plugged in the controller using an otg cable and then loaded the game. No input.  This must be an error.  Tried again.  No input. Ahhhhhh!

For some unknown reason,  I can't get unity on android to recognize my device properly.  Android itself randomly selects things when buttons are pushed, so something is happening.  

I then loaded up the bt joystick mapping app I purchased a while back to map a joystick for a vr flight sim on android and it found it right away. but when trying to assign bits to the buttons,  nothing would activate when buttons were pushed. a prompt at the top of the app made it clear that it was receiving something. But I have not had any luck with it actually allowing input. 

I did see that there is now an upgraded nicohood library to use, so I will treat that and see if there are any differences.  But with the comments from a couple people stating similar problems with Linux and android, I'm pretty sure that I'm out of luck.  

Nicohood built his library based on the same thing I built mine.  I understand his is very nice, but he doesn't have the time to look in to the android problem.  There is another user who is though. 

For now, my dreams of custom hardware and software controllers for mobile vr are dying on the vine.  I'll just tear apart an old moga bluetooth controller to make this build. I found several for 5 bucks each a year ago and haven't used them.  

At least all is not lost, I can always build custom controllers for desktop based vr.  And maybe this person working on his own controller for android will figure this out for me.  Or, once I regain my resolve, I'll do it myself. But now it's time to focus on game development. 

Revised Pinball Controller Code

So with my last attempt, I was using a SPST switch and attempting to use a spring to release the button. After several failed linear pots and a half working sketch, I tried something else.

This time I am using a endstop type switch that is SPDT and I wired the Norm off position to the button 3 input and the Norm on position to the button 4 input. I tried to do the same sketch with the SPST using the ON position to start the readPull() function, and it just plain will not work. This solutino takes another input to resolve the issue, but it seems to work cleanly.

The only thing is, because the function is outside the loop, the buttons wont work while pulling back. But, I do not think that people usually push the buttons while pulling the shooter. And now that I write this, I could just put the other buttons in to the function and in the off chance that you would push them, it would still work.

Anyhow, this is the updated code. I will post the schematics another time. I need to move on to the actual game. I wasted enough time trying to figure out the pull shooter code.


/*
All around joystick to easily create custom layouts 


// this is the address of each button in the 4 bytes 
definitions :
#define BUTTON_1 0x01
#define BUTTON_2 0x02
#define BUTTON_3 0x03
#define BUTTON_4 0x04
#define BUTTON_5 0x05
#define BUTTON_6 0x06
#define BUTTON_7 0x07
#define BUTTON_8 0x08
#define BUTTON_9 0x09
#define BUTTON_10 0x0A
#define BUTTON_11 0x0B
#define BUTTON_12 0x0C
#define BUTTON_13 0x0D
#define BUTTON_14 0x0E
#define BUTTON_15 0x0F
#define BUTTON_16 0x10
#define BUTTON_17 0x11
#define BUTTON_18 0x12
#define BUTTON_19 0x13
#define BUTTON_20 0x14
#define BUTTON_21 0x15
#define BUTTON_22 0x16
#define BUTTON_23 0x17
#define BUTTON_24 0x18
#define BUTTON_25 0x19
#define BUTTON_26 0x1A
#define BUTTON_27 0x1B
#define BUTTON_28 0x1C
#define BUTTON_29 0x1D
#define BUTTON_30 0x1E
#define BUTTON_31 0x1F
#define BUTTON_32 0x20

*/

    #include <Bounce2.h>
    JoyState_t joySt; // joystick HID descriptor
    
    
    const bool DEBUG = false;  // set to true to debug the raw values
    int BUTTON_1 = 11;// LEFT TRIGGER ON PINBALL
    int BUTTON_2 = 10;//RIGHT TRIGGER ON PINBALL
    int BUTTON_3 = 9; //Used to trigger the value of the pinball shooter at its apex
    int BUTTON_4 = 8; //
    int throttlePin = A5; //One Axes for pinball shooter
    int xPin = A2;
    int yPin = A3;
    int xZero, yZero;
    int xValue, yValue;
    int deadzone = 5;  // smaller values will be set to 0
    int throttleValue;// CURRENTLY SET TO PINBALL LAUNCHER
    unsigned int maxRead ; //SET MAXREAD AS THE MAX INPUT FOR THE BALL
    unsigned int lastRead; // last stored reading greater than previous
    unsigned int pushed; //was the button pushed last time?
    int count = 0;
    int maxCount = 100; // number of loops to allow the axis to be sent to the computer. The lower the number the less accurate the input. I will figure this out later.



/**************************************************************************************/
    void setup()
    {

    if(DEBUG) {
        Serial.begin(9600);
               }
    

        maxRead = 0;  //zero the value before loop
        lastRead = 0; // zero the value before loop
        pushed = false;
     
    // Setup the button with an internal pull-up :
  
  
        pinMode(BUTTON_1,INPUT_PULLUP); 
        pinMode(BUTTON_2,INPUT_PULLUP);
        pinMode(throttlePin, INPUT);
        pinMode(xPin, INPUT);
        pinMode(yPin, INPUT);
        pinMode(BUTTON_3,INPUT_PULLUP); 
        pinMode(BUTTON_4,INPUT_PULLUP);     
        xZero = analogRead(xPin);
        yZero = analogRead(yPin);
       
    

    // zero out all axis and button variables 
    joySt.xAxis = 0;
    joySt.yAxis = 0;
    joySt.zAxis = 0;
    joySt.xRotAxis = 0;
    joySt.yRotAxis = 0;
    joySt.zRotAxis = 0;
    joySt.throttle = 0;
    joySt.rudder = 0;
    joySt.hatSw1 = 0;
    joySt.hatSw2 = 0;
    joySt.buttons = 0;

       }


  void loop() {
          
    while(digitalRead(BUTTON_4) == HIGH){
      pushed = false;
      count = 0;   
      readPull();
    }
        
        
        if ((pushed == true) && (count <= maxCount)) { // if the button was pressed and the max count has not been reached
        joySt.zAxis = map(maxRead,0,1023,0,255); // map the output to the axis
        count++; // add one to the count
          }
         else if (count = maxCount){
           pushed = false;
           count = 0;
           joySt.zAxis = 0;
         }       


        joySt.buttons = 0x00; // off state
        
        
        if (digitalRead(BUTTON_1) == LOW){
        joySt.buttons += 0x01;
        
        }
        
        if (digitalRead(BUTTON_2) == LOW){
        joySt.buttons += 0x02; //adds the two inputs together
       
        }
        


        xValue = analogRead(xPin) - xZero;
    yValue = analogRead(yPin) - yZero;

    if(abs(xValue) < deadzone) {
        xValue = 0;
    }
    if(abs(yValue) < deadzone) {
        yValue = 0;
    }

    

    joySt.xAxis = map(xValue, 450, -450, 0, 255);  // here the axis is inverted
    joySt.yAxis = map(yValue, -400, 400, 0, 255);

        
        
    if(DEBUG) {
        Serial.print("X: ");
        Serial.println(xValue);
        Serial.print("Y: ");
        Serial.println(yValue);
                Serial.print("Throttle value");
                Serial.println(throttleValue);
                Serial.print("maxread");
                Serial.println(maxRead);
                Serial.print("lastRead");
                Serial.println(lastRead);
                
    }




    // Call Joystick.move
    Joystick.setState(&joySt);

     }
                /**************************************************/
   void readPull() {
     
         throttleValue = analogRead(throttlePin);  //(throttlePin) - throttleZero;
         joySt.throttle = map(throttleValue,0,1023,0,255); // scaling the throttle value      
  
         if (digitalRead(BUTTON_3) == HIGH){ //if the button is pushed set pushed to true and lastread to 0 and set the axis value to the max read. lastread will read on the next loop
           pushed = true;  
           lastRead = 0;
         }
           
           // THIS SECTION WILL DETERMINE THE LAST HIGHEST READING AND APPLY THAT TO THE BUTTON 
        
        if (throttleValue > lastRead) {
                 lastRead = throttleValue; // store the current throttle value in last read
        }
          else if (throttleValue <= lastRead) { //throttle is changing direction so record th elast value that was the highes t and store it 
                 maxRead = lastRead;  // store the max value in last read
              
        }
        
            // Call Joystick.move
    Joystick.setState(&joySt); // apparently this has to be called every time to update the position of an axis or joystick button. 
         }

   
                /**************************************************/

Until next time.....

FINALLY!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! figured it out

And now that I have it figured out, I feel stupid. I guess sleeping on it works.

While trying to get the variable to reset after the button was pushed, i was clearing all of the variables that were sent to the button push. But not the variable that creates the data for the other variables. I just figured that since the value would shift so much all of the time, it would not matter if I did clear it.

But, I cant process information in the linear fashion that this code does, so my brain broke when I tried to reason with it. I am so glad I didn't post this question on Stack Exchange. That would be an invitation for trolling, for sure.

But here is my code as of now.

 


/*
All around joystick to easily create custom layouts 


// this is the address of each button in the 4 bytes 
definitions :
#define BUTTON_1 0x01
#define BUTTON_2 0x02
#define BUTTON_3 0x03
#define BUTTON_4 0x04
#define BUTTON_5 0x05
#define BUTTON_6 0x06
#define BUTTON_7 0x07
#define BUTTON_8 0x08
#define BUTTON_9 0x09
#define BUTTON_10 0x0A
#define BUTTON_11 0x0B
#define BUTTON_12 0x0C
#define BUTTON_13 0x0D
#define BUTTON_14 0x0E
#define BUTTON_15 0x0F
#define BUTTON_16 0x10
#define BUTTON_17 0x11
#define BUTTON_18 0x12
#define BUTTON_19 0x13
#define BUTTON_20 0x14
#define BUTTON_21 0x15
#define BUTTON_22 0x16
#define BUTTON_23 0x17
#define BUTTON_24 0x18
#define BUTTON_25 0x19
#define BUTTON_26 0x1A
#define BUTTON_27 0x1B
#define BUTTON_28 0x1C
#define BUTTON_29 0x1D
#define BUTTON_30 0x1E
#define BUTTON_31 0x1F
#define BUTTON_32 0x20

*/

    #include <Bounce2.h>
    JoyState_t joySt; // joystick HID descriptor
    
    
    const bool DEBUG = false;  // set to true to debug the raw values
    int BUTTON_1 = 11;// LEFT TRIGGER ON PINBALL
    int BUTTON_2 = 10;//RIGHT TRIGGER ON PINBALL
    int BUTTON_3 = 9; //Used to trigger the value of the pinball shooter at its apex
    int throttlePin = A5; //One Axes for pinball shooter
    int xPin = A2;
    int yPin = A3;
    int xZero, yZero;
    int xValue, yValue;
    int deadzone = 5;  // smaller values will be set to 0
    int throttleValue;// CURRENTLY SET TO PINBALL LAUNCHER
    unsigned int maxRead ; //SET MAXREAD AS THE MAX INPUT FOR THE BALL
    unsigned int lastRead; // last stored reading greater than previous
    unsigned int pushed; //was the button pushed last time?



/**************************************************************************************/
    void setup()
    {

    if(DEBUG) {
        Serial.begin(9600);
               }
    

        maxRead = 0;  //zero the value before loop
        lastRead = 0; // zero the value before loop
        pushed = false;
     
    // Setup the button with an internal pull-up :
  
  
        pinMode(BUTTON_1,INPUT_PULLUP); 
        pinMode(BUTTON_2,INPUT_PULLUP);
        pinMode(throttlePin, INPUT);
        pinMode(xPin, INPUT);
        pinMode(yPin, INPUT);
        pinMode(BUTTON_3,INPUT_PULLUP);      
        xZero = analogRead(xPin);
    yZero = analogRead(yPin);
       
    

    // zero out all axis and button variables 
    joySt.xAxis = 0;
    joySt.yAxis = 0;
    joySt.zAxis = 0;
    joySt.xRotAxis = 0;
    joySt.yRotAxis = 0;
    joySt.zRotAxis = 0;
    joySt.throttle = 0;
    joySt.rudder = 0;
    joySt.hatSw1 = 0;
    joySt.hatSw2 = 0;
    joySt.buttons = 0;

       }


  void loop()
        {
        joySt.buttons = 0x00; // off state
        
   
        if (digitalRead(BUTTON_1) == LOW){
        joySt.buttons += 0x01;
        
        }
        
        if (digitalRead(BUTTON_2) == LOW){
        joySt.buttons += 0x02; //adds the two inputs together
       
        }
        
        if (digitalRead(BUTTON_3) == LOW){ //if the button is pushed set pushed to true and lastread to 0 and set the axis value to the max read. lastread will read on the next loop
           joySt.zAxis = map(maxRead,0,1023,0,255);
           pushed = true;
           delay(1);
           lastRead = 0;
           
        }        
       
        xValue = analogRead(xPin) - xZero;
    yValue = analogRead(yPin) - yZero;

    if(abs(xValue) < deadzone) {
        xValue = 0;
    }
    if(abs(yValue) < deadzone) {
        yValue = 0;
    }

    throttleValue = analogRead(throttlePin);  //(throttlePin) - throttleZero;
    
    
        // THIS SECTION WILL DETERMINE THE LAST HIGHEST READING AND APPLY THAT TO THE BUTTON 
        
        if (throttleValue > lastRead) {
                 lastRead = throttleValue; // store the current throttle value in last read
        }
          else if (throttleValue <= lastRead) { //throttle is changing direction so record th elast value that was the highes t and store it 
                 maxRead = lastRead;  // store the max value in last read
              
        }

        if (digitalRead(BUTTON_3) == HIGH && (pushed = true)){ // if the button is pressed and let go, set the axis back to 0
           joySt.zAxis = 0;
           pushed = false;
          }
          



    joySt.xAxis = map(xValue, 450, -450, 0, 255);  // here the axis is inverted
    joySt.yAxis = map(yValue, -400, 400, 0, 255);
        joySt.throttle = map(throttleValue,0,1023,0,255); // scaling the throttle value
        
        
    if(DEBUG) {
        Serial.print("X: ");
        Serial.println(xValue);
        Serial.print("Y: ");
        Serial.println(yValue);
                Serial.print("Throttle value");
                Serial.println(throttleValue);
                Serial.print("maxread");
                Serial.println(maxRead);
                Serial.print("lastRead");
                Serial.println(lastRead);
                
    }

//  joySt.xAxis = random(255);
//  joySt.yAxis = random(255);
//  joySt.zAxis = random(255);
//  joySt.xRotAxis = random(255);
//  joySt.yRotAxis = random(255);
//  joySt.zRotAxis = random(255);
//  joySt.throttle = random(255);
//  joySt.rudder = random(255);
//
//  joySt.throttle++;
//
//
//  joySt.buttons <<= 1;
//  if (joySt.buttons == 0)
//      joySt.buttons = 1;
//
//  joySt.hatSw1++;
//  joySt.hatSw2--;
//
//  if (joySt.hatSw1 > 8)
//      joySt.hatSw1 = 0;
//  if (joySt.hatSw2 > 8)
//      joySt.hatSw2 = 8;
//
//  delay(100);
//
//  if (joySt.throttle > 127)
//      digitalWrite(13, HIGH);
//  else
//      digitalWrite(13, LOW);


    // Call Joystick.move
    Joystick.setState(&joySt);

    }

These two files enable you to replace the default HID descriptors in the arduino IDE. To use them in your projects, with an arduino leonardo or an arduino pro micro, rename your original files and place them in a folder within the directory. Use the .BAK file extension to remind you that it is a backup. The directory is in C:\Program Files (x86)\Arduino\hardware\arduino\cores\arduino and the files to replace are HID.cpp and USBAPI.h.

The files are below for use. I originaly saw this when first researching @ http://www.instructables.com/id/Add-a-little-two-analog-axis-thumb-joystick-to-you/?ALLSTEPS

Then that pointed towards http://www.imaginaryindustries.com/blog/?p=80

Which gave me insight in to the working of HID. it is confusing at first, but once you stare at the HID descriptors and play with the descriptor tool from the USB site and some other sites that have java versions of the descriptor tool.

And this is the list of sites I read through to understand this stuff more. It should be comprehensive if you are willing to look through them. I pretty much did all of the googling for you.

http://share.xmarks.com/folder/bookmarks/nOiUcxaHt6

This is using xmarks so its web based.