Commits

Wagner Sartori Junior committed a4ded53

getting rid of warning comments about char* and moving digitalWriteFast out of libraries path at arduino core to inside application.

Comments (0)

Files changed (7)

 
 // button debouncing adapted from http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1210559123/7;
 #define BOUNCE_TIME_BUTTON		200	// bounce time in ms for the menu button;
-#define BOUNCE_TIME_IR			500	// bounce time in ms for the IR receiver;
 
 
 // last time the respective button was pressed; used for debouncing;

HT1632C/HT1632C.cpp

 
 #include "HT1632C.h"
 #include <avr/pgmspace.h>	// fonts are now loaded in program space;
-#include <digitalWriteFast/digitalWriteFast.h>
 #include "font3.h"
 #include "fontBig.h"
+#include "../digitalWriteFast/digitalWriteFast.h"
 
 HT1632C::HT1632C()
 {
 
 void HT1632C::setup()
 {
-	pinModeFast2(HT1632_CS, OUTPUT);
-	digitalWriteFast2(HT1632_CS, HIGH);
-	pinModeFast2(HT1632_WRCLK, OUTPUT);
-	pinModeFast2(HT1632_DATA, OUTPUT);
-	pinModeFast2(HT1632_CLK, OUTPUT);
+	pinModeFast(HT1632_CS, OUTPUT);
+	digitalWriteFast(HT1632_CS, HIGH);
+	pinModeFast(HT1632_WRCLK, OUTPUT);
+	pinModeFast(HT1632_DATA, OUTPUT);
+	pinModeFast(HT1632_CLK, OUTPUT);
 	for (int i=1; i<=CHIP_MAX; i++) {
 		HT1632C::sendCmd(i, HT1632_CMD_SYSDIS); // Disable system
 		HT1632C::sendCmd(i, HT1632_CMD_COMS00); // 16*32, PMOS drivers
 
 void HT1632C::outputClkPulse()	//Output a clock pulse
 {
-	digitalWriteFast2(HT1632_CLK, HIGH);
-	digitalWriteFast2(HT1632_CLK, LOW);
+	digitalWriteFast(HT1632_CLK, HIGH);
+	digitalWriteFast(HT1632_CLK, LOW);
 }
 
 void HT1632C::chipSelect(int select)
 {
 	unsigned char tmp = 0;
 	if (select < 0) { // Enable all HT1632C
-		digitalWriteFast2(HT1632_CS, LOW);
+		digitalWriteFast(HT1632_CS, LOW);
 		for (tmp=1; tmp<=CHIP_MAX; tmp++) {
 			HT1632C::outputClkPulse();
 		}
 	} else if(select==0) { //Disable all HT1632Cs
-		digitalWriteFast2(HT1632_CS, HIGH);
+		digitalWriteFast(HT1632_CS, HIGH);
 		for(tmp=1; tmp<=CHIP_MAX; tmp++) {
 			HT1632C::outputClkPulse();
 		}
 	} else {
-		digitalWriteFast2(HT1632_CS, HIGH);
+		digitalWriteFast(HT1632_CS, HIGH);
 		for(tmp=1; tmp<=CHIP_MAX; tmp++) {
 			HT1632C::outputClkPulse();
 		}
-		digitalWriteFast2(HT1632_CS, LOW);
+		digitalWriteFast(HT1632_CS, LOW);
 		HT1632C::outputClkPulse();
-		digitalWriteFast2(HT1632_CS, HIGH);
+		digitalWriteFast(HT1632_CS, HIGH);
 		tmp = 1;
 		for( ; tmp<select; tmp++) {
 			HT1632C::outputClkPulse();
 void HT1632C::writeBits(byte bits, byte firstbit)
 {
 	while (firstbit) {
-		digitalWriteFast2(HT1632_WRCLK, LOW);
+		digitalWriteFast(HT1632_WRCLK, LOW);
 		if (bits & firstbit) {
-			digitalWriteFast2(HT1632_DATA, HIGH);
+			digitalWriteFast(HT1632_DATA, HIGH);
 		} else {
-			digitalWriteFast2(HT1632_DATA, LOW);
+			digitalWriteFast(HT1632_DATA, LOW);
 		}
-		digitalWriteFast2(HT1632_WRCLK, HIGH);
+		digitalWriteFast(HT1632_WRCLK, HIGH);
 		firstbit >>= 1;
 	}
 }
 
 
 
-char	*dayName[]		=	{"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"};
-char	*monthName[]	=	{"", "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
+const char	*dayName[]		=	{"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"};
+const char	*monthName[]	=	{"", "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
 
 
 
 
 
 // menu items;
-char* menu[]	=	{	"SHOW QUOTE",
+const char* menu[]	=	{	"SHOW QUOTE",
 						"SHOW UTC",
 						"SHOW BIG",		// (fc) added Aug 1/2010 to display time only, with big font;
 						"SET TIME",		//*	time command added by <MLS> Apr 2, 2010
 void	TrunetClock::readMessageFromMemory()
 {
 	// the message starts right after the word "line:";
-	char* msg = "line: Trunet Clock by Wagner Sartori Junior";
-        msg += '\0';
+	char const* msg = "line: Trunet Clock by Wagner Sartori Junior";
+    msg += '\0';
 	if (msg)
 	{
 		msg = msg + 6;	// message starts after "line:" (6 chars later);
 	delay(1000);
 }
 
-void TrunetClock::displayStaticLine(char* text, int color)
+void TrunetClock::displayStaticLine(const char* text, int color)
 {
 	// try to center the text;
 	int len	=	strlen(text);
   void	readMessageFromMemory();
 
   void	displayScrollingLine();
-  void  displayStaticLine(char* text, int color);
+  void  displayStaticLine(const char* text, int color);
   void	displayTime(int hour, int minute, boolean isAlarmEnabled, boolean is24hourModeEnabled);
   void	displayTimeDate(int hour, int minute, int day, int month, int year, boolean isAlarmEnabled, boolean is24hourModeEnabled);
   void	displayTimeBlink(int hour, int minute, boolean isAlarmEnabled);

VarManager/VarManager.cpp

 	VarManager::varPersistence = var;
 }
 
-int VarManager::getVarAddrLocation(char name[MAXVARLEN]) {
+int VarManager::getVarAddrLocation(const char name[MAXVARLEN]) {
 	varElement *variable;
 
 	for(variable=VarManager::varList;variable!=0;variable=variable->next) {
 	return -1;
 }
 
-void VarManager::setVarAddrLocation(char name[MAXVARLEN], int addr) {
+void VarManager::setVarAddrLocation(const char name[MAXVARLEN], int addr) {
 	varElement *variable;
 	variable = new varElement;
-	strcpy(variable->name, name);
+	strcpy((char *)variable->name, name);
 	variable->addr = addr;
 	variable->value = 255;
 	variable->next = VarManager::varList;
 	VarManager::varList = variable;
 }
 
-int VarManager::getVarValue(char name[MAXVARLEN]) {
+int VarManager::getVarValue(const char name[MAXVARLEN]) {
 	varElement *variable;
 	int val = 255;
 
 	return val;
 }
 
-void VarManager::setVarValue(char name[MAXVARLEN], int value) {
+void VarManager::setVarValue(const char name[MAXVARLEN], int value) {
 	varElement *variable;
 
 #ifdef _DEBUG_

VarManager/VarManager.h

 
 	void  setVarPersistence(int var);
 
-	int  getVarAddrLocation(char name[MAXVARLEN]);
-	void setVarAddrLocation(char name[MAXVARLEN], int addr);
-	int         getVarValue(char name[MAXVARLEN]);
-	void        setVarValue(char name[MAXVARLEN], int value);
+	int  getVarAddrLocation(const char name[MAXVARLEN]);
+	void setVarAddrLocation(const char name[MAXVARLEN], int addr);
+	int         getVarValue(const char name[MAXVARLEN]);
+	void        setVarValue(const char name[MAXVARLEN], int value);
 
 private:
 	int varPersistence;
 
-	struct varElement { char name[MAXVARLEN];
+	struct varElement { const char name[MAXVARLEN];
 					    int addr;
 					    int value;
 					    varElement *next;

digitalWriteFast/digitalWriteFast.h

+#if !defined(digitalPinToPortReg)
+#if !(defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) || defined(__AVR_ATmega2561__) )
+
+
+// Standard Arduino Pins
+#define digitalPinToPortReg(P) \
+(((P) >= 0 && (P) <= 7) ? &PORTD : (((P) >= 8 && (P) <= 13) ? &PORTB : &PORTC))
+#define digitalPinToDDRReg(P) \
+(((P) >= 0 && (P) <= 7) ? &DDRD : (((P) >= 8 && (P) <= 13) ? &DDRB : &DDRC))
+#define digitalPinToPINReg(P) \
+(((P) >= 0 && (P) <= 7) ? &PIND : (((P) >= 8 && (P) <= 13) ? &PINB : &PINC))
+#define digitalPinToBit(P) \
+(((P) >= 0 && (P) <= 7) ? (P) : (((P) >= 8 && (P) <= 13) ? (P) - 8 : (P) - 14))
+
+#if defined(__AVR_ATmega8__)
+
+// 3 PWM
+#define digitalPinToTimer(P) \
+(((P) ==  9 || (P) == 10) ? &TCCR1A : (((P) == 11) ? &TCCR2 : 0))
+#define digitalPinToTimerBit(P) \
+(((P) ==  9) ? COM1A1 : (((P) == 10) ? COM1B1 : COM21))
+#else
+
+// 6 PWM
+#define digitalPinToTimer(P) \
+(((P) ==  6 || (P) ==  5) ? &TCCR0A : \
+        (((P) ==  9 || (P) == 10) ? &TCCR1A : \
+        (((P) == 11 || (P) ==  3) ? &TCCR2A : 0)))
+#define digitalPinToTimerBit(P) \
+(((P) ==  6) ? COM0A1 : (((P) ==  5) ? COM0B1 : \
+        (((P) ==  9) ? COM1A1 : (((P) == 10) ? COM1B1 : \
+        (((P) == 11) ? COM2A1 : COM2B1)))))
+#endif
+
+#else
+// Arduino Mega Pins
+#define digitalPinToPortReg(P) \
+(((P) >= 22 && (P) <= 29) ? &PORTA : \
+        ((((P) >= 10 && (P) <= 13) || ((P) >= 50 && (P) <= 53)) ? &PORTB : \
+        (((P) >= 30 && (P) <= 37) ? &PORTC : \
+        ((((P) >= 18 && (P) <= 21) || (P) == 38) ? &PORTD : \
+        ((((P) >= 0 && (P) <= 3) || (P) == 5) ? &PORTE : \
+        (((P) >= 54 && (P) <= 61) ? &PORTF : \
+        ((((P) >= 39 && (P) <= 41) || (P) == 4) ? &PORTG : \
+        ((((P) >= 6 && (P) <= 9) || (P) == 16 || (P) == 17) ? &PORTH : \
+        (((P) == 14 || (P) == 15) ? &PORTJ : \
+        (((P) >= 62 && (P) <= 69) ? &PORTK : &PORTL))))))))))
+
+#define digitalPinToDDRReg(P) \
+(((P) >= 22 && (P) <= 29) ? &DDRA : \
+        ((((P) >= 10 && (P) <= 13) || ((P) >= 50 && (P) <= 53)) ? &DDRB : \
+        (((P) >= 30 && (P) <= 37) ? &DDRC : \
+        ((((P) >= 18 && (P) <= 21) || (P) == 38) ? &DDRD : \
+        ((((P) >= 0 && (P) <= 3) || (P) == 5) ? &DDRE : \
+        (((P) >= 54 && (P) <= 61) ? &DDRF : \
+        ((((P) >= 39 && (P) <= 41) || (P) == 4) ? &DDRG : \
+        ((((P) >= 6 && (P) <= 9) || (P) == 16 || (P) == 17) ? &DDRH : \
+        (((P) == 14 || (P) == 15) ? &DDRJ : \
+        (((P) >= 62 && (P) <= 69) ? &DDRK : &DDRL))))))))))
+
+#define digitalPinToPINReg(P) \
+(((P) >= 22 && (P) <= 29) ? &PINA : \
+        ((((P) >= 10 && (P) <= 13) || ((P) >= 50 && (P) <= 53)) ? &PINB : \
+        (((P) >= 30 && (P) <= 37) ? &PINC : \
+        ((((P) >= 18 && (P) <= 21) || (P) == 38) ? &PIND : \
+        ((((P) >= 0 && (P) <= 3) || (P) == 5) ? &PINE : \
+        (((P) >= 54 && (P) <= 61) ? &PINF : \
+        ((((P) >= 39 && (P) <= 41) || (P) == 4) ? &PING : \
+        ((((P) >= 6 && (P) <= 9) || (P) == 16 || (P) == 17) ? &PINH : \
+        (((P) == 14 || (P) == 15) ? &PINJ : \
+        (((P) >= 62 && (P) <= 69) ? &PINK : &PINL))))))))))
+
+#define digitalPinToBit(P) \
+(((P) >=  7 && (P) <=  9) ? (P) - 3 : \
+        (((P) >= 10 && (P) <= 13) ? (P) - 6 : \
+        (((P) >= 22 && (P) <= 29) ? (P) - 22 : \
+        (((P) >= 30 && (P) <= 37) ? 37 - (P) : \
+        (((P) >= 39 && (P) <= 41) ? 41 - (P) : \
+        (((P) >= 42 && (P) <= 49) ? 49 - (P) : \
+        (((P) >= 50 && (P) <= 53) ? 53 - (P) : \
+        (((P) >= 54 && (P) <= 61) ? (P) - 54 : \
+        (((P) >= 62 && (P) <= 69) ? (P) - 62 : \
+        (((P) == 0 || (P) == 15 || (P) == 17 || (P) == 21) ? 0 : \
+        (((P) == 1 || (P) == 14 || (P) == 16 || (P) == 20) ? 1 : \
+        (((P) == 19) ? 2 : \
+        (((P) == 5 || (P) == 6 || (P) == 18) ? 3 : \
+        (((P) == 2) ? 4 : \
+        (((P) == 3 || (P) == 4) ? 5 : 7)))))))))))))))
+
+// 15 PWM
+#define digitalPinToTimer(P) \
+(((P) == 13 || (P) ==  4) ? &TCCR0A : \
+        (((P) == 11 || (P) == 12) ? &TCCR1A : \
+        (((P) == 10 || (P) ==  9) ? &TCCR2A : \
+        (((P) ==  5 || (P) ==  2 || (P) ==  3) ? &TCCR3A : \
+        (((P) ==  6 || (P) ==  7 || (P) ==  8) ? &TCCR4A : \
+        (((P) == 46 || (P) == 45 || (P) == 44) ? &TCCR5A : 0))))))
+#define digitalPinToTimerBit(P) \
+(((P) == 13) ? COM0A1 : (((P) ==  4) ? COM0B1 : \
+        (((P) == 11) ? COM1A1 : (((P) == 12) ? COM1B1 : \
+        (((P) == 10) ? COM2A1 : (((P) ==  9) ? COM2B1 : \
+        (((P) ==  5) ? COM3A1 : (((P) ==  2) ? COM3B1 : (((P) ==  3) ? COM3C1 : \
+        (((P) ==  6) ? COM4A1 : (((P) ==  7) ? COM4B1 : (((P) ==  8) ? COM4C1 : \
+        (((P) == 46) ? COM5A1 : (((P) == 45) ? COM5B1 : COM5C1))))))))))))))
+
+#endif
+#endif
+
+#if !defined(digitalWriteFast)
+#define digitalWriteFast(P, V) \
+if (__builtin_constant_p(P) && __builtin_constant_p(V)) { \
+                if (digitalPinToTimer(P)) \
+                        bitClear(*digitalPinToTimer(P), digitalPinToTimerBit(P)); \
+                bitWrite(*digitalPinToPortReg(P), digitalPinToBit(P), (V)); \
+        } else { \
+                digitalWrite((P), (V)); \
+        }
+#endif
+
+#if !defined(pinModeFast)
+#define pinModeFast(P, V) \
+if (__builtin_constant_p(P) && __builtin_constant_p(V)) { \
+                bitWrite(*digitalPinToDDRReg(P), digitalPinToBit(P), (V)); \
+        } else {  \
+                pinMode((P), (V)); \
+        } 
+#endif
+
+#if !defined(digitalReadFast)
+#define digitalReadFast(P) ( (int) __digitalReadFast__((P)) )
+#define __digitalReadFast__(P ) \
+(__builtin_constant_p(P) ) ? ( \
+                digitalPinToTimer(P) ? ( \
+                       bitClear(*digitalPinToTimer(P), digitalPinToTimerBit(P)) ,  \
+                             bitRead(*digitalPinToPINReg(P), digitalPinToBit(P))) : \
+                  bitRead(*digitalPinToPINReg(P), digitalPinToBit(P)))  : \
+                digitalRead((P))
+#endif
+
+#if !defined(digitalWriteFast2)
+#define digitalWriteFast2(P, V) \
+if (__builtin_constant_p(P) && __builtin_constant_p(V)) { \
+                bitWrite(*digitalPinToPortReg(P), digitalPinToBit(P), (V)); \
+        } else { \
+                digitalWrite((P), (V)); \
+        }
+#endif
+
+#if !defined(pinModeFast2)
+#define pinModeFast2(P, V) \
+if (__builtin_constant_p(P) && __builtin_constant_p(V)) { \
+                if (digitalPinToTimer(P)) \
+                        bitClear(*digitalPinToTimer(P), digitalPinToTimerBit(P)); \
+                bitWrite(*digitalPinToDDRReg(P), digitalPinToBit(P), (V)); \
+        } else {  \
+                pinMode((P), (V)); \
+        } 
+#endif
+
+#if !defined(digitalReadFast2)
+#define digitalReadFast2(P) ( (int) __digitalReadFast2__((P)) )
+#define __digitalReadFast2__(P ) \
+(__builtin_constant_p(P) ) ? ( \
+                ( bitRead(*digitalPinToPINReg(P), digitalPinToBit(P))) ) : \
+                digitalRead((P))
+#endif