Show Posts
Pages: 1 [2] 3 4 ... 147
16  Development / Other Software Development / Re: New peek function for HardwareSerial on: August 17, 2014, 08:53:04 am
Here is a solution. And you can access RX and TX buffers. Sorry for any headaches it may cause, and feel free to ask if you have questions.

template< typename Tag, typename Tag::type M >
  struct AccessMember{
    friend typename Tag::type get( Tag ){ return M; }

template< bool _RX >
struct HardwareSerial_Buffer{
  typedef uint8_t arr_t[ _RX ? SERIAL_RX_BUFFER_SIZE : SERIAL_TX_BUFFER_SIZE ];
  typedef arr_t HardwareSerial::*type;
  friend type get( HardwareSerial_Buffer );

template struct AccessMember< HardwareSerial_Buffer< true >, &HardwareSerial::_rx_buffer >;
template struct AccessMember< HardwareSerial_Buffer< false >, &HardwareSerial::_tx_buffer >;

uint8_t *GetRX( HardwareSerial &instance ){ return instance.*get( HardwareSerial_Buffer< true >() ); }
uint8_t *GetTX( HardwareSerial &instance ){ return instance.*get( HardwareSerial_Buffer< false >() ); }

And it is used very simply:
void setup() {
  Serial.begin( 9600 );
  uint8_t *rx_start = GetRX( Serial );
  uint8_t *tx_start = GetTX( Serial );

void loop() {}
17  Development / Other Software Development / Re: New peek function for HardwareSerial on: August 17, 2014, 08:25:20 am
then the only way seems to be to mod the libs...  smiley-sad

There is always a way. I'll have a crack and see what I can come up with.

18  Using Arduino / Programming Questions / Re: HTML/CSS/Java Webpage w Arduino Mega & Wifi Shield on: August 15, 2014, 02:31:22 am
If you are using external resources, make the most of it. ( googledrive / web hosting )

The Arduino only need send a few lines at most if you can link in a javascript, or iframe resource.

Javascript can control the whole site. Interaction after the initial html page only needs to be ajax requests for data. All the visual elements can be externally loaded.

As for the tediousness of writing the code in client.print calls, C++ allows a few strange things, take this for instance:

    "This is line 1 "
    "This is line 2 "
    "This is line 3 "
    "however, they are all actually "
    "on the same line"

Its still produces a single line, but as its HTML, it does not matter. The code possibly looks neater though.

Just remember for plain text, you'll need to add a space to the end of each string or at the start of a new string, Otherwisetheresultcouldlooklikethis.
19  Using Arduino / Programming Questions / Re: Constructor not called and loop not runnin on: August 14, 2014, 09:10:34 am
If you want to use Arduino features in the constructor, just don't use a global object... However there is always a solution.

On an AVR you can control the start up, which I do in my library here: Using it, your original code should work ( as it calls init() before global constructors are called. ).

The code is short so I'll post it here, you do not need to do anything apart from include it, or just dump this code into the start of your sketch.

//Written by Christopher Andrews, Provided under MIT & GPL licences.
#if defined( __AVR__ ) && !defined( HEADER_SMALLSETUP )
#include "wiring.c"

/*** init runs before constructors ***/
__attribute__ ((naked)) __attribute__ ((section (".init5"))) void init();

/*** USBAttach runs after constructors ***/
#if defined( USBCON )
__attribute__ ((naked)) __attribute__ ((section (".init7"))) void USBAttach();
void USBAttach(){ USBDevice.attach(); }

/*** setup runs after USBAttach to ensure Serial is active ***/
__attribute__ ((naked)) __attribute__ ((section (".init8")))  void setup();

/*** main() runs as normal, only contains runtime code ***/
__attribute__ ((naked)) int main();

#ifdef __AVR_ATtiny25__
int main(){ return (({while( loop(), true );}),0x00); }
int main(){ return (({while( ( serialEventRun ? serialEventRun() : ( void ) 0 ), loop(), true );}),0x00); }
20  Using Arduino / Programming Questions / Re: How to pass function / variable name? on: August 14, 2014, 08:56:08 am
What am I missing?

Nothing, its the IDE's fault.

It generates prototypes. Longs story short add a prototype below the typedef:

typedef void (*footype)();
void bar(footype g);

void bar(footype g){
  Serial.print("inside bar\n");

This article explains what is happening in detail:

Down the bottom I show how to write a function that does not have a prototype generated.
21  Using Arduino / Programming Questions / Re: Constructor not called and loop not runnin on: August 14, 2014, 07:38:58 am
Init needs to be called before your serial usage in the constructor,

As the instance is global, your constructor runs before the call to init().

You can move the constructor code to a function named start or begin ( begin isn't the best choice as it is a C++11 free function ).
Then call this function from setup.

22  Using Arduino / Programming Questions / Re: How to pass function / variable name? on: August 13, 2014, 09:13:15 am
Some people have problems with complex data definitions. For example, what is:
double (*(*pf)())[3][4];

It looks like, pf is a pointer to a function returning a pointer to a multidimensional array of doubles.

For a little handy info, dealing with function pointers is one place where templates can seem like the easy solution. Even if typedef is used. Consider a function that takes a function pointer with a parameter, calls it and returns it.

Too many brackets for my liking...
void (*action(void (*func)(char), char param ))(char) {
    func( param );
    return func;

Using a typedef we can do this:
typedef void (*Func)(char);

Func action( Func func, char param ){
  func( param );
  return func;

However it is still hard coded to the datatypes and must be changed when ever the function prototypes change, and it doesn't allow expansion to functions that may return a value or take a different parameter type.

A template makes this easy, and it works with C++11 lambdas, the above methods are specifically for functions.
template< typename Func, typename Param >
  Func action( Func func, Param param ){
    func( param );
    return func;

23  Using Arduino / Programming Questions / Re: Little Help Understanding What's Happening In Code Between Library & Sketch? on: August 13, 2014, 05:45:08 am
A struct is not a class - it is just a container for data. A struct can contain several different data items with different data types. If you think of a byte as a container for 8 bits of data a struct is just a more complex container.

In C++ classes, structs, and unions are all types of classes. The only difference between a class and a struct is the members of a struct are all public.

In fact when writing a class that must be a POD, you can write it easier by using the 'struct' class key rather than 'class'. This is because a POD must be trivial and a standard-layout class, which must have no protected or private members.

Uncomment the 'public:' to allow POD initialization:
struct abc{
  int a;
  int b;
class def{
    int a;
    int b;

void setup(){
  abc a = {1,2};
  def b = {1,2};

void loop(){}
24  Community / Website and Forum / Re: HTTPS ? on: August 10, 2014, 11:14:44 pm
The index page has a log in link which uses SSL:

Maybe an upgrade took place and http was used for a little while.
25  Using Arduino / Programming Questions / Re: program is not working after few hours until reset on: August 10, 2014, 09:25:36 pm
--- Insert additional 'failure to post your code' sarcasm here ---

26  Using Arduino / Project Guidance / Re: how to listen serial.print with flash ? on: August 07, 2014, 02:00:59 pm
You may need to re-phrase your post. Its not clear what you are asking.

Do you use an ethernet shield? Or serial communication?

flash is typically what is known as the program memory on the Arduino. Are you talking about the PC software?

If so, you can try and code your app to resend if it doesn't receive a response in a certain time. You will also have to make sure the Arduino can send a response with every request it receives.
27  Using Arduino / Programming Questions / Re: State Machine (Question) on: August 07, 2014, 04:33:00 am
What is wrong with the switch statement I provided above, is that what you are referring too?

First you work out the number or id of the button pressed, then the switch runs a function depending on which button was pressed. If I add some more lines, you can see each case has a break.

switch( whichButton ){

  case 0:     //Button 0 pressed

  case 1:      //Button 1 pressed

  case 2:      //Button 2 pressed
28  Using Arduino / Programming Questions / Re: Make an Array "On the Fly" on: August 07, 2014, 04:15:00 am
would probably lead to a loss

that is inline, it constructs a temporary object. So, you want to do something, but write no code for it...

Code size != Compiled size.

If you are aiming for less lines just put it all on one:
 struct Combine2{ operator char*(){ return ( char* ) this; } byte a,b; };SPI.transferBuffer( (Combine2){ x, y }, NULL, 2 );
29  Using Arduino / Programming Questions / Re: PSTR Issue on: August 07, 2014, 03:59:57 am
Which are what on this site?

The button or


[code=title]//Your code here[/code]

Code: (title)
//Your code here

and what BulldogLowell said, beat me...
30  Using Arduino / Programming Questions / Re: Make an Array "On the Fly" on: August 07, 2014, 03:51:08 am
You can make the array static, then write to each element.

Or mask the bytes together, however testing would have to prove any benefit ( or loss ).

Why not a C++ approach then:
struct Combine2{
  operator char*(){ return ( char* ) this; }
  byte a,b;


SPI.transferBuffer( (Combine2){ x, y }, NULL, 2 );

If you do not like the compound literal, you can provide a constructor.
Pages: 1 [2] 3 4 ... 147