Show Posts
Pages: 1 [2] 3 4 ... 6
16  Using Arduino / Programming Questions / Re: (*XXX).print(); // XXX = pointer to instance that can print on: November 26, 2013, 09:49:50 am
thanks :-)

it is working with your original!! ;-)

can you explain why to use the & (reference) thing?
Code:
protected:
Print &OutputA;
Print &OutputB;

if have understand it right its like this:
Code:
byte bAValue = 5;
byte *pPointer; // that is a place to store a pointer
pPointer = &bAValue; //pPointer gets the place where bAValue is stored in memory
Serial.print("print destination of Pointer: ");
Serial.println(*pPointer); // get the value that is stored at the place pPointer points to
so with &xx you get the pointer to the location where xx is stored.
with *xx you get the value 'real value'
so why do you use the & to define the variable?!

attached the updated testsketch - i have added the pointer test in the menu entry 't' test

sunny greetings
stefan
17  Using Arduino / Programming Questions / Re: (*XXX).print(); // XXX = pointer to instance that can print on: November 26, 2013, 08:34:37 am
Hi pYro_65,

i have tested your last version with the Set
is Set automatically called?

i added the current test file.
it crashes if you try to use the serial menu as long as no TelnetClient is connected:
--> it prints the first char 'M' from "MainMenu" on OutputA (Serial)
 than tries to print the first char 'M' on OutputB (EthernetClient) and crashes.


the problem is - i use a global scope variable for the EthernetClient;
this is set to the Client that the EthernetServer.available() (line 577) returns.
so if the client left  the EthernetClient object is stopped.

if the EthernetClient was connected on time it is all fine.
--->  i had an idea during writing this:
up to know i had:
Code:
EthernetClient ethTelnet_Client = 0;
i just changed this to
Code:
EthernetClient ethTelnet_Client = EthernetClient();
:-) and now the DualWriter just works :-)
i had the memory that i have read in the reference that if (EthernetClient) returns false if it is not ready..
so if i initialize the variable with an EthernetClient Object that would just give a boolean false..


one way would be to parse the pointer to the EthernetClient to every function that uses it - so the DualWriter could be set to the right pointers..?!

i don't know if it would make sens to pass all values (as reference) in an uC environment.. and have no Global values..
on 'big' computers normally there is the thing: as local as possible, as global as needed.

now it is working :-)
thanks for your help pYro_65!!
it would be interesting why it did not work when i initialized this with 0 ?!
and i tested it - only your second version with the Set worked.
what does this Set do?!  who/when is it called?

attached the working example.

sunny greetings
stefan
18  Using Arduino / Programming Questions / Re: (*XXX).print(); // XXX = pointer to instance that can print on: November 25, 2013, 12:00:34 pm
thanks for this thing!
it just works nice!!

