Jump to content
fusedwires

Tiva C Alarm Library Overlapping Data

Recommended Posts

I am attempting to construct a simple library for creating alarm objects, basically just the days of the week, an hour, and a minute packaged together in an object for easy management.

 

I have attached a zip of the library, (feel free to use any code that might be useful!) but I am having an issue where toggling the days of the week alters the values of the integer hour and minute values. The days of the week are stored as an array of seven booleans, but I don't think that I am making a fencepost error somewhere...

 

I tried the various days of the week, and figured out that days 0-3 (Sun-Wed) alter the hour value, while days 4-6 (Thur-Sat) alter the minute value. Based on that, and the way that the numbers change (roughly multiples of 8) I think that the array of booleans is being written right over the top of the integer values in memory (or vice versa).

 

Am I configuring something in my library wrong, or instantiating the object incorrectly, maybe?

 

I have also attached a zip of some code demonstrating the problem by printing the values through serial.

 

MTAlarm.zip Zipped Library Code

 

problem_demo.zip Zipped demo code (Note: toggling commands are commented out, so out of the box it should function roughly as anticipated.)

 

Thanks in advance!

 

Mike

Share this post


Link to post
Share on other sites

I'm more familiar with C than C++, but I would feel better if this line

 

  boolean _wdays[];

 

looked more like this:

 

  boolean _wdays[7];

 

 
And even then, I'd be tempted to use bit flags inside a simple 'char weekdays'
with an enum to define the symbolic names.
 
Please ignore me if C++ correctly allocates enough space for the array.
 
PS: also, your MTAlarm.ino has a spurious MTButton() declaration instead of MTAlarm().  Don't know if that matters.

Share this post


Link to post
Share on other sites

mgh,

 

Thanks! You are completely correct - I had failed to declare the size of the array in the .h file. Changing it to

boolean _wdays[7]

fixed the problem completely! 

 

That is also a good suggestion about using bitflags - i'll include that in my next round of modifications.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...