Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.
Photo

ADXL345 Visual Basic code advice needed

adxl345 accelerometer 3D accelerometer properties visual basic driver

  • Please log in to reply
4 replies to this topic

#1 clefranc

clefranc

    Member

  • Members
  • PipPip
  • 16 posts

Posted 30 March 2013 - 01:28 AM

Hi, I'm still playing with the ADXL345. I've wrote a "driver" for controlling and retrieving data from the accelerometer, and catching the interrupts. There is a long series of property that I call "hardware properties" and relate to the device's registers. Some registers are basically only Byte, but others, like the DATA_FORMAT, have more functionnalities like Full Resolution or Range. In the Main() of my N+2 project, I would like to write something like this: acc = new ADXL345() ' The class driver. Done acc.DataFormat.FullResolution = True ' Right now it's like acc.DataFormatFullResolution acc.DataFormat.Range = ADXL345.Range.Range_16g ' Right now it's like acc.DataFormatRange You know what I'm looking for? Like nested properties? I've tried to create a DataFormat class, that include the FullResolution and Range properties, but because ADXL345 class inherits from the I2CDevice, it can't reach some methods, give me errors. If someone can take a look and give advices, or better, help me write the part I don't get, it'll be appreciated. If it's functionnal, the code will be open for the community (codeplex). I'm using a N+2 with MF4.3 under VS2012. Thanks Christian

 

Attached File  Accelerometer3D.zip   98.04KB   20 downloads



#2 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 30 March 2013 - 03:45 PM

Hi Christian, Why is it that you're wanting to access sub-properties of the I2CDevice class? Perhaps there's a way to restructure things. What are you trying to accomplish specifically? It's neither ideal nor speedy, but you can sometimes use reflection to get to methods within a parent/related class which doesn't normally expose them. That's unfortunately also a great way to write code that breaks easily as the other pieces of the framework change--and is generally bad object oriented programming. But it's possible. I would recommend rethinking the code first though, before resorting to brute force methods like reflection. Chris

#3 clefranc

clefranc

    Member

  • Members
  • PipPip
  • 16 posts

Posted 31 March 2013 - 01:36 AM

Hi Chris,

I don't want access to sub properties of the I2CDevice object.

 

If you take a look I my code, you'll clearly see that my 'driver' class only inherits from the I2CDevice, and I only need to access its methods for I2C communication. I think inheritance is fairly common, to add new functionnality.

 

It's only some properties of my 'driver' that I want to make hierachical, say DataFormat.FullResolution instead of DataFormatFullResolution, see the dot?

 

Sorry for my bad English.



#4 Andre Trollip

Andre Trollip

    Advanced Member

  • Members
  • PipPipPip
  • 68 posts
  • LocationGauteng, South Africa

Posted 06 May 2013 - 09:43 PM

Add a property on your class called DataFormat and make it of a type that you create. This new type (class) can have a property called FullResolution. Google "Decorator Pattern" I think that's what you might be after.

#5 clefranc

clefranc

    Member

  • Members
  • PipPip
  • 16 posts

Posted 07 May 2013 - 06:12 AM

Add a property on your class called DataFormat and make it of a type that you create. This new type (class) can have a property called FullResolution. Google "Decorator Pattern" I think that's what you might be after.

 

Hi Galibore,

Already tried that. BTW, thanks for the "Decorator Pattern" concept, was not aware of it. Will do some search.

 

The problem with the new class with a FullResolution property is that it can't reach shared members, etc.

 

If you can take a look at the code below, I've added a DataFormatProperties class that show off these errors.

 

Chistian

Attached File  Accelerometer3D_2.zip   98.46KB   29 downloads







Also tagged with one or more of these keywords: adxl345, accelerometer 3D, accelerometer, properties, visual basic, driver

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.