buzzer setup
This commit is contained in:
parent
a144e547cc
commit
1676f9843d
|
@ -36,6 +36,9 @@
|
||||||
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="de.innot.avreclipse.compiler.option.incpath.2022106753" name="Include Paths (-I)" superClass="de.innot.avreclipse.compiler.option.incpath" valueType="includePath">
|
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="de.innot.avreclipse.compiler.option.incpath.2022106753" name="Include Paths (-I)" superClass="de.innot.avreclipse.compiler.option.incpath" valueType="includePath">
|
||||||
<listOptionValue builtIn="false" value="/usr/avr/sys-root/include/"/>
|
<listOptionValue builtIn="false" value="/usr/avr/sys-root/include/"/>
|
||||||
</option>
|
</option>
|
||||||
|
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="de.innot.avreclipse.compiler.option.def.266185078" name="Define Syms (-D)" superClass="de.innot.avreclipse.compiler.option.def" valueType="definedSymbols">
|
||||||
|
<listOptionValue builtIn="false" value="DEBUG"/>
|
||||||
|
</option>
|
||||||
<inputType id="de.innot.avreclipse.compiler.winavr.input.507254525" name="C Source Files" superClass="de.innot.avreclipse.compiler.winavr.input"/>
|
<inputType id="de.innot.avreclipse.compiler.winavr.input.507254525" name="C Source Files" superClass="de.innot.avreclipse.compiler.winavr.input"/>
|
||||||
</tool>
|
</tool>
|
||||||
<tool id="de.innot.avreclipse.tool.cppcompiler.app.debug.1143634285" name="AVR C++ Compiler" superClass="de.innot.avreclipse.tool.cppcompiler.app.debug">
|
<tool id="de.innot.avreclipse.tool.cppcompiler.app.debug.1143634285" name="AVR C++ Compiler" superClass="de.innot.avreclipse.tool.cppcompiler.app.debug">
|
||||||
|
@ -44,6 +47,7 @@
|
||||||
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="de.innot.avreclipse.cppcompiler.option.incpath.823066655" name="Include Paths (-I)" superClass="de.innot.avreclipse.cppcompiler.option.incpath" valueType="includePath">
|
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="de.innot.avreclipse.cppcompiler.option.incpath.823066655" name="Include Paths (-I)" superClass="de.innot.avreclipse.cppcompiler.option.incpath" valueType="includePath">
|
||||||
<listOptionValue builtIn="false" value="/usr/avr/sys-root/include/"/>
|
<listOptionValue builtIn="false" value="/usr/avr/sys-root/include/"/>
|
||||||
</option>
|
</option>
|
||||||
|
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="true" id="de.innot.avreclipse.cppcompiler.option.def.1747193420" name="Define Syms (-D)" superClass="de.innot.avreclipse.cppcompiler.option.def" valueType="definedSymbols"/>
|
||||||
<inputType id="de.innot.avreclipse.cppcompiler.input.250930691" superClass="de.innot.avreclipse.cppcompiler.input"/>
|
<inputType id="de.innot.avreclipse.cppcompiler.input.250930691" superClass="de.innot.avreclipse.cppcompiler.input"/>
|
||||||
</tool>
|
</tool>
|
||||||
<tool id="de.innot.avreclipse.tool.linker.winavr.app.debug.853456894" name="AVR C Linker" superClass="de.innot.avreclipse.tool.linker.winavr.app.debug"/>
|
<tool id="de.innot.avreclipse.tool.linker.winavr.app.debug.853456894" name="AVR C Linker" superClass="de.innot.avreclipse.tool.linker.winavr.app.debug"/>
|
||||||
|
|
|
@ -78,7 +78,7 @@ void charger::update() {
|
||||||
|
|
||||||
full++;
|
full++;
|
||||||
|
|
||||||
if (full == 2) {
|
if (full == 5) {
|
||||||
//not charging --> battery full
|
//not charging --> battery full
|
||||||
status.active = false;
|
status.active = false;
|
||||||
full = 0;
|
full = 0;
|
||||||
|
@ -93,6 +93,8 @@ void charger::update() {
|
||||||
const double div = 0.000277778;
|
const double div = 0.000277778;
|
||||||
capacity = capacity + ((unsigned long int) (div * getCurrent() * 1000));
|
capacity = capacity + ((unsigned long int) (div * getCurrent() * 1000));
|
||||||
//serialSend("update\r\n");
|
//serialSend("update\r\n");
|
||||||
|
|
||||||
|
full = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -94,9 +94,9 @@ ISR (TIMER1_COMPA_vect) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#ifdef DEBUG
|
|
||||||
ISR(__vector_default) {
|
ISR(__vector_default) {
|
||||||
|
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,8 @@
|
||||||
ioController::ioController() {
|
ioController::ioController() {
|
||||||
ports_init();
|
ports_init();
|
||||||
adc_init();
|
adc_init();
|
||||||
|
//beeps = 0;
|
||||||
|
PORTB |= (1 << BUZZER);
|
||||||
}
|
}
|
||||||
|
|
||||||
ioController::~ioController() {
|
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) {
|
void ioController::adc_init(void) {
|
||||||
ADMUX = (1 << REFS0); //select AVCC as reference
|
ADMUX = (1 << REFS0); //select AVCC as reference
|
||||||
ADCSRA = (1 << ADEN) | 7; //enable and prescale = 128 (16MHz/128 = 125kHz)
|
ADCSRA = (1 << ADEN) | 7; //enable and prescale = 128 (16MHz/128 = 125kHz)
|
||||||
|
@ -130,3 +123,45 @@ void ioController::setWS2812_red() {
|
||||||
setWS2812(BRIGHTNESS, 0, 0);
|
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;
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,8 +11,10 @@
|
||||||
class ioController {
|
class ioController {
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
void setWS2812(const unsigned char red, const unsigned char green,
|
void setWS2812(const unsigned char red, const unsigned char green,
|
||||||
const unsigned char blue);
|
const unsigned char blue);
|
||||||
|
void stopBuzzer();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ioController();
|
ioController();
|
||||||
|
@ -23,7 +25,7 @@ public:
|
||||||
void activateChargers();
|
void activateChargers();
|
||||||
void deactivateChargers();
|
void deactivateChargers();
|
||||||
void setActiveLED(bool pBool);
|
void setActiveLED(bool pBool);
|
||||||
void setBuzzer(bool pBool);
|
|
||||||
void adc_init(void);
|
void adc_init(void);
|
||||||
int readAdc(char chan);
|
int readAdc(char chan);
|
||||||
void setMultiplexer(bool pS2, bool pS1, bool pS0);
|
void setMultiplexer(bool pS2, bool pS1, bool pS0);
|
||||||
|
@ -31,6 +33,9 @@ public:
|
||||||
void setWS2812_clear(void);
|
void setWS2812_clear(void);
|
||||||
void setWS2812_green(void);
|
void setWS2812_green(void);
|
||||||
void setWS2812_red(void);
|
void setWS2812_red(void);
|
||||||
|
|
||||||
|
void startBuzzer();
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* SRC_IOCONTROLLER_H_ */
|
#endif /* SRC_IOCONTROLLER_H_ */
|
||||||
|
|
|
@ -30,7 +30,6 @@ int main(void) {
|
||||||
|
|
||||||
io = (ioController*) malloc(sizeof(ioController));
|
io = (ioController*) malloc(sizeof(ioController));
|
||||||
|
|
||||||
io->setBuzzer(false);
|
|
||||||
io->deactivateChargers();
|
io->deactivateChargers();
|
||||||
io->setActiveLED(true);
|
io->setActiveLED(true);
|
||||||
io->activateChargers();
|
io->activateChargers();
|
||||||
|
@ -42,8 +41,7 @@ int main(void) {
|
||||||
clk = &tmp;
|
clk = &tmp;
|
||||||
|
|
||||||
createChargers();
|
createChargers();
|
||||||
|
io->setActiveLED(false);
|
||||||
//io.setWS2812(0, 255, 255);
|
|
||||||
|
|
||||||
//loop till power off
|
//loop till power off
|
||||||
while (true) {
|
while (true) {
|
||||||
|
@ -73,23 +71,37 @@ void updateGUI() {
|
||||||
|
|
||||||
static struct time_t lastStamp[CHARGER_SIZE];
|
static struct time_t lastStamp[CHARGER_SIZE];
|
||||||
|
|
||||||
|
static unsigned int lastCapacity[CHARGER_SIZE];
|
||||||
|
|
||||||
|
static bool fullAlert[CHARGER_SIZE];
|
||||||
|
|
||||||
if (chargers[indexCount].getStatus().active) {
|
if (chargers[indexCount].getStatus().active) {
|
||||||
//charging
|
//charging
|
||||||
lastStamp[indexCount] = clk->getTime(chargers[indexCount].getStartTime());
|
lastStamp[indexCount] = clk->getTime(
|
||||||
ui->gui_print((indexCount + 1), true,
|
chargers[indexCount].getStartTime());
|
||||||
lastStamp[indexCount],
|
|
||||||
|
lastCapacity[indexCount] =
|
||||||
|
chargers[indexCount].getCapacity();
|
||||||
|
|
||||||
|
fullAlert[indexCount] = false;
|
||||||
|
|
||||||
|
ui->gui_print((indexCount + 1), true, lastStamp[indexCount],
|
||||||
chargers[indexCount].getVoltage(),
|
chargers[indexCount].getVoltage(),
|
||||||
chargers[indexCount].getCurrent(),
|
chargers[indexCount].getCurrent(),
|
||||||
chargers[indexCount].getCapacity());
|
lastCapacity[indexCount]);
|
||||||
io->setWS2812_red();
|
io->setWS2812_red();
|
||||||
} else {
|
} else {
|
||||||
//full
|
//full
|
||||||
ui->gui_print((indexCount + 1), false,
|
ui->gui_print((indexCount + 1), false,
|
||||||
lastStamp[indexCount],
|
lastStamp[indexCount],
|
||||||
chargers[indexCount].getVoltage(),
|
chargers[indexCount].getVoltage(), 0,
|
||||||
chargers[indexCount].getCurrent(),
|
lastCapacity[indexCount]);
|
||||||
chargers[indexCount].getCapacity());
|
|
||||||
io->setWS2812_green();
|
io->setWS2812_green();
|
||||||
|
|
||||||
|
if (fullAlert[indexCount] == false) {
|
||||||
|
fullAlert[indexCount] = true;
|
||||||
|
//io->startBuzzer();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
notfound = false;
|
notfound = false;
|
||||||
|
@ -117,12 +129,14 @@ bool everySec() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void updateChargers() {
|
void updateChargers() {
|
||||||
|
io->setActiveLED(true);
|
||||||
for (int i = 0; i < CHARGER_SIZE; i++) {
|
for (int i = 0; i < CHARGER_SIZE; i++) {
|
||||||
if (chargers[i].getStatus().connected) {
|
if (chargers[i].getStatus().connected) {
|
||||||
//charger active --> battery pluged on
|
//charger active --> battery pluged on
|
||||||
chargers[i].update();
|
chargers[i].update();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
io->setActiveLED(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
void checkForBattery() { //TODO
|
void checkForBattery() { //TODO
|
||||||
|
@ -130,7 +144,6 @@ void checkForBattery() { //TODO
|
||||||
static int errorCount[CHARGER_SIZE];
|
static int errorCount[CHARGER_SIZE];
|
||||||
|
|
||||||
for (int l = 0; l < CHARGER_SIZE; l++) {
|
for (int l = 0; l < CHARGER_SIZE; l++) {
|
||||||
|
|
||||||
bool zero = false;
|
bool zero = false;
|
||||||
double tmp1 = 0.0;
|
double tmp1 = 0.0;
|
||||||
double tmp2 = 0.0;
|
double tmp2 = 0.0;
|
||||||
|
@ -243,7 +256,7 @@ void serialSetup(void) {
|
||||||
UBRR0L = BUAD_RATE_CALC;
|
UBRR0L = BUAD_RATE_CALC;
|
||||||
//transimit and recieve enable
|
//transimit and recieve enable
|
||||||
UCSR0B = (1 << TXEN0) | (1 << TXCIE0) | (1 << RXEN0) | (1 << RXCIE0);
|
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) {
|
void serialSend(const char* sendString) {
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
|
|
||||||
#define DEBUG
|
//#define DEBUG
|
||||||
|
|
||||||
|
|
||||||
/* system header */
|
/* system header */
|
||||||
|
@ -69,7 +69,7 @@ void serialSend(const char* sendString);
|
||||||
|
|
||||||
/* ws2812 */
|
/* ws2812 */
|
||||||
#define LED_C 1
|
#define LED_C 1
|
||||||
#define BRIGHTNESS 20 //0 to 255
|
#define BRIGHTNESS 255 //0 to 255
|
||||||
|
|
||||||
void updateChargers();
|
void updateChargers();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue