diff --git a/Software/.cproject b/Software/.cproject
index 461b961..8602c35 100644
--- a/Software/.cproject
+++ b/Software/.cproject
@@ -36,6 +36,9 @@
+
@@ -44,6 +47,7 @@
+
diff --git a/Software/src/charger.cpp b/Software/src/charger.cpp
index fa5b598..bd9b10c 100644
--- a/Software/src/charger.cpp
+++ b/Software/src/charger.cpp
@@ -78,7 +78,7 @@ void charger::update() {
full++;
- if (full == 2) {
+ if (full == 5) {
//not charging --> battery full
status.active = false;
full = 0;
@@ -93,6 +93,8 @@ void charger::update() {
const double div = 0.000277778;
capacity = capacity + ((unsigned long int) (div * getCurrent() * 1000));
//serialSend("update\r\n");
+
+ full = 0;
}
}
diff --git a/Software/src/clock.cpp b/Software/src/clock.cpp
index 1603b53..309c690 100644
--- a/Software/src/clock.cpp
+++ b/Software/src/clock.cpp
@@ -94,9 +94,9 @@ ISR (TIMER1_COMPA_vect) {
}
-#ifdef DEBUG
+
ISR(__vector_default) {
}
-#endif
+
diff --git a/Software/src/ioController.cpp b/Software/src/ioController.cpp
index 54b368b..e158c50 100644
--- a/Software/src/ioController.cpp
+++ b/Software/src/ioController.cpp
@@ -10,6 +10,8 @@
ioController::ioController() {
ports_init();
adc_init();
+ //beeps = 0;
+ PORTB |= (1 << BUZZER);
}
ioController::~ioController() {
@@ -58,15 +60,6 @@ void ioController::setActiveLED(bool pBool) {
}
}
-void ioController::setBuzzer(bool pBool) {
- //TODO needs testing
- if (!pBool) {
- PORTB |= (1 << BUZZER); //ON
- } else {
- PORTB &= ~(1 << BUZZER); //OFF
- }
-}
-
void ioController::adc_init(void) {
ADMUX = (1 << REFS0); //select AVCC as reference
ADCSRA = (1 << ADEN) | 7; //enable and prescale = 128 (16MHz/128 = 125kHz)
@@ -130,3 +123,45 @@ void ioController::setWS2812_red() {
setWS2812(BRIGHTNESS, 0, 0);
}
+void ioController::startBuzzer() {
+ //beeps = 0;
+
+ //PORTB |= (1 << BUZZER); // switch Buzzer on
+ PORTB &= ~(1 << BUZZER);
+
+ // Set the Timer Mode to CTC
+ TCCR0A |= (1 << WGM01);
+
+ // Set the value that you want to count to
+ OCR0A = 0xFF;
+
+ TIMSK0 |= (1 << OCIE0A); //Set the ISR COMPA vect
+
+ TCCR0B |= (1 << CS02) | (1 << CS00);
+ // set prescaler to 1024 and start the timer
+
+ sei();
+ //enable interrupts
+
+}
+
+void ioController::stopBuzzer() {
+/*
+ if (beeps < 100) {
+
+ if (beeps % 10 == 0) {
+ PORTB ^= (1 << BUZZER);
+
+ }
+
+ beeps++;
+
+ } else {
+ //PORTB &= ~(1 << BUZZER); // switch Buzzer off
+ PORTB |= (1 << BUZZER);
+ TCCR0B = 0; //stop timer
+ beeps = 0;
+ }
+*/
+}
+
diff --git a/Software/src/ioController.h b/Software/src/ioController.h
index c8382ec..3f1570f 100644
--- a/Software/src/ioController.h
+++ b/Software/src/ioController.h
@@ -11,8 +11,10 @@
class ioController {
private:
+
void setWS2812(const unsigned char red, const unsigned char green,
const unsigned char blue);
+ void stopBuzzer();
public:
ioController();
@@ -23,7 +25,7 @@ public:
void activateChargers();
void deactivateChargers();
void setActiveLED(bool pBool);
- void setBuzzer(bool pBool);
+
void adc_init(void);
int readAdc(char chan);
void setMultiplexer(bool pS2, bool pS1, bool pS0);
@@ -31,6 +33,9 @@ public:
void setWS2812_clear(void);
void setWS2812_green(void);
void setWS2812_red(void);
+
+ void startBuzzer();
+
};
#endif /* SRC_IOCONTROLLER_H_ */
diff --git a/Software/src/main.cpp b/Software/src/main.cpp
index 66ae7ff..dd6fe04 100644
--- a/Software/src/main.cpp
+++ b/Software/src/main.cpp
@@ -30,7 +30,6 @@ int main(void) {
io = (ioController*) malloc(sizeof(ioController));
- io->setBuzzer(false);
io->deactivateChargers();
io->setActiveLED(true);
io->activateChargers();
@@ -42,8 +41,7 @@ int main(void) {
clk = &tmp;
createChargers();
-
- //io.setWS2812(0, 255, 255);
+ io->setActiveLED(false);
//loop till power off
while (true) {
@@ -73,23 +71,37 @@ void updateGUI() {
static struct time_t lastStamp[CHARGER_SIZE];
+ static unsigned int lastCapacity[CHARGER_SIZE];
+
+ static bool fullAlert[CHARGER_SIZE];
+
if (chargers[indexCount].getStatus().active) {
//charging
- lastStamp[indexCount] = clk->getTime(chargers[indexCount].getStartTime());
- ui->gui_print((indexCount + 1), true,
- lastStamp[indexCount],
+ lastStamp[indexCount] = clk->getTime(
+ chargers[indexCount].getStartTime());
+
+ lastCapacity[indexCount] =
+ chargers[indexCount].getCapacity();
+
+ fullAlert[indexCount] = false;
+
+ ui->gui_print((indexCount + 1), true, lastStamp[indexCount],
chargers[indexCount].getVoltage(),
chargers[indexCount].getCurrent(),
- chargers[indexCount].getCapacity());
+ lastCapacity[indexCount]);
io->setWS2812_red();
} else {
//full
ui->gui_print((indexCount + 1), false,
lastStamp[indexCount],
- chargers[indexCount].getVoltage(),
- chargers[indexCount].getCurrent(),
- chargers[indexCount].getCapacity());
+ chargers[indexCount].getVoltage(), 0,
+ lastCapacity[indexCount]);
io->setWS2812_green();
+
+ if (fullAlert[indexCount] == false) {
+ fullAlert[indexCount] = true;
+ //io->startBuzzer();
+ }
}
notfound = false;
@@ -117,12 +129,14 @@ bool everySec() {
}
void updateChargers() {
+ io->setActiveLED(true);
for (int i = 0; i < CHARGER_SIZE; i++) {
if (chargers[i].getStatus().connected) {
//charger active --> battery pluged on
chargers[i].update();
}
}
+ io->setActiveLED(false);
}
void checkForBattery() { //TODO
@@ -130,7 +144,6 @@ void checkForBattery() { //TODO
static int errorCount[CHARGER_SIZE];
for (int l = 0; l < CHARGER_SIZE; l++) {
-
bool zero = false;
double tmp1 = 0.0;
double tmp2 = 0.0;
@@ -243,7 +256,7 @@ void serialSetup(void) {
UBRR0L = BUAD_RATE_CALC;
//transimit and recieve enable
UCSR0B = (1 << TXEN0) | (1 << TXCIE0) | (1 << RXEN0) | (1 << RXCIE0);
- UCSR0C = (1 << UCSZ01) | (1 << UCSZ00); //8 bit data format
+ UCSR0C = (1 << UCSZ01) | (1 << UCSZ00);//8 bit data format
}
void serialSend(const char* sendString) {
diff --git a/Software/src/openChargeMicro.h b/Software/src/openChargeMicro.h
index db66d42..8784bdb 100644
--- a/Software/src/openChargeMicro.h
+++ b/Software/src/openChargeMicro.h
@@ -1,5 +1,5 @@
-#define DEBUG
+//#define DEBUG
/* system header */
@@ -69,7 +69,7 @@ void serialSend(const char* sendString);
/* ws2812 */
#define LED_C 1
-#define BRIGHTNESS 20 //0 to 255
+#define BRIGHTNESS 255 //0 to 255
void updateChargers();