with your help i found out that my idea also worked :
Code:
void handle_Menu_Main(char *caCommand, Print &pOUT) {
pOUT.println(F("MainMenu:"));
char bFirstChar = caCommand[0];

switch (bFirstChar) {
case 'h':
case 'H':
case '?': {
// help
pOUT.println();
pOUT.println(F("Help for pOUT Commands:"));
pOUT.println(F("\t '?': this help"));
...
i just head the problem that i tried to use a pointer?!
Code:
void handle_Menu_Main(char *caCommand, Print *pOUT) { ...
i dont really know what it is doing now..
but i can call it like this:
Code:
handle_Menu_Main(sSerialInputCurrent, Serial);
// or
handle_Menu_Main(sTelnetInputCurrent, ethTelnet_Client);
and it is working as expected.

the DualWriter would be also very nice - but there is one problem with this approach:
it only works if both objects are 'available' - for the EthernetClient this is not always (in time) the case -
its only available when an client has connected to the server..
i tried to do something like this -
but it is a try and error in the dark ;-)
Code:
class DualWriter : public Print {
public:
DualWriter( Print &p_Out1, Print &p_Out2 ) : OutputA( p_Out1 ), OutputB( p_Out2 ){}

size_t write( uint8_t u_Data ) {
OutputA.write( u_Data );
//check if OutputB is available
if ( &OutputB != NULL ) {
OutputB.write( u_Data );
}
return 0x01;
}

protected:
Print &OutputA;
Print &OutputB;
};  

DualWriter dwOUT( Serial, ethTelnet_Client);
when arduino tries to write the first byte to the OutputB it crashes..
that is 'normal' because OutputB is just 0 at this time and definitely not an EthernetClient object..

but how could i check this?  

thanks for your point(er) in the right direction - at the moment i will use the first approach..
i attached the current version - so if someone want to test this out - both variants are included (one commented out)
sunny greetings
stefan
19  Using Arduino / Programming Questions / Pointer to Print Class (DualWriter) / TelnetServer [solved] on: November 25, 2013, 06:51:01 am
Hi Community,

i have build a test sketch for a 'menu control' for debugging things..
this sketch is reachable in two ways:
Serial
Telnet (arduino ethernet)
the Telnet thing is based on the concept of this post
for windows you can use PuTTY a telnet client.

at the moment i need a extra menu handler function for both communication ways.
but i would like to use the same menu handler function.
so i had two ideas to get this to work:
(1) give the handler function a pointer to the Object it should use for print
(2) have a 'own' myprint function that prints to both outputs.
     (just calls the orig. Serial.print() and EthernetClient.print() with the same content)

so with version (2) i would need a function that imitates the orig. print function -
but thats not so trivial - because i think there are multiple versions to get the different data-types printed -
so if i am right i would have to build that behavior too ;-) (minimal for the types i use..)

for (1) i think it should be really easy - but i don't know which pointer type to use-
one time i could use HardwareSerial the other i need EthernetClient - so how to get this together?
i know that they are both based on Stream and for printing Stream is based on Print ??

so if someone of you have an idea how to do this pleas let me know !
i have added a demosketch with the simple Serial and Telnet Menus.
(edit: updated title and updated the sketch attachment)

sunny greetings
stefan
20  Using Arduino / Audio / Re: Thoughts on a costum midi controller (what should I use) on: November 24, 2013, 01:19:29 pm
if you use a arduino that is based on Atmel ATmega32U4 this chip could be your USB Midi thing.
there are some finished libs for Mouse and Keyboard - but as far as i know no lib for Midi -
one option is to check LUFA (there are midi examples)
but i dont know if it is possible to get this in combination with the normal Arduino IDE...

if you have an UNO with the 8U2 you can use the dualMocoLUFA

i hope now you have some starting points...

sunny greetings
stefan
21  Community / Website and Forum / Reference - Ethernet library page on: November 24, 2013, 10:55:59 am
Hi Community,

i have read the Reference page about the Ethernet library
http://arduino.cc/en/Reference/Ethernet
and found that there is the Server and Client Class - but if you try to compile with the current IDE it tells you:
Quote
As of Arduino 1.0, the Server class in the Ethernet library has been renamed to EthernetServer.
so i think in the Reference there should be a remark on the Server and Client page that they are renamed?!

sunny greetings
stefan
22  Using Arduino / Programming Questions / Re: #ifdef / #switchdef / array for upload to multiple targets (same HW) on: November 14, 2013, 10:18:18 am
thanks for the suggestion with the EEPROM.
i haven't worked with this up to now ;-)
so its a good idea to look into it.

the fixed ip is by design. in the system where this boards will be used are no dhcp. all server and clients have fixed ips.
Also if you are using an ethernet or WiFi card it should have a MAC ROM already...
iam using the ArduinoEthernet boards - so its the same like an UNO + Ethernet-Shield
so the W5100 has a programmed mac?
than i think there would be a option to read that out with the Ethernet library..

sunny greetings
stefan
23  Using Arduino / Programming Questions / #ifdef / #switchdef / array for upload to multiple targets (same HW) on: November 14, 2013, 07:16:00 am
hello community,

i will have to program ~20 ArduinoEthernet boards - all with the identical sketch -
but every board has a uniq mac and a ipaddress -
so i searching for an idea to 'define' the 'Hardware/Bord-Specific' parameters for all boards -
and than choose in an easy way which one to use for the current upload target (connected board)..

i have two different ideas till now -
1 - use a array to store all possible configs
Code:
tDeviceParameters dpDeviceList[] = {
{ // -- not used.
 0, // cbID
{ 0x90, 0xA2, 0xDA, 0x0E, 0x0E, 0x00 }, // mac
IPAddress(192, 168, 222, 100), // ip
},
{ // development board
 1, // cbID
{ 0x90, 0xA2, 0xDA, 0x0E, 0x0E, 0x4E }, // mac
IPAddress(192, 168, 222, 101), // ip
},
{ // test board
 2, // cbID
{ 0x90, 0xA2, 0xDA, 0x0E, 0x0E, 0x43 }, // mac
IPAddress(192, 168, 222, 102), // ip
},
{ // second test board
 3, // cbID
{ 0x90, 0xA2, 0xDA, 0x0E, 0x0E, 0x45 }, // mac
IPAddress(192, 168, 222, 103), // ip
},
};

tDeviceParameters dpThisDeviceX = dpDeviceList[1]; // number is identical with ID == identical with IPAddress ending.
problem: all infos are using space... but only one is used...

2 - use a list of #ifdef s
Code:
#define DEVICE_1

#ifdef DEVICE_1
tDeviceParameters dpThisDevice = {
// development board
 1, // cbID
{ 0x90, 0xA2, 0xDA, 0x0E, 0x0E, 0x4E }, // mac
IPAddress(192, 168, 222, 101), // ip
};
#endif

#ifdef DEVICE_2
tDeviceParameters dpThisDevice = {
// second test board
 2, // cbID
{ 0x90, 0xA2, 0xDA, 0x0E, 0x0E, 0x43 }, // mac
IPAddress(192, 168, 222, 102), // ip
};
#endif

#ifdef DEVICE_3
tDeviceParameters dpThisDevice = {
// second test board
 3, // cbID
{ 0x90, 0xA2, 0xDA, 0x0E, 0x0E, 0x45 }, // mac
IPAddress(192, 168, 222, 103), // ip
};
#endif
//...
this is not so nice from the formating  ?!  smiley-cool

have someone out there another idea / concept to do something like this?
i have added my test sketch - its the basic UDPSendReceiveString Example with small modifications.
or is the compiler so clever to know that only one of the entrys in an array is used in the software?

sunny greetings
stefan
24  Using Arduino / Programming Questions / Re: switch statement and const from class on: November 12, 2013, 11:35:19 am
thanks for the explanation :-)
25  Using Arduino / Programming Questions / Re: switch statement and const from class on: November 12, 2013, 11:03:34 am
thanks PaulS.
that fixed it.
i think i  understand - the difference -
Code:
FaderLin::state_Standby
so you just use the class definitions
Code:
myFaderOne.state_Standby
so you use the instance to get the member.
--> what is returned the second way?
means this i have to use the first one every time i have defined static members in my classes for a cleaner style?

i have tried to minimize code so its easier to read and understand -
if you want to look at the full code - i have added the test sketch and the raw lib files-
( the lib files go into 'arduino_sketchbook\libraries\FaderLin\' )
( the test sketch go into 'arduino_sketchbook\test_callBackFunc\' )
26  Using Arduino / Programming Questions / Re: switch statement and const from class on: November 12, 2013, 10:29:31 am
Hi PaulS,
Hi PeterH,
ok sorry.
i hope this time i have all relevant information posted.

in the the Library header file (FaderLin.h) i declare the constants -
Code:
/** FaderLin Library **/
//Check if this class is allready there or if it must be created...
#ifndef FaderLin_h
#define FaderLin_h


/** Includes Core Arduino functionality **/
#if ARDUINO < 100
#include <WProgram.h>
#else
#include <Arduino.h>
#endif

/** Class Definition: **/

class FaderLin
{
public:
// public definitions:

static const byte state_NotValid = 0;
static const byte state_Standby = 1;
static const byte state_Fading = 2;
static const byte state_Finished = 42;

//call back function definition
typedef void (* tCbfuncStateChanged) (byte *bState);
typedef void (* tCbfuncValuesChanged) (word *wValues, byte bCount);


// public methods

//Constructor
//FaderLin(byte cbChannelCount_Temp);
FaderLin(byte cbChannelCount_Temp, tCbfuncValuesChanged cbfuncValuesChanged_Temp, tCbfuncStateChanged cbfuncStateChanged_Temp);


//Destructor
~FaderLin();


// initialize class
void begin();

// check if class is ready to operate.
boolean isReady();

// public methods

/** update **/
/**
  * update()
  * returns state
  * main function of library. call as often as possible ;-)
  **/
byte update();

/** getState **/
byte getState();

/** fader things **/
void startFadeTo(unsigned long ulFadeDuration_New, uint16_t *waValues_NewTarget);
//void startFadeTo(unsigned long ulFadeDuration_New, uint16_t wValues_NewTarget);
void stopFade();

uint16_t *getCurrentValues();
//uint16_t getCurrentValues();

const byte getChannelCount();

private:
// per object data

// flag to check if the begin function is already called and the class is ready to work.
boolean bReady;

//call back functions:
const tCbfuncValuesChanged cbfuncValuesChanged;
const tCbfuncStateChanged cbfuncStateChanged;

//internal variables
unsigned long ulTimeStamp_FadeStart;
unsigned long ulFadeDuration;

boolean flagFadingFinished;
boolean Active;

// channels:
const byte cbChannelCount;

//http://forum.arduino.cc/index.php?topic=57433.msg412702#msg412702
uint16_t *waValues_Source;
uint16_t *waValues_Target;
uint16_t *waValues_Current;
uint16_t *waValues_Dif;
boolean *baValues_DifIsNegativ;

// private methods
void printArray(uint16_t *array);

// word multiMap(word val, word* _in, word* _out, uint8_t size);

};

#endif //ifndef FaderLin_h

/** the end **/

in my testsketch (test_callBackFunc.ino) i have included the Library and...
Code:
/** libraries **/
#include "FaderLin.h"

//FaderLin myFaderOne(2);
FaderLin myFaderOne(2, myFaderOne_callback_OutputChanged, myFaderOne_callback_StateChanged);

//....

void myFaderOne_callback_StateChanged(byte *bState) {
Serial.println(F("myFaderOne State:"));
/* does not work. error: 'myFaderOne' cannot appear in a constant-expression */
switch (*bState) {
case myFaderOne.state_Standby : {
Serial.println(F("standby"));
} break;
case myFaderOne.state_Fading : {
Serial.println(F("fading."));
} break;
case myFaderOne.state_Finished : {
Serial.println(F("fading finished!"));
} break;
default: {
Serial.println(F("error. not a know state."));
}
} //end switch
/* */

/* this way it would work...
if ( (*bState) == myFaderOne.state_Standby ) {
Serial.println(F("standby"));
}
/* */
}

//....

void setup() {
//...
Serial.println(F("FaderLin:"));
Serial.println(F("\t myFaderOne.begin();"));
myFaderOne.begin();
Serial.println(F("\t finished."));
//...
}

void loop(){
//...
myFaderOne.update();
//...
}
... and 'made' a object out of my class.
(pleas correct the wrong technical terms - at the moment i cant remember the right ones..)
so with myFaderOne.state_Standby i have the value of the constant definition?!
but at this point i dont know how exactly this works..
i think the compiler cant make a fix (constant) thing out of my 'myFaderOne.state_Standby'-
so  i have to tell the compiler that this hole thing ('myFaderOne.state_Standby') is a constant?!
but how?

sunny greetings
stefan
27  Using Arduino / Programming Questions / switch statement and const from class (solved) on: November 12, 2013, 07:24:39 am
Hello community,

its just a simple 'is it possible':
i have:
Quote
void myFaderOne_callback_StateChanged(byte *bState) {
   Serial.println(F("myFaderOne State:"));
   /* does not work. error: 'myFaderOne' cannot appear in a constant-expression */
   switch (*bState) {
      case myFaderOne.state_Standby : {
            Serial.println(F("standby"));
         } break;
      case myFaderOne.state_Fading : {
            Serial.println(F("fading."));
         } break;
      case myFaderOne.state_Finished : {
            Serial.println(F("fading finished!"));
         } break;
      default: {
            Serial.println(F("error. not a know state."));
         }
   } //end switch
   /* */
}
the compiler don't like this because of
test_callBackFunc:426: error: 'myFaderOne' cannot appear in a constant-expression
test_callBackFunc:426: error: `.' cannot appear in a constant-expression

i have defined the states in my class as public :
static const byte state_Standby            = 1;
static const byte state_Fading            = 2;
static const byte state_Finished         = 42;
if i check with an if
Quote
   if ( (*bState) == myFaderOne.state_Standby ) {
      Serial.println(F("standby"));
   }
it just works.

i see the problem is that the compiler needs a const as switch statement.
and he dont get the linke to the consts in the class.
so is there a solution to do this with a  switch statement? / to tell the compiler that 'myFaderOne.state_Fading' is a 'const' ??
i know that i can use if..
its just out of interest..

sunny greetings stefan
28  Using Arduino / Programming Questions / Re: class - constructor initialize constant on: September 16, 2013, 04:26:44 pm
@Paul: thanks for the explanation/tip
now i have it working;-)
29  Using Arduino / Programming Questions / Re: class - constructor initialize constant on: September 16, 2013, 06:54:25 am
@Nick Gammon:
i tried your tip -
thanks! it works!!!!


@Paul: You are right!
the idea to have it const was just because of the second thing:
Code:
void FaderLin::startFadeTo(unsigned long ulFadeDuration_New, uint16_t waValues_NewTarget[cbChannelCount]) {
// set Source values
for ( byte bIndex = 0; bIndex < cbChannelCount; bIndex++) {
// set Target Values
waValues_Target[bIndex] = waValues_NewTarget[bIndex];
}
}
but i think that is no way to go -
i think i have to learn to use reference at this point...
30  Using Arduino / Programming Questions / class - constructor initialize constant [solved] on: September 16, 2013, 06:03:59 am
Hello Community,

iam experimenting with writing a library and have some questions:

how is the 'prefered' way to pass a value to the class that will not change over runtime?

normaly i would just use
Code:
const byte bMyConstantValue = 4;
i have tried and declared my Value in the .h file as following:
Code:
/** Class Definition: **/

class FaderLin {
public:
// public definitions:
static const byte state_Fading = 0;
static const byte state_Finished = 1;
// public methods
//Constructor
FaderLin(const byte cbChannelCount_Temp);
//Destructor
~FaderLin();

// initialize class
void begin();
// public methods
byte update();
private:
// per object data
// flag to check if the begin function is already called and the class is ready to work.
boolean bReady;

// channel values:
const byte cbChannelCount;

// http://forum.arduino.cc/index.php?topic=57433.msg412702#msg412702
uint16_t *waValues_Source;
uint16_t *waValues_Target;
uint16_t *waValues_Current;
uint16_t *waValues_Dif;

// private methods
};
and in the constructor of the class (.cpp file)
Code:
/** Constructor **/
FaderLin::FaderLin(const byte cbChannelCount_Temp)
{
//do some initializing
//check how to initialize const values in this place..
cbChannelCount = cbChannelCount_Temp;
}

/** Begin (activate object/instantce) **/
void FaderLin::begin()
{
if (bReady == false)
{
#ifdef debug_FaderLin
Serial.println(F("************************************************************"));
Serial.println(F("** Welcome to FaderLin World - Library will initialise... **"));
Serial.println(F("************************************************************"));
Serial.println(F("FaderLin::begin: "));
#endif

//clean up memory.
for ( byte bIndex = 0; bIndex < cbChannelCount; bIndex++) {
waValues_Source[bIndex] = 0;
waValues_Target[bIndex] = 0;
waValues_Current[bIndex] = 0;
waValues_Dif[bIndex] = 0;
}
bReady = true;
}
}
with this i get the errors:
Code:
...\FaderLin.cpp: In constructor 'FaderLin::FaderLin(byte)':
...\FaderLin.cpp:101: error: uninitialized member 'FaderLin::cbChannelCount' with 'const' type 'const byte'
...\FaderLin.cpp:105: error: assignment of read-only data-member 'FaderLin::cbChannelCount'
...
the assignment is clear - but how to do it a nother way??

as you can see i want to use the value to initialize a array.
for the array i found the solution @http://forum.arduino.cc/index.php?topic=57433.msg412702#msg412702

so in the first thing i just declared the 'cbChannelCount' as normal 'byte' type. so i just only read it in my code.
but in one following function i want to get an array with the same size as my internal arrays from the 'user-sketch'.
i also want to give the user access to the values of the waValues_Current array with a 'get' function.

my first approach was
Code:
void FaderLin::startFadeTo(unsigned long ulFadeDuration_New, uint16_t waValues_NewTarget[cbChannelCount]) {
// set Source values
for ( byte bIndex = 0; bIndex < cbChannelCount; bIndex++) {
// set Target Values
waValues_Target[bIndex] = waValues_NewTarget[bIndex];
}
}
but here the errors are:
Code:
...\/FaderLin.h: At global scope:
...\/FaderLin.h:184: error: invalid use of non-static data member 'FaderLin::cbChannelCount'
...\FaderLin.cpp:269: error: from this location
...\FaderLin.cpp:269: error: array bound is not an integer constant
...\FaderLin.cpp:269: error: prototype for 'void FaderLin::startFadeTo(long unsigned int)' does not match any in class 'FaderLin'
...\/FaderLin.h:145: error: candidate is: void FaderLin::startFadeTo(long unsigned int, uint16_t*)
can someone help me how to do this the right way?
or has someone some tutorials / infos to learn the basics in for this kind of things?

sunny greetings

stefan
Pages: 1 [2] 3 4 ... 6