Reputation: 6684
Background:
I am programming an ATmega328. I can't stand the Arduino IDE, so I prefer using Xcode for writing code. However, I have found all of the options available online for using Xcode to actually upload sketches to Arduino to be convoluted at best and have not been successful in trying to implement them.
Current Method:
What currently works well for me is to use Xcode strictly as a debugger, and 'creating' stripped down versions of Arduino classes when I need them so the debugger doesn't freak out when I put in lines of code specific to Arduino. For example, I have a Serial class in my Xcode project which has the following functions, which work just fine:
void Serial::print(int myInt)
{
cout << myInt;
}
void Serial::println(int myInt)
{
cout << myInt << endl;
}
I do the same for strings, and whatever other standard C++ datatype I may need to print.
This way, any time I want to put Serial.print
within a function in another class I'm working on, I can debug strictly from within Xcode without opening the Arduino IDE. I can also create a "fake" class for pinMode
, etc.
Issue:
I would like to do this with the byte
datatype used in the Arduino environment. I am taking an object-oriented approach to this program, and it threatens to eat up the precious RAM on my little Arduino. So, in order to save space, I'm converting all my int
s to byte
s and so forth.
But, I assume (and my compiler tells me) that I can't subclass char
, or int
, or any other basic types. I don't see how I can start using statements like "byte a = 2
" or something similar with my current (somewhat convoluted) work-around method.
Essentially, I want to trick Xcode into thinking byte
is the same thing as int
for all intents and purposes.
Any ideas?
Upvotes: 2
Views: 1559
Reputation: 31493
You can probably save yourself a lot of effort by reusing ncore which implements the Arduino hardware abstraction layer for Macs.
Even if you want to do this by hand it's worth taking a look at ncore. It defines byte using:
typedef uint8_t byte;
(in fact this is exactly how the libraries bundled with the Arduino IDE define it too!)
Upvotes: 1
Reputation:
Typedefs. (By the way, it's not Xcode who you will be fooling, but the compiler.)
typedef int byte;
or
typedef uint8_t byte;
Upvotes: 2
Reputation: 225272
You are looking for the typedef
keyword:
typedef int byte;
But int
types are usually larger than a single byte. What you really probably want is:
typedef unsigned char byte;
Upvotes: 3