Permalink
Browse files

Cleaning up code.

  • Loading branch information...
1 parent 9784823 commit b8347374e5885684977b9291ea71382e178d6e25 @Zuph Zuph committed Mar 12, 2012
Showing with 242 additions and 180 deletions.
  1. +10 −0 .gitignore
  2. +2 −2 Makefile
  3. +5 −8 comm/outputParse.c
  4. +76 −0 eepromVars.c
  5. +49 −49 eepromVars.h
  6. +83 −0 lprintf.c
  7. +8 −0 lprintf.h
  8. +9 −119 main.c
  9. +0 −2 parsing/epoch.c
View
@@ -0,0 +1,10 @@
+*.o
+*.lst
+*.map
+*.lss
+*.hex
+*.swp
+*.eep
+*.elf
+*.sym
+.dep/
View
@@ -61,8 +61,8 @@ TARGET = main
# List C source files here. (C dependencies are automatically generated.)
-SRC = lib/i2c.c lib/tmp100.c lib/bmp085.c lib/ds3231.c\
-queue.c parsing/epoch.c parsing/gps.c logging/openlog.c comm/outputParse.c $(TARGET).c
+SRC = eepromVars.c lib/i2c.c lib/tmp100.c lib/bmp085.c lib/ds3231.c\
+queue.c parsing/epoch.c parsing/gps.c logging/openlog.c comm/outputParse.c lprintf.c $(TARGET).c
# List Assembler source files here.
View
@@ -19,7 +19,7 @@
#include "outputParse.h"
-#define opdebug
+//#define opdebug
//if commented out, no eeprom writing
#define detacheeprom
@@ -69,10 +69,7 @@ uint16_t getTxSample(uint8_t *output, uint32_t *bitmask, uint16_t sampleNumber,
//Sample Retrieval words
#ifdef opdebug
lprintf("ISAMP: %d\n", sampleNumber);
- for(int i = 0; i < SAMPLESTRINGSIZEINCHARS; i++)
- {
- lprintf("%c", sampleHolder[i]);
- }
+ lprintf("%s", sampleHolder);
lprintf("\n");
#endif
@@ -214,12 +211,12 @@ void loadBatch(void)
sizeOfSample = getTxSample(thisSample, currentBitmask, i, batchNumber);
#ifdef opdebug
- lprintf("A Sample: ");
+ //lprintf("A Sample: ");
#endif
for(int j=0; j < sizeOfSample; j++)
{
#ifdef opdebug
- lprintf("%x ", thisSample[j]);
+ //lprintf("%x ", thisSample[j]);
#endif
uint8_t data[3];
uint8_t error;
@@ -234,7 +231,7 @@ void loadBatch(void)
commPromEnd++;
}
#ifdef opdebug
- lprintf("\n");
+ //lprintf("\n");
#endif
}
View
@@ -0,0 +1,76 @@
+
+#include <avr/eeprom.h>
+
+uint8_t EEMEM EEepochStartSeconds;
+uint8_t EEMEM EEepochStartMinutes;
+uint8_t EEMEM EEepochStartHours;
+uint8_t EEMEM EEepochStartDays;
+
+uint16_t EEMEM EEballastTargetAltitude;
+int16_t EEMEM EEballastTargetPositiveVSpeed;
+int16_t EEMEM EEballastTargetNegativeVSpeed;
+
+uint16_t EEMEM EEmaydayAltitude;
+int16_t EEMEM EEmaydayVSpeed;
+
+uint16_t EEMEM EEballastSafetyAltThresh;
+uint8_t EEMEM EEautoBallastDisable;
+
+uint8_t EEMEM EEoverOceanFlag;
+
+int8_t EEMEM EEnightTemperatureForecast;
+uint32_t EEMEM EEsunriseAnticipation;
+
+uint16_t EEMEM EEmaxAllowableTXInterval;
+
+int8_t EEMEM EEbatteryHeaterSetpoint;
+
+uint16_t EEMEM EEdataCollectionInterval; //Var 0x03
+uint16_t EEMEM EEdataTransmitInterval; //Var 0x04
+uint16_t EEMEM EEshortDataTransmitInterval;
+
+uint16_t EEMEM EEhfDataTransmitInterval;
+uint8_t EEMEM EEhfRapidTransmit;
+
+
+uint32_t EEMEM EEepochOfLastBatchTransmit;
+
+uint16_t EEMEM EEcurrentBatchNumber;
+uint16_t EEMEM EEbatchSampleStart;
+uint16_t EEMEM EEbatchSampleEnd;
+
+uint16_t EEMEM EEcommPromStart;
+uint16_t EEMEM EEcommPromEnd;
+
+uint8_t EEMEM EEflightComputerResetCount;
+uint8_t EEMEM EEcommModuleResetCount;
+
+uint8_t EEMEM EEflightPhase; //Var 0x05
+
+uint32_t EEMEM EEcurrentTelemetryBitmap[3]; //Var 0x06
+uint16_t EEMEM EEcurrentTelemetryVersion; //Var 0x07
+
+uint8_t EEMEM EEEpochLock = 0;
+
+uint16_t EEMEM EEhfTimeToTx;
+uint8_t EEMEM EEhfLenngthToTx;
+
+uint32_t EEMEM EEepochOffset;
+
+//THIS IS ALSO DEFINED IN MAIN, REMEMBER TO CHANGE THIS DUMMY
+#define VSPEEDSAMPLESDESIRED 20
+
+int16_t EEMEM EEvSpeedHolderSamples[VSPEEDSAMPLESDESIRED];
+
+//Needed for BMP085
+short EEMEM EEBMPac1;
+short EEMEM EEBMPac2;
+short EEMEM EEBMPac3;
+unsigned short EEMEM EEBMPac4;
+unsigned short EEMEM EEBMPac5;
+unsigned short EEMEM EEBMPac6;
+short EEMEM EEBMPb1;
+short EEMEM EEBMPb2;
+short EEMEM EEBMPmb;
+short EEMEM EEBMPmc;
+short EEMEM EEBMPmd;
View
@@ -14,84 +14,84 @@
//
//*****************************************************************************
-#ifndef EEPROMVARS_H
+#ifndef EEPROMVARS_Hf
#define EEPROMVARS_H
#include <avr/eeprom.h>
-uint8_t EEMEM EEepochStartSeconds;
-uint8_t EEMEM EEepochStartMinutes;
-uint8_t EEMEM EEepochStartHours;
-uint8_t EEMEM EEepochStartDays;
+extern uint8_t EEMEM EEepochStartSeconds;
+extern uint8_t EEMEM EEepochStartMinutes;
+extern uint8_t EEMEM EEepochStartHours;
+extern uint8_t EEMEM EEepochStartDays;
-uint16_t EEMEM EEballastTargetAltitude;
-int16_t EEMEM EEballastTargetPositiveVSpeed;
-int16_t EEMEM EEballastTargetNegativeVSpeed;
+extern uint16_t EEMEM EEballastTargetAltitude;
+extern int16_t EEMEM EEballastTargetPositiveVSpeed;
+extern int16_t EEMEM EEballastTargetNegativeVSpeed;
-uint16_t EEMEM EEmaydayAltitude;
-int16_t EEMEM EEmaydayVSpeed;
+extern uint16_t EEMEM EEmaydayAltitude;
+extern int16_t EEMEM EEmaydayVSpeed;
-uint16_t EEMEM EEballastSafetyAltThresh;
-uint8_t EEMEM EEautoBallastDisable;
+extern uint16_t EEMEM EEballastSafetyAltThresh;
+extern uint8_t EEMEM EEautoBallastDisable;
-uint8_t EEMEM EEoverOceanFlag;
+extern uint8_t EEMEM EEoverOceanFlag;
-int8_t EEMEM EEnightTemperatureForecast;
-uint32_t EEMEM EEsunriseAnticipation;
+extern int8_t EEMEM EEnightTemperatureForecast;
+extern uint32_t EEMEM EEsunriseAnticipation;
-uint16_t EEMEM EEmaxAllowableTXInterval;
+extern uint16_t EEMEM EEmaxAllowableTXInterval;
-int8_t EEMEM EEbatteryHeaterSetpoint;
+extern int8_t EEMEM EEbatteryHeaterSetpoint;
-uint16_t EEMEM EEdataCollectionInterval; //Var 0x03
-uint16_t EEMEM EEdataTransmitInterval; //Var 0x04
-uint16_t EEMEM EEshortDataTransmitInterval;
+extern uint16_t EEMEM EEdataCollectionInterval; //Var 0x03
+extern uint16_t EEMEM EEdataTransmitInterval; //Var 0x04
+extern uint16_t EEMEM EEshortDataTransmitInterval;
-uint16_t EEMEM EEhfDataTransmitInterval;
-uint8_t EEMEM EEhfRapidTransmit;
+extern uint16_t EEMEM EEhfDataTransmitInterval;
+extern uint8_t EEMEM EEhfRapidTransmit;
-uint32_t EEMEM EEepochOfLastBatchTransmit;
+extern uint32_t EEMEM EEepochOfLastBatchTransmit;
-uint16_t EEMEM EEcurrentBatchNumber;
-uint16_t EEMEM EEbatchSampleStart;
-uint16_t EEMEM EEbatchSampleEnd;
+extern uint16_t EEMEM EEcurrentBatchNumber;
+extern uint16_t EEMEM EEbatchSampleStart;
+extern uint16_t EEMEM EEbatchSampleEnd;
-uint16_t EEMEM EEcommPromStart;
-uint16_t EEMEM EEcommPromEnd;
+extern uint16_t EEMEM EEcommPromStart;
+extern uint16_t EEMEM EEcommPromEnd;
-uint8_t EEMEM EEflightComputerResetCount;
-uint8_t EEMEM EEcommModuleResetCount;
+extern uint8_t EEMEM EEflightComputerResetCount;
+extern uint8_t EEMEM EEcommModuleResetCount;
-uint8_t EEMEM EEflightPhase; //Var 0x05
+extern uint8_t EEMEM EEflightPhase; //Var 0x05
-uint32_t EEMEM EEcurrentTelemetryBitmap[3]; //Var 0x06
-uint16_t EEMEM EEcurrentTelemetryVersion; //Var 0x07
+extern uint32_t EEMEM EEcurrentTelemetryBitmap[3]; //Var 0x06
+extern uint16_t EEMEM EEcurrentTelemetryVersion; //Var 0x07
-uint8_t EEMEM EEEpochLock = 0;
+extern uint8_t EEMEM EEEpochLock;
-uint16_t EEMEM EEhfTimeToTx;
-uint8_t EEMEM EEhfLenngthToTx;
+extern uint16_t EEMEM EEhfTimeToTx;
+extern uint8_t EEMEM EEhfLenngthToTx;
-uint32_t EEMEM EEepochOffset;
+extern uint32_t EEMEM EEepochOffset;
//THIS IS ALSO DEFINED IN MAIN, REMEMBER TO CHANGE THIS DUMMY
#define VSPEEDSAMPLESDESIRED 20
-int16_t EEMEM EEvSpeedHolderSamples[VSPEEDSAMPLESDESIRED];
+extern int16_t EEMEM EEvSpeedHolderSamples[VSPEEDSAMPLESDESIRED];
//Needed for BMP085
-short EEMEM EEBMPac1;
-short EEMEM EEBMPac2;
-short EEMEM EEBMPac3;
-unsigned short EEMEM EEBMPac4;
-unsigned short EEMEM EEBMPac5;
-unsigned short EEMEM EEBMPac6;
-short EEMEM EEBMPb1;
-short EEMEM EEBMPb2;
-short EEMEM EEBMPmb;
-short EEMEM EEBMPmc;
-short EEMEM EEBMPmd;
+extern short EEMEM EEBMPac1;
+extern short EEMEM EEBMPac2;
+extern short EEMEM EEBMPac3;
+extern unsigned short EEMEM EEBMPac4;
+extern unsigned short EEMEM EEBMPac5;
+extern unsigned short EEMEM EEBMPac6;
+extern short EEMEM EEBMPb1;
+extern short EEMEM EEBMPb2;
+extern short EEMEM EEBMPmb;
+extern short EEMEM EEBMPmc;
+extern short EEMEM EEBMPmd;
#endif
View
@@ -0,0 +1,83 @@
+#include <stdio.h>
+#include <avr/io.h>
+#include <util/delay.h>
+#include <string.h>
+
+#include <avr/pgmspace.h>
+
+#include "lprintf.h"
+#include "lib/i2c.h"
+
+//LEDs on PB3 and PB4
+#define STATUS_PORT PORTB
+#define STATUS_LED1 3
+#define STATUS_LED2 4
+
+#define yellow_on() ( PORTB |= (1 << STATUS_LED1) )
+#define red_on() ( PORTB |= (1 << STATUS_LED2) )
+
+#define yellow_off() ( PORTB &= ~(1 << STATUS_LED1) )
+#define red_off() ( PORTB &= ~(1 << STATUS_LED2) )
+
+int lprintf(char *str, ...)
+{
+ char lstr[301];
+ int chars;
+ va_list args;
+
+ va_start(args, str);
+
+ lstr[0] = 'F';
+
+ chars = vsnprintf(lstr+1, 300, str, args);
+
+ if(chars > 300)
+ {
+ va_end(args);
+ return 1;
+ } else {
+ uint8_t retVal = i2cMasterSendNI(0b00001110, chars+1, lstr);
+ if(retVal != I2C_OK)
+ {
+ yellow_on();
+ }
+
+ va_end(args);
+ return 0;
+ }
+ _delay_ms(100);
+}
+
+int lprintf_P(const char *str, ...)
+{
+ char lstr[100];
+ uint8_t i2cSend[101];
+ int chars;
+ va_list args;
+
+ va_start(args, str);
+
+ chars = vsnprintf_P(lstr, 100, str, args);
+
+ if(chars > 100)
+ {
+ va_end(args);
+ return 1;
+ } else {
+ int i=0;
+ i2cSend[0] = 'F';
+ for(i=0; i <=chars; i++)
+ {
+ i2cSend[i+1] = (uint8_t)lstr[i];
+ }
+ uint8_t retVal = i2cMasterSendNI(0b00001110, chars+1, i2cSend);
+ if(retVal != I2C_OK)
+ {
+ yellow_on();
+ }
+
+ va_end(args);
+ return 0;
+ }
+ _delay_ms(100);
+}
View
@@ -0,0 +1,8 @@
+#ifndef LPRINTF_H
+#define LPRINTF_H
+
+int lprintf(char *, ...);
+
+int lprintf_P(const char *, ...);
+
+#endif
Oops, something went wrong.

0 comments on commit b834737

Please sign in to comment.