bikegenerator/display/software/.idea/workspace.xml

750 lines
155 KiB
XML

<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ChangeListManager">
<list default="true" id="9fad4545-a424-4a82-86dc-76602cf3eef3" name="Default" comment="began working on actual code for parsing values from uart&#10;not working yet!">
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/displayboard/src/main.c" afterPath="$PROJECT_DIR$/displayboard/src/main.c" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/.idea/workspace.xml" afterPath="$PROJECT_DIR$/.idea/workspace.xml" />
</list>
<ignored path="bikegenerator.iws" />
<ignored path=".idea/workspace.xml" />
<file path="/Makefile" changelist="9fad4545-a424-4a82-86dc-76602cf3eef3" time="1371032328243" ignored="false" />
<file path="/Dummy.txt" changelist="9fad4545-a424-4a82-86dc-76602cf3eef3" time="1371242759237" ignored="false" />
<file path="/main.c" changelist="9fad4545-a424-4a82-86dc-76602cf3eef3" time="1371243598804" ignored="false" />
<file path="/uart.c" changelist="9fad4545-a424-4a82-86dc-76602cf3eef3" time="1371164805619" ignored="false" />
<file path="/a.java" changelist="9fad4545-a424-4a82-86dc-76602cf3eef3" time="1371206947114" ignored="false" />
<file path="/utils.c" changelist="9fad4545-a424-4a82-86dc-76602cf3eef3" time="1371240856046" ignored="false" />
<option name="TRACKING_ENABLED" value="true" />
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
<option name="LAST_RESOLUTION" value="IGNORE" />
</component>
<component name="ChangesViewManager" flattened_view="true" show_ignored="false" />
<component name="CreatePatchCommitExecutor">
<option name="PATCH_PATH" value="" />
</component>
<component name="DaemonCodeAnalyzer">
<disable_hints />
</component>
<component name="DebuggerManager">
<ui_properties default_suspend_policy="SuspendAll" default_condition_enabled="true" />
<breakpoint_any default_suspend_policy="SuspendAll" default_condition_enabled="true">
<breakpoint>
<option name="NOTIFY_CAUGHT" value="true" />
<option name="NOTIFY_UNCAUGHT" value="true" />
<option name="ENABLED" value="false" />
<option name="LOG_ENABLED" value="false" />
<option name="LOG_EXPRESSION_ENABLED" value="false" />
<option name="REMOVE_AFTER_HIT" value="false" />
<option name="SUSPEND_POLICY" value="SuspendAll" />
<option name="SUSPEND" value="true" />
<option name="COUNT_FILTER_ENABLED" value="false" />
<option name="COUNT_FILTER" value="0" />
<option name="CONDITION_ENABLED" value="true" />
<option name="CLASS_FILTERS_ENABLED" value="false" />
<option name="INSTANCE_FILTERS_ENABLED" value="false" />
<option name="CONDITION" value="" />
<option name="LOG_MESSAGE" value="" />
</breakpoint>
<breakpoint>
<option name="NOTIFY_CAUGHT" value="true" />
<option name="NOTIFY_UNCAUGHT" value="true" />
<option name="ENABLED" value="false" />
<option name="LOG_ENABLED" value="false" />
<option name="LOG_EXPRESSION_ENABLED" value="false" />
<option name="REMOVE_AFTER_HIT" value="false" />
<option name="SUSPEND_POLICY" value="SuspendAll" />
<option name="SUSPEND" value="true" />
<option name="COUNT_FILTER_ENABLED" value="false" />
<option name="COUNT_FILTER" value="0" />
<option name="CONDITION_ENABLED" value="true" />
<option name="CLASS_FILTERS_ENABLED" value="false" />
<option name="INSTANCE_FILTERS_ENABLED" value="false" />
<option name="CONDITION" value="" />
<option name="LOG_MESSAGE" value="" />
</breakpoint>
</breakpoint_any>
<breakpoint_rules />
<ui_properties />
</component>
<component name="ExecutionTargetManager" SELECTED_TARGET="default_target" />
<component name="FavoritesManager">
<favorites_list name="bikegenerator" />
</component>
<component name="FileEditorManager">
<leaf>
<file leaf-file-name="main.c" pinned="false" current="true" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/displayboard/src/main.c">
<provider selected="true" editor-type-id="text-editor">
<state line="198" column="6" selection-start="4939" selection-end="4939" vertical-scroll-proportion="1.4441965">
<folding>
<element signature="n#{&#10;&#9;// clock is 8MHz&#10;&#9;TCCR1B |= _BV(WGM12) | _BV(CS11) | _BV(CS10) ; // CTC Mode for Timer 1 (16Bit) with prescale of 64&#10;&#9;OCR1A = 250; // 500Hz&#10;&#9;TIMSK = _BV(OCIE1A);&#10;&#9;sei();&#9;// enable interrupts&#10;}#0;n#static void timer_init(void) {&#10;&#9;// clock is 8MHz&#10;&#9;TCCR1B |= _BV(WGM12) | _BV(CS11) | _BV(CS10) ; // CTC Mode for Timer 1 (16Bit) with prescale of 64&#10;&#9;OCR1A = 250; // 500Hz&#10;&#9;TIMSK = _BV(OCIE1A);&#10;&#9;sei();&#9;// enable interrupts&#10;}#0;n#const uint8_t digit_translate[10] = {&#10; 63, 6, 91, 79, 102, 109, 125, 7, 127, 111&#10;};&#10;&#10;&#10;static void timer_init(void) {&#10;&#9;// clock is 8MHz&#10;&#9;TCCR1B |= _BV(WGM12) | _BV(CS11) | _BV(CS10) ; // CTC Mode for Timer 1 (16Bit) with prescale of 64&#10;&#9;OCR1A = 250; // 500Hz&#10;&#9;TIMSK = _BV(OCIE1A);&#10;&#9;sei();&#9;// enable interrupts&#10;}&#10;&#10;static void ports_init(void) {&#10; // make column / digit driver pins to output&#10; LEDDIG_DDR |= _BV(LEDS_MID1) | _BV(LEDS_MID2) | _BV(LEDS_LOAD) | _BV(LEDS_GEN);&#10; SEVENSEGDIG_DDR |= _BV(DIG0) | _BV(DIG1) | _BV(DIG2) | _BV(DIG3) | _BV(DIG4) | _BV(DIG5);&#10;&#10; // make data ports to output&#10; LED_DDR = 0xff;&#10; SEVENSEG_DDR = 0xff;&#10;&#10; SEVENSEGDIG_PORT = 0;&#10; SEVENSEG_PORT = 0;&#10;&#10; LEDDIG_PORT = 0;&#10; LED_PORT = 0;&#10;}&#10;&#10;static void print_sevenseg(uint8_t display, uint16_t value) {&#10; uint8_t d[3];&#10; d[2] = (value % 1000 / 100 );&#10; d[1] = (value % 100 / 10 );&#10; d[0] = (value % 10);&#10;&#10; if(display == 0) {&#10; for(uint8_t i = 0; i&lt; 3; i++) {&#10; digitbuffer[i] = digit_translate[d[i]];&#10; }&#10; } else {&#10; for(uint8_t i = 0; i&lt; 3; i++) {&#10; digitbuffer[i+3] = digit_translate[d[i]];&#10; }&#10; }&#10;}&#10;&#10;#ifdef DEBUG&#10;void pretty_print_all_values(void) {&#10; uart_puts_P(&quot;Voltage: &quot;);&#10; uart_print_uint16(voltage);&#10; uart_puts_P(&quot;mV\r\n&quot;);&#10;&#10; uart_puts_P(&quot;Load: &quot;);&#10; uart_print_uint16(current_out);&#10; uart_puts_P(&quot;mA &quot;);&#10; uart_print_uint16( power_load);&#10; uart_puts_P(&quot;W\r\n&quot;);&#10;&#10; uart_puts_P(&quot;Generator: &quot;);&#10; uart_print_uint16(current_in);&#10; uart_puts_P(&quot;mA &quot;);&#10; uart_print_uint16( power_gen);&#10; uart_puts_P(&quot;W\r\n&quot;);&#10;&#10; uart_puts_P(&quot;switches (load, dump, gen): &quot;);&#10; uart_putc(48 + loadsw);&#10; uart_putc(',');&#10; uart_putc(48 + dumpsw);&#10; uart_putc(',');&#10; uart_putc(48 + gensw);&#10; uart_puts_P(&quot;\r\n&quot;);&#10;}&#10;#endif&#10;&#10;void process_command() {&#10; if(strstr(command_in,&quot;A&quot;) != NULL) {&#10; // we have an A and B (from check in work_uart()&#10; // so our message should be complete and consist of:&#10; // A$voltage,$current_in,$current_out,$power_in,$power_out,loadsw,dumpsw,gensw\n&#10;&#10; //A12.5,65464,00000,00000,00000,1,0,1B&#10;&#10; char *token;&#10; uint8_t tokencounter = 0;&#10;&#10; char *start = strrchr(command_in, 'A');&#10;&#10; // remove first (B is ignored by atoi)&#10; start++;&#10;&#10;#ifdef DEBUG&#10; uart_puts_P(&quot;from start: &quot;);&#10; uart_puts(start);&#10; uart_puts_P(&quot;\r\n&quot;);&#10;#endif&#10;&#10; token = strtok(start, &quot;,&quot;);&#10;&#10; while( token ) {&#10;#ifdef DEBUG&#10; uart_puts_P(&quot;token= &quot;);&#10; uart_puts(token);&#10; uart_puts_P(&quot;\r\n&quot;);&#10;#endif&#10;&#10; switch(tokencounter) {&#10; case 0:&#10; voltage = atoi(token);&#10; break;&#10; case 1:&#10; current_in = atoi(token);&#10; break;&#10; case 2:&#10; current_out = atoi(token);&#10; break;&#10; case 3:&#10; power_gen = atoi(token);&#10; break;&#10; case 4:&#10; power_load = atoi(token);&#10; break;&#10; case 5:&#10; if(atoi(token) == 1) loadsw = 1;&#10; else loadsw = 0;&#10; break;&#10; case 6:&#10; if(atoi(token) == 1) dumpsw = 1;&#10; else dumpsw = 0;&#10; break;&#10; case 7:&#10; if(atoi(token) == 1) gensw = 1;&#10; else gensw = 0;&#10; break;&#10; }&#10;&#10; tokencounter++;&#10; token = strtok(NULL, &quot;,&quot;);&#10; }&#10;#ifdef DEBUG&#10; pretty_print_all_values();&#10;#endif&#10;&#10; }&#10;}&#10;&#10;void work_uart(){&#10; unsigned int c = uart_getc();&#10;&#10; if ( !(c &amp; UART_NO_DATA) ) {&#10;&#10; data_in[data_count] = c;&#10;&#10; if (data_in[data_count] == 'B') { // finish reading when newline is received&#10; data_count = 0;&#10;&#10; memcpy(command_in, data_in, BUFSIZE);&#10;&#10; // Now clear data_in, the UART can reuse it now&#10; memset(data_in, 0, BUFSIZE);&#10;&#10; process_command();&#10; } else {&#10; data_count++;&#10; }&#10; }&#10;}&#10;&#10;&#10;&#10;&#10;int main(void) {&#10;&#9;ports_init();&#10;&#9;timer_init();&#10; uart_init(UART_BAUD_SELECT(19200,F_CPU));&#10; memset(data_in, 0, BUFSIZE);&#10;&#10;&#9;while(1) {&#10;&#10;&#9; work_uart();&#10;&#10; if(syscounter &gt;= 200) {&#10; uart_putc('a'); // send a to receive values&#10;&#10; print_sevenseg(0, power_gen);&#10; print_sevenseg(1, power_load);&#10;&#10; syscounter = 0;&#10; }&#10;&#9;}&#10;&#9;&#10;&#9;return(0);&#10;}&#10;&#10;// system timer&#10;SIGNAL(TIMER1_COMPA_vect) {&#10;&#9;syscounter++;&#10;&#10;&#9;// output to sevensegment and leds&#10;&#9;// make this here to reduce display flicker&#10; digit++;&#10; if(digit &gt;5) digit = 0;&#10; leddigit++;&#10; if(leddigit &gt;3) leddigit = 0;&#10;&#10; SEVENSEG_PORT = digitbuffer[digit];&#10; SEVENSEGDIG_PORT = _BV(digit+DIG0);&#10;&#10; LED_PORT = leddigitbuffer[leddigit];&#10; LEDDIG_PORT = _BV(leddigit);&#10;}#0;n#volatile uint8_t leddigitbuffer[4] = { 0,0,0,0 };&#10;uint8_t digit = 0;&#10;uint8_t leddigit = 0;&#10;&#10;// values send over uart from powerboard&#10;uint16_t voltage = 0;&#10;int16_t current_in = 0;&#10;int16_t current_out = 0;&#10;uint8_t dumpsw = 0; //TODO: make bitfield&#10;uint8_t loadsw = 0; //TODO: make bitfield&#10;uint8_t gensw = 0; //TODO: make bitfield&#10;&#10;uint16_t power_gen = 0;&#10;uint16_t power_load = 0;&#10;&#10;unsigned char data_count = 0;&#10;unsigned char data_in[BUFSIZE];&#10;char command_in[BUFSIZE];&#10;&#10;const uint8_t digit_translate[10] = {&#10; 63, 6, 91, 79, 102, 109, 125, 7, 127, 111&#10;};&#10;&#10;&#10;static void timer_init(void) {&#10;&#9;// clock is 8MHz&#10;&#9;TCCR1B |= _BV(WGM12) | _BV(CS11) | _BV(CS10) ; // CTC Mode for Timer 1 (16Bit) with prescale of 64&#10;&#9;OCR1A = 250; // 500Hz&#10;&#9;TIMSK = _BV(OCIE1A);&#10;&#9;sei();&#9;// enable interrupts&#10;}&#10;&#10;static void ports_init(void) {&#10; // make column / digit driver pins to output&#10; LEDDIG_DDR |= _BV(LEDS_MID1) | _BV(LEDS_MID2) | _BV(LEDS_LOAD) | _BV(LEDS_GEN);&#10; SEVENSEGDIG_DDR |= _BV(DIG0) | _BV(DIG1) | _BV(DIG2) | _BV(DIG3) | _BV(DIG4) | _BV(DIG5);&#10;&#10; // make data ports to output&#10; LED_DDR = 0xff;&#10; SEVENSEG_DDR = 0xff;&#10;&#10; SEVENSEGDIG_PORT = 0;&#10; SEVENSEG_PORT = 0;&#10;&#10; LEDDIG_PORT = 0;&#10; LED_PORT = 0;&#10;}&#10;&#10;static void print_sevenseg(uint8_t display, uint16_t value) {&#10; uint8_t d[3];&#10; d[2] = (value % 1000 / 100 );&#10; d[1] = (value % 100 / 10 );&#10; d[0] = (value % 10);&#10;&#10; if(display == 0) {&#10; for(uint8_t i = 0; i&lt; 3; i++) {&#10; digitbuffer[i] = digit_translate[d[i]];&#10; }&#10; } else {&#10; for(uint8_t i = 0; i&lt; 3; i++) {&#10; digitbuffer[i+3] = digit_translate[d[i]];&#10; }&#10; }&#10;}&#10;&#10;#ifdef DEBUG&#10;void pretty_print_all_values(void) {&#10; uart_puts_P(&quot;Voltage: &quot;);&#10; uart_print_uint16(voltage);&#10; uart_puts_P(&quot;mV\r\n&quot;);&#10;&#10; uart_puts_P(&quot;Load: &quot;);&#10; uart_print_uint16(current_out);&#10; uart_puts_P(&quot;mA &quot;);&#10; uart_print_uint16( power_load);&#10; uart_puts_P(&quot;W\r\n&quot;);&#10;&#10; uart_puts_P(&quot;Generator: &quot;);&#10; uart_print_uint16(current_in);&#10; uart_puts_P(&quot;mA &quot;);&#10; uart_print_uint16( power_gen);&#10; uart_puts_P(&quot;W\r\n&quot;);&#10;&#10; uart_puts_P(&quot;switches (load, dump, gen): &quot;);&#10; uart_putc(48 + loadsw);&#10; uart_putc(',');&#10; uart_putc(48 + dumpsw);&#10; uart_putc(',');&#10; uart_putc(48 + gensw);&#10; uart_puts_P(&quot;\r\n&quot;);&#10;}&#10;#endif&#10;&#10;void process_command() {&#10; if(strstr(command_in,&quot;A&quot;) != NULL) {&#10; // we have an A and B (from check in work_uart()&#10; // so our message should be complete and consist of:&#10; // A$voltage,$current_in,$current_out,$power_in,$power_out,loadsw,dumpsw,gensw\n&#10;&#10; //A12.5,65464,00000,00000,00000,1,0,1B&#10;&#10; char *token;&#10; uint8_t tokencounter = 0;&#10;&#10; char *start = strrchr(command_in, 'A');&#10;&#10; // remove first (B is ignored by atoi)&#10; start++;&#10;&#10;#ifdef DEBUG&#10; uart_puts_P(&quot;from start: &quot;);&#10; uart_puts(start);&#10; uart_puts_P(&quot;\r\n&quot;);&#10;#endif&#10;&#10; token = strtok(start, &quot;,&quot;);&#10;&#10; while( token ) {&#10;#ifdef DEBUG&#10; uart_puts_P(&quot;token= &quot;);&#10; uart_puts(token);&#10; uart_puts_P(&quot;\r\n&quot;);&#10;#endif&#10;&#10; switch(tokencounter) {&#10; case 0:&#10; voltage = atoi(token);&#10; break;&#10; case 1:&#10; current_in = atoi(token);&#10; break;&#10; case 2:&#10; current_out = atoi(token);&#10; break;&#10; case 3:&#10; power_gen = atoi(token);&#10; break;&#10; case 4:&#10; power_load = atoi(token);&#10; break;&#10; case 5:&#10; if(atoi(token) == 1) loadsw = 1;&#10; else loadsw = 0;&#10; break;&#10; case 6:&#10; if(atoi(token) == 1) dumpsw = 1;&#10; else dumpsw = 0;&#10; break;&#10; case 7:&#10; if(atoi(token) == 1) gensw = 1;&#10; else gensw = 0;&#10; break;&#10; }&#10;&#10; tokencounter++;&#10; token = strtok(NULL, &quot;,&quot;);&#10; }&#10;#ifdef DEBUG&#10; pretty_print_all_values();&#10;#endif&#10;&#10; }&#10;}&#10;&#10;void work_uart(){&#10; unsigned int c = uart_getc();&#10;&#10; if ( !(c &amp; UART_NO_DATA) ) {&#10;&#10; data_in[data_count] = c;&#10;&#10; if (data_in[data_count] == 'B') { // finish reading when newline is received&#10; data_count = 0;&#10;&#10; memcpy(command_in, data_in, BUFSIZE);&#10;&#10; // Now clear data_in, the UART can reuse it now&#10; memset(data_in, 0, BUFSIZE);&#10;&#10; process_command();&#10; } else {&#10; data_count++;&#10; }&#10; }&#10;}&#10;&#10;&#10;&#10;&#10;int main(void) {&#10;&#9;ports_init();&#10;&#9;timer_init();&#10; uart_init(UART_BAUD_SELECT(19200,F_CPU));&#10; memset(data_in, 0, BUFSIZE);&#10;&#10;&#9;while(1) {&#10;&#10;&#9; work_uart();&#10;&#10; if(syscounter &gt;= 200) {&#10; uart_putc('a'); // send a to receive values&#10;&#10; print_sevenseg(0, power_gen);&#10; print_sevenseg(1, power_load);&#10;&#10; syscounter = 0;&#10; }&#10;&#9;}&#10;&#9;&#10;&#9;return(0);&#10;}&#10;&#10;// system timer&#10;SIGNAL(TIMER1_COMPA_vect) {&#10;&#9;syscounter++;&#10;&#10;&#9;// output to sevensegment and leds&#10;&#9;// make this here to reduce display flicker&#10; digit++;&#10; if(digit &gt;5) digit = 0;&#10; leddigit++;&#10; if(leddigit &gt;3) leddigit = 0;&#10;&#10; SEVENSEG_PORT = digitbuffer[digit];&#10; SEVENSEGDIG_PORT = _BV(digit+DIG0);&#10;&#10; LED_PORT = leddigitbuffer[leddigit];&#10; LEDDIG_PORT = _BV(leddigit);&#10;}#0;n#volatile uint8_t digitbuffer[6] = { 0,0,0,0,0,0 };&#10;volatile uint8_t leddigitbuffer[4] = { 0,0,0,0 };&#10;uint8_t digit = 0;&#10;uint8_t leddigit = 0;&#10;&#10;// values send over uart from powerboard&#10;uint16_t voltage = 0;&#10;int16_t current_in = 0;&#10;int16_t current_out = 0;&#10;uint8_t dumpsw = 0; //TODO: make bitfield&#10;uint8_t loadsw = 0; //TODO: make bitfield&#10;uint8_t gensw = 0; //TODO: make bitfield&#10;&#10;uint16_t power_gen = 0;&#10;uint16_t power_load = 0;&#10;&#10;unsigned char data_count = 0;&#10;unsigned char data_in[BUFSIZE];&#10;char command_in[BUFSIZE];&#10;&#10;const uint8_t digit_translate[10] = {&#10; 63, 6, 91, 79, 102, 109, 125, 7, 127, 111&#10;};&#10;&#10;&#10;static void timer_init(void) {&#10;&#9;// clock is 8MHz&#10;&#9;TCCR1B |= _BV(WGM12) | _BV(CS11) | _BV(CS10) ; // CTC Mode for Timer 1 (16Bit) with prescale of 64&#10;&#9;OCR1A = 250; // 500Hz&#10;&#9;TIMSK = _BV(OCIE1A);&#10;&#9;sei();&#9;// enable interrupts&#10;}&#10;&#10;static void ports_init(void) {&#10; // make column / digit driver pins to output&#10; LEDDIG_DDR |= _BV(LEDS_MID1) | _BV(LEDS_MID2) | _BV(LEDS_LOAD) | _BV(LEDS_GEN);&#10; SEVENSEGDIG_DDR |= _BV(DIG0) | _BV(DIG1) | _BV(DIG2) | _BV(DIG3) | _BV(DIG4) | _BV(DIG5);&#10;&#10; // make data ports to output&#10; LED_DDR = 0xff;&#10; SEVENSEG_DDR = 0xff;&#10;&#10; SEVENSEGDIG_PORT = 0;&#10; SEVENSEG_PORT = 0;&#10;&#10; LEDDIG_PORT = 0;&#10; LED_PORT = 0;&#10;}&#10;&#10;static void print_sevenseg(uint8_t display, uint16_t value) {&#10; uint8_t d[3];&#10; d[2] = (value % 1000 / 100 );&#10; d[1] = (value % 100 / 10 );&#10; d[0] = (value % 10);&#10;&#10; if(display == 0) {&#10; for(uint8_t i = 0; i&lt; 3; i++) {&#10; digitbuffer[i] = digit_translate[d[i]];&#10; }&#10; } else {&#10; for(uint8_t i = 0; i&lt; 3; i++) {&#10; digitbuffer[i+3] = digit_translate[d[i]];&#10; }&#10; }&#10;}&#10;&#10;#ifdef DEBUG&#10;void pretty_print_all_values(void) {&#10; uart_puts_P(&quot;Voltage: &quot;);&#10; uart_print_uint16(voltage);&#10; uart_puts_P(&quot;mV\r\n&quot;);&#10;&#10; uart_puts_P(&quot;Load: &quot;);&#10; uart_print_uint16(current_out);&#10; uart_puts_P(&quot;mA &quot;);&#10; uart_print_uint16( power_load);&#10; uart_puts_P(&quot;W\r\n&quot;);&#10;&#10; uart_puts_P(&quot;Generator: &quot;);&#10; uart_print_uint16(current_in);&#10; uart_puts_P(&quot;mA &quot;);&#10; uart_print_uint16( power_gen);&#10; uart_puts_P(&quot;W\r\n&quot;);&#10;&#10; uart_puts_P(&quot;switches (load, dump, gen): &quot;);&#10; uart_putc(48 + loadsw);&#10; uart_putc(',');&#10; uart_putc(48 + dumpsw);&#10; uart_putc(',');&#10; uart_putc(48 + gensw);&#10; uart_puts_P(&quot;\r\n&quot;);&#10;}&#10;#endif&#10;&#10;void process_command() {&#10; if(strstr(command_in,&quot;A&quot;) != NULL) {&#10; // we have an A and B (from check in work_uart()&#10; // so our message should be complete and consist of:&#10; // A$voltage,$current_in,$current_out,$power_in,$power_out,loadsw,dumpsw,gensw\n&#10;&#10; //A12.5,65464,00000,00000,00000,1,0,1B&#10;&#10; char *token;&#10; uint8_t tokencounter = 0;&#10;&#10; char *start = strrchr(command_in, 'A');&#10;&#10; // remove first (B is ignored by atoi)&#10; start++;&#10;&#10;#ifdef DEBUG&#10; uart_puts_P(&quot;from start: &quot;);&#10; uart_puts(start);&#10; uart_puts_P(&quot;\r\n&quot;);&#10;#endif&#10;&#10; token = strtok(start, &quot;,&quot;);&#10;&#10; while( token ) {&#10;#ifdef DEBUG&#10; uart_puts_P(&quot;token= &quot;);&#10; uart_puts(token);&#10; uart_puts_P(&quot;\r\n&quot;);&#10;#endif&#10;&#10; switch(tokencounter) {&#10; case 0:&#10; voltage = atoi(token);&#10; break;&#10; case 1:&#10; current_in = atoi(token);&#10; break;&#10; case 2:&#10; current_out = atoi(token);&#10; break;&#10; case 3:&#10; power_gen = atoi(token);&#10; break;&#10; case 4:&#10; power_load = atoi(token);&#10; break;&#10; case 5:&#10; if(atoi(token) == 1) loadsw = 1;&#10; else loadsw = 0;&#10; break;&#10; case 6:&#10; if(atoi(token) == 1) dumpsw = 1;&#10; else dumpsw = 0;&#10; break;&#10; case 7:&#10; if(atoi(token) == 1) gensw = 1;&#10; else gensw = 0;&#10; break;&#10; }&#10;&#10; tokencounter++;&#10; token = strtok(NULL, &quot;,&quot;);&#10; }&#10;#ifdef DEBUG&#10; pretty_print_all_values();&#10;#endif&#10;&#10; }&#10;}&#10;&#10;void work_uart(){&#10; unsigned int c = uart_getc();&#10;&#10; if ( !(c &amp; UART_NO_DATA) ) {&#10;&#10; data_in[data_count] = c;&#10;&#10; if (data_in[data_count] == 'B') { // finish reading when newline is received&#10; data_count = 0;&#10;&#10; memcpy(command_in, data_in, BUFSIZE);&#10;&#10; // Now clear data_in, the UART can reuse it now&#10; memset(data_in, 0, BUFSIZE);&#10;&#10; process_command();&#10; } else {&#10; data_count++;&#10; }&#10; }&#10;}&#10;&#10;&#10;&#10;&#10;int main(void) {&#10;&#9;ports_init();&#10;&#9;timer_init();&#10; uart_init(UART_BAUD_SELECT(19200,F_CPU));&#10; memset(data_in, 0, BUFSIZE);&#10;&#10;&#9;while(1) {&#10;&#10;&#9; work_uart();&#10;&#10; if(syscounter &gt;= 200) {&#10; uart_putc('a'); // send a to receive values&#10;&#10; print_sevenseg(0, power_gen);&#10; print_sevenseg(1, power_load);&#10;&#10; syscounter = 0;&#10; }&#10;&#9;}&#10;&#9;&#10;&#9;return(0);&#10;}&#10;&#10;// system timer&#10;SIGNAL(TIMER1_COMPA_vect) {&#10;&#9;syscounter++;&#10;&#10;&#9;// output to sevensegment and leds&#10;&#9;// make this here to reduce display flicker&#10; digit++;&#10; if(digit &gt;5) digit = 0;&#10; leddigit++;&#10; if(leddigit &gt;3) leddigit = 0;&#10;&#10; SEVENSEG_PORT = digitbuffer[digit];&#10; SEVENSEGDIG_PORT = _BV(digit+DIG0);&#10;&#10; LED_PORT = leddigitbuffer[leddigit];&#10; LEDDIG_PORT = _BV(leddigit);&#10;}#0" expanded="false" />
<element signature="n#{&#10; // make column / digit driver pins to output&#10; LEDDIG_DDR |= _BV(LEDS_MID1) | _BV(LEDS_MID2) | _BV(LEDS_LOAD) | _BV(LEDS_GEN);&#10; SEVENSEGDIG_DDR |= _BV(DIG0) | _BV(DIG1) | _BV(DIG2) | _BV(DIG3) | _BV(DIG4) | _BV(DIG5);&#10;&#10; // make data ports to output&#10; LED_DDR = 0xff;&#10; SEVENSEG_DDR = 0xff;&#10;&#10; SEVENSEGDIG_PORT = 0;&#10; SEVENSEG_PORT = 0;&#10;&#10; LEDDIG_PORT = 0;&#10; LED_PORT = 0;&#10;}#0;n#static void ports_init(void) {&#10; // make column / digit driver pins to output&#10; LEDDIG_DDR |= _BV(LEDS_MID1) | _BV(LEDS_MID2) | _BV(LEDS_LOAD) | _BV(LEDS_GEN);&#10; SEVENSEGDIG_DDR |= _BV(DIG0) | _BV(DIG1) | _BV(DIG2) | _BV(DIG3) | _BV(DIG4) | _BV(DIG5);&#10;&#10; // make data ports to output&#10; LED_DDR = 0xff;&#10; SEVENSEG_DDR = 0xff;&#10;&#10; SEVENSEGDIG_PORT = 0;&#10; SEVENSEG_PORT = 0;&#10;&#10; LEDDIG_PORT = 0;&#10; LED_PORT = 0;&#10;}#0;n#const uint8_t digit_translate[10] = {&#10; 63, 6, 91, 79, 102, 109, 125, 7, 127, 111&#10;};&#10;&#10;&#10;static void timer_init(void) {&#10;&#9;// clock is 8MHz&#10;&#9;TCCR1B |= _BV(WGM12) | _BV(CS11) | _BV(CS10) ; // CTC Mode for Timer 1 (16Bit) with prescale of 64&#10;&#9;OCR1A = 250; // 500Hz&#10;&#9;TIMSK = _BV(OCIE1A);&#10;&#9;sei();&#9;// enable interrupts&#10;}&#10;&#10;static void ports_init(void) {&#10; // make column / digit driver pins to output&#10; LEDDIG_DDR |= _BV(LEDS_MID1) | _BV(LEDS_MID2) | _BV(LEDS_LOAD) | _BV(LEDS_GEN);&#10; SEVENSEGDIG_DDR |= _BV(DIG0) | _BV(DIG1) | _BV(DIG2) | _BV(DIG3) | _BV(DIG4) | _BV(DIG5);&#10;&#10; // make data ports to output&#10; LED_DDR = 0xff;&#10; SEVENSEG_DDR = 0xff;&#10;&#10; SEVENSEGDIG_PORT = 0;&#10; SEVENSEG_PORT = 0;&#10;&#10; LEDDIG_PORT = 0;&#10; LED_PORT = 0;&#10;}&#10;&#10;static void print_sevenseg(uint8_t display, uint16_t value) {&#10; uint8_t d[3];&#10; d[2] = (value % 1000 / 100 );&#10; d[1] = (value % 100 / 10 );&#10; d[0] = (value % 10);&#10;&#10; if(display == 0) {&#10; for(uint8_t i = 0; i&lt; 3; i++) {&#10; digitbuffer[i] = digit_translate[d[i]];&#10; }&#10; } else {&#10; for(uint8_t i = 0; i&lt; 3; i++) {&#10; digitbuffer[i+3] = digit_translate[d[i]];&#10; }&#10; }&#10;}&#10;&#10;#ifdef DEBUG&#10;void pretty_print_all_values(void) {&#10; uart_puts_P(&quot;Voltage: &quot;);&#10; uart_print_uint16(voltage);&#10; uart_puts_P(&quot;mV\r\n&quot;);&#10;&#10; uart_puts_P(&quot;Load: &quot;);&#10; uart_print_uint16(current_out);&#10; uart_puts_P(&quot;mA &quot;);&#10; uart_print_uint16( power_load);&#10; uart_puts_P(&quot;W\r\n&quot;);&#10;&#10; uart_puts_P(&quot;Generator: &quot;);&#10; uart_print_uint16(current_in);&#10; uart_puts_P(&quot;mA &quot;);&#10; uart_print_uint16( power_gen);&#10; uart_puts_P(&quot;W\r\n&quot;);&#10;&#10; uart_puts_P(&quot;switches (load, dump, gen): &quot;);&#10; uart_putc(48 + loadsw);&#10; uart_putc(',');&#10; uart_putc(48 + dumpsw);&#10; uart_putc(',');&#10; uart_putc(48 + gensw);&#10; uart_puts_P(&quot;\r\n&quot;);&#10;}&#10;#endif&#10;&#10;void process_command() {&#10; if(strstr(command_in,&quot;A&quot;) != NULL) {&#10; // we have an A and B (from check in work_uart()&#10; // so our message should be complete and consist of:&#10; // A$voltage,$current_in,$current_out,$power_in,$power_out,loadsw,dumpsw,gensw\n&#10;&#10; //A12.5,65464,00000,00000,00000,1,0,1B&#10;&#10; char *token;&#10; uint8_t tokencounter = 0;&#10;&#10; char *start = strrchr(command_in, 'A');&#10;&#10; // remove first (B is ignored by atoi)&#10; start++;&#10;&#10;#ifdef DEBUG&#10; uart_puts_P(&quot;from start: &quot;);&#10; uart_puts(start);&#10; uart_puts_P(&quot;\r\n&quot;);&#10;#endif&#10;&#10; token = strtok(start, &quot;,&quot;);&#10;&#10; while( token ) {&#10;#ifdef DEBUG&#10; uart_puts_P(&quot;token= &quot;);&#10; uart_puts(token);&#10; uart_puts_P(&quot;\r\n&quot;);&#10;#endif&#10;&#10; switch(tokencounter) {&#10; case 0:&#10; voltage = atoi(token);&#10; break;&#10; case 1:&#10; current_in = atoi(token);&#10; break;&#10; case 2:&#10; current_out = atoi(token);&#10; break;&#10; case 3:&#10; power_gen = atoi(token);&#10; break;&#10; case 4:&#10; power_load = atoi(token);&#10; break;&#10; case 5:&#10; if(atoi(token) == 1) loadsw = 1;&#10; else loadsw = 0;&#10; break;&#10; case 6:&#10; if(atoi(token) == 1) dumpsw = 1;&#10; else dumpsw = 0;&#10; break;&#10; case 7:&#10; if(atoi(token) == 1) gensw = 1;&#10; else gensw = 0;&#10; break;&#10; }&#10;&#10; tokencounter++;&#10; token = strtok(NULL, &quot;,&quot;);&#10; }&#10;#ifdef DEBUG&#10; pretty_print_all_values();&#10;#endif&#10;&#10; }&#10;}&#10;&#10;void work_uart(){&#10; unsigned int c = uart_getc();&#10;&#10; if ( !(c &amp; UART_NO_DATA) ) {&#10;&#10; data_in[data_count] = c;&#10;&#10; if (data_in[data_count] == 'B') { // finish reading when newline is received&#10; data_count = 0;&#10;&#10; memcpy(command_in, data_in, BUFSIZE);&#10;&#10; // Now clear data_in, the UART can reuse it now&#10; memset(data_in, 0, BUFSIZE);&#10;&#10; process_command();&#10; } else {&#10; data_count++;&#10; }&#10; }&#10;}&#10;&#10;&#10;&#10;&#10;int main(void) {&#10;&#9;ports_init();&#10;&#9;timer_init();&#10; uart_init(UART_BAUD_SELECT(19200,F_CPU));&#10; memset(data_in, 0, BUFSIZE);&#10;&#10;&#9;while(1) {&#10;&#10;&#9; work_uart();&#10;&#10; if(syscounter &gt;= 200) {&#10; uart_putc('a'); // send a to receive values&#10;&#10; print_sevenseg(0, power_gen);&#10; print_sevenseg(1, power_load);&#10;&#10; syscounter = 0;&#10; }&#10;&#9;}&#10;&#9;&#10;&#9;return(0);&#10;}&#10;&#10;// system timer&#10;SIGNAL(TIMER1_COMPA_vect) {&#10;&#9;syscounter++;&#10;&#10;&#9;// output to sevensegment and leds&#10;&#9;// make this here to reduce display flicker&#10; digit++;&#10; if(digit &gt;5) digit = 0;&#10; leddigit++;&#10; if(leddigit &gt;3) leddigit = 0;&#10;&#10; SEVENSEG_PORT = digitbuffer[digit];&#10; SEVENSEGDIG_PORT = _BV(digit+DIG0);&#10;&#10; LED_PORT = leddigitbuffer[leddigit];&#10; LEDDIG_PORT = _BV(leddigit);&#10;}#0;n#volatile uint8_t leddigitbuffer[4] = { 0,0,0,0 };&#10;uint8_t digit = 0;&#10;uint8_t leddigit = 0;&#10;&#10;// values send over uart from powerboard&#10;uint16_t voltage = 0;&#10;int16_t current_in = 0;&#10;int16_t current_out = 0;&#10;uint8_t dumpsw = 0; //TODO: make bitfield&#10;uint8_t loadsw = 0; //TODO: make bitfield&#10;uint8_t gensw = 0; //TODO: make bitfield&#10;&#10;uint16_t power_gen = 0;&#10;uint16_t power_load = 0;&#10;&#10;unsigned char data_count = 0;&#10;unsigned char data_in[BUFSIZE];&#10;char command_in[BUFSIZE];&#10;&#10;const uint8_t digit_translate[10] = {&#10; 63, 6, 91, 79, 102, 109, 125, 7, 127, 111&#10;};&#10;&#10;&#10;static void timer_init(void) {&#10;&#9;// clock is 8MHz&#10;&#9;TCCR1B |= _BV(WGM12) | _BV(CS11) | _BV(CS10) ; // CTC Mode for Timer 1 (16Bit) with prescale of 64&#10;&#9;OCR1A = 250; // 500Hz&#10;&#9;TIMSK = _BV(OCIE1A);&#10;&#9;sei();&#9;// enable interrupts&#10;}&#10;&#10;static void ports_init(void) {&#10; // make column / digit driver pins to output&#10; LEDDIG_DDR |= _BV(LEDS_MID1) | _BV(LEDS_MID2) | _BV(LEDS_LOAD) | _BV(LEDS_GEN);&#10; SEVENSEGDIG_DDR |= _BV(DIG0) | _BV(DIG1) | _BV(DIG2) | _BV(DIG3) | _BV(DIG4) | _BV(DIG5);&#10;&#10; // make data ports to output&#10; LED_DDR = 0xff;&#10; SEVENSEG_DDR = 0xff;&#10;&#10; SEVENSEGDIG_PORT = 0;&#10; SEVENSEG_PORT = 0;&#10;&#10; LEDDIG_PORT = 0;&#10; LED_PORT = 0;&#10;}&#10;&#10;static void print_sevenseg(uint8_t display, uint16_t value) {&#10; uint8_t d[3];&#10; d[2] = (value % 1000 / 100 );&#10; d[1] = (value % 100 / 10 );&#10; d[0] = (value % 10);&#10;&#10; if(display == 0) {&#10; for(uint8_t i = 0; i&lt; 3; i++) {&#10; digitbuffer[i] = digit_translate[d[i]];&#10; }&#10; } else {&#10; for(uint8_t i = 0; i&lt; 3; i++) {&#10; digitbuffer[i+3] = digit_translate[d[i]];&#10; }&#10; }&#10;}&#10;&#10;#ifdef DEBUG&#10;void pretty_print_all_values(void) {&#10; uart_puts_P(&quot;Voltage: &quot;);&#10; uart_print_uint16(voltage);&#10; uart_puts_P(&quot;mV\r\n&quot;);&#10;&#10; uart_puts_P(&quot;Load: &quot;);&#10; uart_print_uint16(current_out);&#10; uart_puts_P(&quot;mA &quot;);&#10; uart_print_uint16( power_load);&#10; uart_puts_P(&quot;W\r\n&quot;);&#10;&#10; uart_puts_P(&quot;Generator: &quot;);&#10; uart_print_uint16(current_in);&#10; uart_puts_P(&quot;mA &quot;);&#10; uart_print_uint16( power_gen);&#10; uart_puts_P(&quot;W\r\n&quot;);&#10;&#10; uart_puts_P(&quot;switches (load, dump, gen): &quot;);&#10; uart_putc(48 + loadsw);&#10; uart_putc(',');&#10; uart_putc(48 + dumpsw);&#10; uart_putc(',');&#10; uart_putc(48 + gensw);&#10; uart_puts_P(&quot;\r\n&quot;);&#10;}&#10;#endif&#10;&#10;void process_command() {&#10; if(strstr(command_in,&quot;A&quot;) != NULL) {&#10; // we have an A and B (from check in work_uart()&#10; // so our message should be complete and consist of:&#10; // A$voltage,$current_in,$current_out,$power_in,$power_out,loadsw,dumpsw,gensw\n&#10;&#10; //A12.5,65464,00000,00000,00000,1,0,1B&#10;&#10; char *token;&#10; uint8_t tokencounter = 0;&#10;&#10; char *start = strrchr(command_in, 'A');&#10;&#10; // remove first (B is ignored by atoi)&#10; start++;&#10;&#10;#ifdef DEBUG&#10; uart_puts_P(&quot;from start: &quot;);&#10; uart_puts(start);&#10; uart_puts_P(&quot;\r\n&quot;);&#10;#endif&#10;&#10; token = strtok(start, &quot;,&quot;);&#10;&#10; while( token ) {&#10;#ifdef DEBUG&#10; uart_puts_P(&quot;token= &quot;);&#10; uart_puts(token);&#10; uart_puts_P(&quot;\r\n&quot;);&#10;#endif&#10;&#10; switch(tokencounter) {&#10; case 0:&#10; voltage = atoi(token);&#10; break;&#10; case 1:&#10; current_in = atoi(token);&#10; break;&#10; case 2:&#10; current_out = atoi(token);&#10; break;&#10; case 3:&#10; power_gen = atoi(token);&#10; break;&#10; case 4:&#10; power_load = atoi(token);&#10; break;&#10; case 5:&#10; if(atoi(token) == 1) loadsw = 1;&#10; else loadsw = 0;&#10; break;&#10; case 6:&#10; if(atoi(token) == 1) dumpsw = 1;&#10; else dumpsw = 0;&#10; break;&#10; case 7:&#10; if(atoi(token) == 1) gensw = 1;&#10; else gensw = 0;&#10; break;&#10; }&#10;&#10; tokencounter++;&#10; token = strtok(NULL, &quot;,&quot;);&#10; }&#10;#ifdef DEBUG&#10; pretty_print_all_values();&#10;#endif&#10;&#10; }&#10;}&#10;&#10;void work_uart(){&#10; unsigned int c = uart_getc();&#10;&#10; if ( !(c &amp; UART_NO_DATA) ) {&#10;&#10; data_in[data_count] = c;&#10;&#10; if (data_in[data_count] == 'B') { // finish reading when newline is received&#10; data_count = 0;&#10;&#10; memcpy(command_in, data_in, BUFSIZE);&#10;&#10; // Now clear data_in, the UART can reuse it now&#10; memset(data_in, 0, BUFSIZE);&#10;&#10; process_command();&#10; } else {&#10; data_count++;&#10; }&#10; }&#10;}&#10;&#10;&#10;&#10;&#10;int main(void) {&#10;&#9;ports_init();&#10;&#9;timer_init();&#10; uart_init(UART_BAUD_SELECT(19200,F_CPU));&#10; memset(data_in, 0, BUFSIZE);&#10;&#10;&#9;while(1) {&#10;&#10;&#9; work_uart();&#10;&#10; if(syscounter &gt;= 200) {&#10; uart_putc('a'); // send a to receive values&#10;&#10; print_sevenseg(0, power_gen);&#10; print_sevenseg(1, power_load);&#10;&#10; syscounter = 0;&#10; }&#10;&#9;}&#10;&#9;&#10;&#9;return(0);&#10;}&#10;&#10;// system timer&#10;SIGNAL(TIMER1_COMPA_vect) {&#10;&#9;syscounter++;&#10;&#10;&#9;// output to sevensegment and leds&#10;&#9;// make this here to reduce display flicker&#10; digit++;&#10; if(digit &gt;5) digit = 0;&#10; leddigit++;&#10; if(leddigit &gt;3) leddigit = 0;&#10;&#10; SEVENSEG_PORT = digitbuffer[digit];&#10; SEVENSEGDIG_PORT = _BV(digit+DIG0);&#10;&#10; LED_PORT = leddigitbuffer[leddigit];&#10; LEDDIG_PORT = _BV(leddigit);&#10;}#0;n#volatile uint8_t digitbuffer[6] = { 0,0,0,0,0,0 };&#10;volatile uint8_t leddigitbuffer[4] = { 0,0,0,0 };&#10;uint8_t digit = 0;&#10;uint8_t leddigit = 0;&#10;&#10;// values send over uart from powerboard&#10;uint16_t voltage = 0;&#10;int16_t current_in = 0;&#10;int16_t current_out = 0;&#10;uint8_t dumpsw = 0; //TODO: make bitfield&#10;uint8_t loadsw = 0; //TODO: make bitfield&#10;uint8_t gensw = 0; //TODO: make bitfield&#10;&#10;uint16_t power_gen = 0;&#10;uint16_t power_load = 0;&#10;&#10;unsigned char data_count = 0;&#10;unsigned char data_in[BUFSIZE];&#10;char command_in[BUFSIZE];&#10;&#10;const uint8_t digit_translate[10] = {&#10; 63, 6, 91, 79, 102, 109, 125, 7, 127, 111&#10;};&#10;&#10;&#10;static void timer_init(void) {&#10;&#9;// clock is 8MHz&#10;&#9;TCCR1B |= _BV(WGM12) | _BV(CS11) | _BV(CS10) ; // CTC Mode for Timer 1 (16Bit) with prescale of 64&#10;&#9;OCR1A = 250; // 500Hz&#10;&#9;TIMSK = _BV(OCIE1A);&#10;&#9;sei();&#9;// enable interrupts&#10;}&#10;&#10;static void ports_init(void) {&#10; // make column / digit driver pins to output&#10; LEDDIG_DDR |= _BV(LEDS_MID1) | _BV(LEDS_MID2) | _BV(LEDS_LOAD) | _BV(LEDS_GEN);&#10; SEVENSEGDIG_DDR |= _BV(DIG0) | _BV(DIG1) | _BV(DIG2) | _BV(DIG3) | _BV(DIG4) | _BV(DIG5);&#10;&#10; // make data ports to output&#10; LED_DDR = 0xff;&#10; SEVENSEG_DDR = 0xff;&#10;&#10; SEVENSEGDIG_PORT = 0;&#10; SEVENSEG_PORT = 0;&#10;&#10; LEDDIG_PORT = 0;&#10; LED_PORT = 0;&#10;}&#10;&#10;static void print_sevenseg(uint8_t display, uint16_t value) {&#10; uint8_t d[3];&#10; d[2] = (value % 1000 / 100 );&#10; d[1] = (value % 100 / 10 );&#10; d[0] = (value % 10);&#10;&#10; if(display == 0) {&#10; for(uint8_t i = 0; i&lt; 3; i++) {&#10; digitbuffer[i] = digit_translate[d[i]];&#10; }&#10; } else {&#10; for(uint8_t i = 0; i&lt; 3; i++) {&#10; digitbuffer[i+3] = digit_translate[d[i]];&#10; }&#10; }&#10;}&#10;&#10;#ifdef DEBUG&#10;void pretty_print_all_values(void) {&#10; uart_puts_P(&quot;Voltage: &quot;);&#10; uart_print_uint16(voltage);&#10; uart_puts_P(&quot;mV\r\n&quot;);&#10;&#10; uart_puts_P(&quot;Load: &quot;);&#10; uart_print_uint16(current_out);&#10; uart_puts_P(&quot;mA &quot;);&#10; uart_print_uint16( power_load);&#10; uart_puts_P(&quot;W\r\n&quot;);&#10;&#10; uart_puts_P(&quot;Generator: &quot;);&#10; uart_print_uint16(current_in);&#10; uart_puts_P(&quot;mA &quot;);&#10; uart_print_uint16( power_gen);&#10; uart_puts_P(&quot;W\r\n&quot;);&#10;&#10; uart_puts_P(&quot;switches (load, dump, gen): &quot;);&#10; uart_putc(48 + loadsw);&#10; uart_putc(',');&#10; uart_putc(48 + dumpsw);&#10; uart_putc(',');&#10; uart_putc(48 + gensw);&#10; uart_puts_P(&quot;\r\n&quot;);&#10;}&#10;#endif&#10;&#10;void process_command() {&#10; if(strstr(command_in,&quot;A&quot;) != NULL) {&#10; // we have an A and B (from check in work_uart()&#10; // so our message should be complete and consist of:&#10; // A$voltage,$current_in,$current_out,$power_in,$power_out,loadsw,dumpsw,gensw\n&#10;&#10; //A12.5,65464,00000,00000,00000,1,0,1B&#10;&#10; char *token;&#10; uint8_t tokencounter = 0;&#10;&#10; char *start = strrchr(command_in, 'A');&#10;&#10; // remove first (B is ignored by atoi)&#10; start++;&#10;&#10;#ifdef DEBUG&#10; uart_puts_P(&quot;from start: &quot;);&#10; uart_puts(start);&#10; uart_puts_P(&quot;\r\n&quot;);&#10;#endif&#10;&#10; token = strtok(start, &quot;,&quot;);&#10;&#10; while( token ) {&#10;#ifdef DEBUG&#10; uart_puts_P(&quot;token= &quot;);&#10; uart_puts(token);&#10; uart_puts_P(&quot;\r\n&quot;);&#10;#endif&#10;&#10; switch(tokencounter) {&#10; case 0:&#10; voltage = atoi(token);&#10; break;&#10; case 1:&#10; current_in = atoi(token);&#10; break;&#10; case 2:&#10; current_out = atoi(token);&#10; break;&#10; case 3:&#10; power_gen = atoi(token);&#10; break;&#10; case 4:&#10; power_load = atoi(token);&#10; break;&#10; case 5:&#10; if(atoi(token) == 1) loadsw = 1;&#10; else loadsw = 0;&#10; break;&#10; case 6:&#10; if(atoi(token) == 1) dumpsw = 1;&#10; else dumpsw = 0;&#10; break;&#10; case 7:&#10; if(atoi(token) == 1) gensw = 1;&#10; else gensw = 0;&#10; break;&#10; }&#10;&#10; tokencounter++;&#10; token = strtok(NULL, &quot;,&quot;);&#10; }&#10;#ifdef DEBUG&#10; pretty_print_all_values();&#10;#endif&#10;&#10; }&#10;}&#10;&#10;void work_uart(){&#10; unsigned int c = uart_getc();&#10;&#10; if ( !(c &amp; UART_NO_DATA) ) {&#10;&#10; data_in[data_count] = c;&#10;&#10; if (data_in[data_count] == 'B') { // finish reading when newline is received&#10; data_count = 0;&#10;&#10; memcpy(command_in, data_in, BUFSIZE);&#10;&#10; // Now clear data_in, the UART can reuse it now&#10; memset(data_in, 0, BUFSIZE);&#10;&#10; process_command();&#10; } else {&#10; data_count++;&#10; }&#10; }&#10;}&#10;&#10;&#10;&#10;&#10;int main(void) {&#10;&#9;ports_init();&#10;&#9;timer_init();&#10; uart_init(UART_BAUD_SELECT(19200,F_CPU));&#10; memset(data_in, 0, BUFSIZE);&#10;&#10;&#9;while(1) {&#10;&#10;&#9; work_uart();&#10;&#10; if(syscounter &gt;= 200) {&#10; uart_putc('a'); // send a to receive values&#10;&#10; print_sevenseg(0, power_gen);&#10; print_sevenseg(1, power_load);&#10;&#10; syscounter = 0;&#10; }&#10;&#9;}&#10;&#9;&#10;&#9;return(0);&#10;}&#10;&#10;// system timer&#10;SIGNAL(TIMER1_COMPA_vect) {&#10;&#9;syscounter++;&#10;&#10;&#9;// output to sevensegment and leds&#10;&#9;// make this here to reduce display flicker&#10; digit++;&#10; if(digit &gt;5) digit = 0;&#10; leddigit++;&#10; if(leddigit &gt;3) leddigit = 0;&#10;&#10; SEVENSEG_PORT = digitbuffer[digit];&#10; SEVENSEGDIG_PORT = _BV(digit+DIG0);&#10;&#10; LED_PORT = leddigitbuffer[leddigit];&#10; LEDDIG_PORT = _BV(leddigit);&#10;}#0" expanded="false" />
<element signature="n#{&#10; uint8_t d[3];&#10; d[2] = (value % 1000 / 100 );&#10; d[1] = (value % 100 / 10 );&#10; d[0] = (value % 10);&#10;&#10; if(display == 0) {&#10; for(uint8_t i = 0; i&lt; 3; i++) {&#10; digitbuffer[i] = digit_translate[d[i]];&#10; }&#10; } else {&#10; for(uint8_t i = 0; i&lt; 3; i++) {&#10; digitbuffer[i+3] = digit_translate[d[i]];&#10; }&#10; }&#10;}#0;n#static void print_sevenseg(uint8_t display, uint16_t value) {&#10; uint8_t d[3];&#10; d[2] = (value % 1000 / 100 );&#10; d[1] = (value % 100 / 10 );&#10; d[0] = (value % 10);&#10;&#10; if(display == 0) {&#10; for(uint8_t i = 0; i&lt; 3; i++) {&#10; digitbuffer[i] = digit_translate[d[i]];&#10; }&#10; } else {&#10; for(uint8_t i = 0; i&lt; 3; i++) {&#10; digitbuffer[i+3] = digit_translate[d[i]];&#10; }&#10; }&#10;}#0;n#const uint8_t digit_translate[10] = {&#10; 63, 6, 91, 79, 102, 109, 125, 7, 127, 111&#10;};&#10;&#10;&#10;static void timer_init(void) {&#10;&#9;// clock is 8MHz&#10;&#9;TCCR1B |= _BV(WGM12) | _BV(CS11) | _BV(CS10) ; // CTC Mode for Timer 1 (16Bit) with prescale of 64&#10;&#9;OCR1A = 250; // 500Hz&#10;&#9;TIMSK = _BV(OCIE1A);&#10;&#9;sei();&#9;// enable interrupts&#10;}&#10;&#10;static void ports_init(void) {&#10; // make column / digit driver pins to output&#10; LEDDIG_DDR |= _BV(LEDS_MID1) | _BV(LEDS_MID2) | _BV(LEDS_LOAD) | _BV(LEDS_GEN);&#10; SEVENSEGDIG_DDR |= _BV(DIG0) | _BV(DIG1) | _BV(DIG2) | _BV(DIG3) | _BV(DIG4) | _BV(DIG5);&#10;&#10; // make data ports to output&#10; LED_DDR = 0xff;&#10; SEVENSEG_DDR = 0xff;&#10;&#10; SEVENSEGDIG_PORT = 0;&#10; SEVENSEG_PORT = 0;&#10;&#10; LEDDIG_PORT = 0;&#10; LED_PORT = 0;&#10;}&#10;&#10;static void print_sevenseg(uint8_t display, uint16_t value) {&#10; uint8_t d[3];&#10; d[2] = (value % 1000 / 100 );&#10; d[1] = (value % 100 / 10 );&#10; d[0] = (value % 10);&#10;&#10; if(display == 0) {&#10; for(uint8_t i = 0; i&lt; 3; i++) {&#10; digitbuffer[i] = digit_translate[d[i]];&#10; }&#10; } else {&#10; for(uint8_t i = 0; i&lt; 3; i++) {&#10; digitbuffer[i+3] = digit_translate[d[i]];&#10; }&#10; }&#10;}&#10;&#10;#ifdef DEBUG&#10;void pretty_print_all_values(void) {&#10; uart_puts_P(&quot;Voltage: &quot;);&#10; uart_print_uint16(voltage);&#10; uart_puts_P(&quot;mV\r\n&quot;);&#10;&#10; uart_puts_P(&quot;Load: &quot;);&#10; uart_print_uint16(current_out);&#10; uart_puts_P(&quot;mA &quot;);&#10; uart_print_uint16( power_load);&#10; uart_puts_P(&quot;W\r\n&quot;);&#10;&#10; uart_puts_P(&quot;Generator: &quot;);&#10; uart_print_uint16(current_in);&#10; uart_puts_P(&quot;mA &quot;);&#10; uart_print_uint16( power_gen);&#10; uart_puts_P(&quot;W\r\n&quot;);&#10;&#10; uart_puts_P(&quot;switches (load, dump, gen): &quot;);&#10; uart_putc(48 + loadsw);&#10; uart_putc(',');&#10; uart_putc(48 + dumpsw);&#10; uart_putc(',');&#10; uart_putc(48 + gensw);&#10; uart_puts_P(&quot;\r\n&quot;);&#10;}&#10;#endif&#10;&#10;void process_command() {&#10; if(strstr(command_in,&quot;A&quot;) != NULL) {&#10; // we have an A and B (from check in work_uart()&#10; // so our message should be complete and consist of:&#10; // A$voltage,$current_in,$current_out,$power_in,$power_out,loadsw,dumpsw,gensw\n&#10;&#10; //A12.5,65464,00000,00000,00000,1,0,1B&#10;&#10; char *token;&#10; uint8_t tokencounter = 0;&#10;&#10; char *start = strrchr(command_in, 'A');&#10;&#10; // remove first (B is ignored by atoi)&#10; start++;&#10;&#10;#ifdef DEBUG&#10; uart_puts_P(&quot;from start: &quot;);&#10; uart_puts(start);&#10; uart_puts_P(&quot;\r\n&quot;);&#10;#endif&#10;&#10; token = strtok(start, &quot;,&quot;);&#10;&#10; while( token ) {&#10;#ifdef DEBUG&#10; uart_puts_P(&quot;token= &quot;);&#10; uart_puts(token);&#10; uart_puts_P(&quot;\r\n&quot;);&#10;#endif&#10;&#10; switch(tokencounter) {&#10; case 0:&#10; voltage = atoi(token);&#10; break;&#10; case 1:&#10; current_in = atoi(token);&#10; break;&#10; case 2:&#10; current_out = atoi(token);&#10; break;&#10; case 3:&#10; power_gen = atoi(token);&#10; break;&#10; case 4:&#10; power_load = atoi(token);&#10; break;&#10; case 5:&#10; if(atoi(token) == 1) loadsw = 1;&#10; else loadsw = 0;&#10; break;&#10; case 6:&#10; if(atoi(token) == 1) dumpsw = 1;&#10; else dumpsw = 0;&#10; break;&#10; case 7:&#10; if(atoi(token) == 1) gensw = 1;&#10; else gensw = 0;&#10; break;&#10; }&#10;&#10; tokencounter++;&#10; token = strtok(NULL, &quot;,&quot;);&#10; }&#10;#ifdef DEBUG&#10; pretty_print_all_values();&#10;#endif&#10;&#10; }&#10;}&#10;&#10;void work_uart(){&#10; unsigned int c = uart_getc();&#10;&#10; if ( !(c &amp; UART_NO_DATA) ) {&#10;&#10; data_in[data_count] = c;&#10;&#10; if (data_in[data_count] == 'B') { // finish reading when newline is received&#10; data_count = 0;&#10;&#10; memcpy(command_in, data_in, BUFSIZE);&#10;&#10; // Now clear data_in, the UART can reuse it now&#10; memset(data_in, 0, BUFSIZE);&#10;&#10; process_command();&#10; } else {&#10; data_count++;&#10; }&#10; }&#10;}&#10;&#10;&#10;&#10;&#10;int main(void) {&#10;&#9;ports_init();&#10;&#9;timer_init();&#10; uart_init(UART_BAUD_SELECT(19200,F_CPU));&#10; memset(data_in, 0, BUFSIZE);&#10;&#10;&#9;while(1) {&#10;&#10;&#9; work_uart();&#10;&#10; if(syscounter &gt;= 200) {&#10; uart_putc('a'); // send a to receive values&#10;&#10; print_sevenseg(0, power_gen);&#10; print_sevenseg(1, power_load);&#10;&#10; syscounter = 0;&#10; }&#10;&#9;}&#10;&#9;&#10;&#9;return(0);&#10;}&#10;&#10;// system timer&#10;SIGNAL(TIMER1_COMPA_vect) {&#10;&#9;syscounter++;&#10;&#10;&#9;// output to sevensegment and leds&#10;&#9;// make this here to reduce display flicker&#10; digit++;&#10; if(digit &gt;5) digit = 0;&#10; leddigit++;&#10; if(leddigit &gt;3) leddigit = 0;&#10;&#10; SEVENSEG_PORT = digitbuffer[digit];&#10; SEVENSEGDIG_PORT = _BV(digit+DIG0);&#10;&#10; LED_PORT = leddigitbuffer[leddigit];&#10; LEDDIG_PORT = _BV(leddigit);&#10;}#0;n#volatile uint8_t leddigitbuffer[4] = { 0,0,0,0 };&#10;uint8_t digit = 0;&#10;uint8_t leddigit = 0;&#10;&#10;// values send over uart from powerboard&#10;uint16_t voltage = 0;&#10;int16_t current_in = 0;&#10;int16_t current_out = 0;&#10;uint8_t dumpsw = 0; //TODO: make bitfield&#10;uint8_t loadsw = 0; //TODO: make bitfield&#10;uint8_t gensw = 0; //TODO: make bitfield&#10;&#10;uint16_t power_gen = 0;&#10;uint16_t power_load = 0;&#10;&#10;unsigned char data_count = 0;&#10;unsigned char data_in[BUFSIZE];&#10;char command_in[BUFSIZE];&#10;&#10;const uint8_t digit_translate[10] = {&#10; 63, 6, 91, 79, 102, 109, 125, 7, 127, 111&#10;};&#10;&#10;&#10;static void timer_init(void) {&#10;&#9;// clock is 8MHz&#10;&#9;TCCR1B |= _BV(WGM12) | _BV(CS11) | _BV(CS10) ; // CTC Mode for Timer 1 (16Bit) with prescale of 64&#10;&#9;OCR1A = 250; // 500Hz&#10;&#9;TIMSK = _BV(OCIE1A);&#10;&#9;sei();&#9;// enable interrupts&#10;}&#10;&#10;static void ports_init(void) {&#10; // make column / digit driver pins to output&#10; LEDDIG_DDR |= _BV(LEDS_MID1) | _BV(LEDS_MID2) | _BV(LEDS_LOAD) | _BV(LEDS_GEN);&#10; SEVENSEGDIG_DDR |= _BV(DIG0) | _BV(DIG1) | _BV(DIG2) | _BV(DIG3) | _BV(DIG4) | _BV(DIG5);&#10;&#10; // make data ports to output&#10; LED_DDR = 0xff;&#10; SEVENSEG_DDR = 0xff;&#10;&#10; SEVENSEGDIG_PORT = 0;&#10; SEVENSEG_PORT = 0;&#10;&#10; LEDDIG_PORT = 0;&#10; LED_PORT = 0;&#10;}&#10;&#10;static void print_sevenseg(uint8_t display, uint16_t value) {&#10; uint8_t d[3];&#10; d[2] = (value % 1000 / 100 );&#10; d[1] = (value % 100 / 10 );&#10; d[0] = (value % 10);&#10;&#10; if(display == 0) {&#10; for(uint8_t i = 0; i&lt; 3; i++) {&#10; digitbuffer[i] = digit_translate[d[i]];&#10; }&#10; } else {&#10; for(uint8_t i = 0; i&lt; 3; i++) {&#10; digitbuffer[i+3] = digit_translate[d[i]];&#10; }&#10; }&#10;}&#10;&#10;#ifdef DEBUG&#10;void pretty_print_all_values(void) {&#10; uart_puts_P(&quot;Voltage: &quot;);&#10; uart_print_uint16(voltage);&#10; uart_puts_P(&quot;mV\r\n&quot;);&#10;&#10; uart_puts_P(&quot;Load: &quot;);&#10; uart_print_uint16(current_out);&#10; uart_puts_P(&quot;mA &quot;);&#10; uart_print_uint16( power_load);&#10; uart_puts_P(&quot;W\r\n&quot;);&#10;&#10; uart_puts_P(&quot;Generator: &quot;);&#10; uart_print_uint16(current_in);&#10; uart_puts_P(&quot;mA &quot;);&#10; uart_print_uint16( power_gen);&#10; uart_puts_P(&quot;W\r\n&quot;);&#10;&#10; uart_puts_P(&quot;switches (load, dump, gen): &quot;);&#10; uart_putc(48 + loadsw);&#10; uart_putc(',');&#10; uart_putc(48 + dumpsw);&#10; uart_putc(',');&#10; uart_putc(48 + gensw);&#10; uart_puts_P(&quot;\r\n&quot;);&#10;}&#10;#endif&#10;&#10;void process_command() {&#10; if(strstr(command_in,&quot;A&quot;) != NULL) {&#10; // we have an A and B (from check in work_uart()&#10; // so our message should be complete and consist of:&#10; // A$voltage,$current_in,$current_out,$power_in,$power_out,loadsw,dumpsw,gensw\n&#10;&#10; //A12.5,65464,00000,00000,00000,1,0,1B&#10;&#10; char *token;&#10; uint8_t tokencounter = 0;&#10;&#10; char *start = strrchr(command_in, 'A');&#10;&#10; // remove first (B is ignored by atoi)&#10; start++;&#10;&#10;#ifdef DEBUG&#10; uart_puts_P(&quot;from start: &quot;);&#10; uart_puts(start);&#10; uart_puts_P(&quot;\r\n&quot;);&#10;#endif&#10;&#10; token = strtok(start, &quot;,&quot;);&#10;&#10; while( token ) {&#10;#ifdef DEBUG&#10; uart_puts_P(&quot;token= &quot;);&#10; uart_puts(token);&#10; uart_puts_P(&quot;\r\n&quot;);&#10;#endif&#10;&#10; switch(tokencounter) {&#10; case 0:&#10; voltage = atoi(token);&#10; break;&#10; case 1:&#10; current_in = atoi(token);&#10; break;&#10; case 2:&#10; current_out = atoi(token);&#10; break;&#10; case 3:&#10; power_gen = atoi(token);&#10; break;&#10; case 4:&#10; power_load = atoi(token);&#10; break;&#10; case 5:&#10; if(atoi(token) == 1) loadsw = 1;&#10; else loadsw = 0;&#10; break;&#10; case 6:&#10; if(atoi(token) == 1) dumpsw = 1;&#10; else dumpsw = 0;&#10; break;&#10; case 7:&#10; if(atoi(token) == 1) gensw = 1;&#10; else gensw = 0;&#10; break;&#10; }&#10;&#10; tokencounter++;&#10; token = strtok(NULL, &quot;,&quot;);&#10; }&#10;#ifdef DEBUG&#10; pretty_print_all_values();&#10;#endif&#10;&#10; }&#10;}&#10;&#10;void work_uart(){&#10; unsigned int c = uart_getc();&#10;&#10; if ( !(c &amp; UART_NO_DATA) ) {&#10;&#10; data_in[data_count] = c;&#10;&#10; if (data_in[data_count] == 'B') { // finish reading when newline is received&#10; data_count = 0;&#10;&#10; memcpy(command_in, data_in, BUFSIZE);&#10;&#10; // Now clear data_in, the UART can reuse it now&#10; memset(data_in, 0, BUFSIZE);&#10;&#10; process_command();&#10; } else {&#10; data_count++;&#10; }&#10; }&#10;}&#10;&#10;&#10;&#10;&#10;int main(void) {&#10;&#9;ports_init();&#10;&#9;timer_init();&#10; uart_init(UART_BAUD_SELECT(19200,F_CPU));&#10; memset(data_in, 0, BUFSIZE);&#10;&#10;&#9;while(1) {&#10;&#10;&#9; work_uart();&#10;&#10; if(syscounter &gt;= 200) {&#10; uart_putc('a'); // send a to receive values&#10;&#10; print_sevenseg(0, power_gen);&#10; print_sevenseg(1, power_load);&#10;&#10; syscounter = 0;&#10; }&#10;&#9;}&#10;&#9;&#10;&#9;return(0);&#10;}&#10;&#10;// system timer&#10;SIGNAL(TIMER1_COMPA_vect) {&#10;&#9;syscounter++;&#10;&#10;&#9;// output to sevensegment and leds&#10;&#9;// make this here to reduce display flicker&#10; digit++;&#10; if(digit &gt;5) digit = 0;&#10; leddigit++;&#10; if(leddigit &gt;3) leddigit = 0;&#10;&#10; SEVENSEG_PORT = digitbuffer[digit];&#10; SEVENSEGDIG_PORT = _BV(digit+DIG0);&#10;&#10; LED_PORT = leddigitbuffer[leddigit];&#10; LEDDIG_PORT = _BV(leddigit);&#10;}#0;n#volatile uint8_t digitbuffer[6] = { 0,0,0,0,0,0 };&#10;volatile uint8_t leddigitbuffer[4] = { 0,0,0,0 };&#10;uint8_t digit = 0;&#10;uint8_t leddigit = 0;&#10;&#10;// values send over uart from powerboard&#10;uint16_t voltage = 0;&#10;int16_t current_in = 0;&#10;int16_t current_out = 0;&#10;uint8_t dumpsw = 0; //TODO: make bitfield&#10;uint8_t loadsw = 0; //TODO: make bitfield&#10;uint8_t gensw = 0; //TODO: make bitfield&#10;&#10;uint16_t power_gen = 0;&#10;uint16_t power_load = 0;&#10;&#10;unsigned char data_count = 0;&#10;unsigned char data_in[BUFSIZE];&#10;char command_in[BUFSIZE];&#10;&#10;const uint8_t digit_translate[10] = {&#10; 63, 6, 91, 79, 102, 109, 125, 7, 127, 111&#10;};&#10;&#10;&#10;static void timer_init(void) {&#10;&#9;// clock is 8MHz&#10;&#9;TCCR1B |= _BV(WGM12) | _BV(CS11) | _BV(CS10) ; // CTC Mode for Timer 1 (16Bit) with prescale of 64&#10;&#9;OCR1A = 250; // 500Hz&#10;&#9;TIMSK = _BV(OCIE1A);&#10;&#9;sei();&#9;// enable interrupts&#10;}&#10;&#10;static void ports_init(void) {&#10; // make column / digit driver pins to output&#10; LEDDIG_DDR |= _BV(LEDS_MID1) | _BV(LEDS_MID2) | _BV(LEDS_LOAD) | _BV(LEDS_GEN);&#10; SEVENSEGDIG_DDR |= _BV(DIG0) | _BV(DIG1) | _BV(DIG2) | _BV(DIG3) | _BV(DIG4) | _BV(DIG5);&#10;&#10; // make data ports to output&#10; LED_DDR = 0xff;&#10; SEVENSEG_DDR = 0xff;&#10;&#10; SEVENSEGDIG_PORT = 0;&#10; SEVENSEG_PORT = 0;&#10;&#10; LEDDIG_PORT = 0;&#10; LED_PORT = 0;&#10;}&#10;&#10;static void print_sevenseg(uint8_t display, uint16_t value) {&#10; uint8_t d[3];&#10; d[2] = (value % 1000 / 100 );&#10; d[1] = (value % 100 / 10 );&#10; d[0] = (value % 10);&#10;&#10; if(display == 0) {&#10; for(uint8_t i = 0; i&lt; 3; i++) {&#10; digitbuffer[i] = digit_translate[d[i]];&#10; }&#10; } else {&#10; for(uint8_t i = 0; i&lt; 3; i++) {&#10; digitbuffer[i+3] = digit_translate[d[i]];&#10; }&#10; }&#10;}&#10;&#10;#ifdef DEBUG&#10;void pretty_print_all_values(void) {&#10; uart_puts_P(&quot;Voltage: &quot;);&#10; uart_print_uint16(voltage);&#10; uart_puts_P(&quot;mV\r\n&quot;);&#10;&#10; uart_puts_P(&quot;Load: &quot;);&#10; uart_print_uint16(current_out);&#10; uart_puts_P(&quot;mA &quot;);&#10; uart_print_uint16( power_load);&#10; uart_puts_P(&quot;W\r\n&quot;);&#10;&#10; uart_puts_P(&quot;Generator: &quot;);&#10; uart_print_uint16(current_in);&#10; uart_puts_P(&quot;mA &quot;);&#10; uart_print_uint16( power_gen);&#10; uart_puts_P(&quot;W\r\n&quot;);&#10;&#10; uart_puts_P(&quot;switches (load, dump, gen): &quot;);&#10; uart_putc(48 + loadsw);&#10; uart_putc(',');&#10; uart_putc(48 + dumpsw);&#10; uart_putc(',');&#10; uart_putc(48 + gensw);&#10; uart_puts_P(&quot;\r\n&quot;);&#10;}&#10;#endif&#10;&#10;void process_command() {&#10; if(strstr(command_in,&quot;A&quot;) != NULL) {&#10; // we have an A and B (from check in work_uart()&#10; // so our message should be complete and consist of:&#10; // A$voltage,$current_in,$current_out,$power_in,$power_out,loadsw,dumpsw,gensw\n&#10;&#10; //A12.5,65464,00000,00000,00000,1,0,1B&#10;&#10; char *token;&#10; uint8_t tokencounter = 0;&#10;&#10; char *start = strrchr(command_in, 'A');&#10;&#10; // remove first (B is ignored by atoi)&#10; start++;&#10;&#10;#ifdef DEBUG&#10; uart_puts_P(&quot;from start: &quot;);&#10; uart_puts(start);&#10; uart_puts_P(&quot;\r\n&quot;);&#10;#endif&#10;&#10; token = strtok(start, &quot;,&quot;);&#10;&#10; while( token ) {&#10;#ifdef DEBUG&#10; uart_puts_P(&quot;token= &quot;);&#10; uart_puts(token);&#10; uart_puts_P(&quot;\r\n&quot;);&#10;#endif&#10;&#10; switch(tokencounter) {&#10; case 0:&#10; voltage = atoi(token);&#10; break;&#10; case 1:&#10; current_in = atoi(token);&#10; break;&#10; case 2:&#10; current_out = atoi(token);&#10; break;&#10; case 3:&#10; power_gen = atoi(token);&#10; break;&#10; case 4:&#10; power_load = atoi(token);&#10; break;&#10; case 5:&#10; if(atoi(token) == 1) loadsw = 1;&#10; else loadsw = 0;&#10; break;&#10; case 6:&#10; if(atoi(token) == 1) dumpsw = 1;&#10; else dumpsw = 0;&#10; break;&#10; case 7:&#10; if(atoi(token) == 1) gensw = 1;&#10; else gensw = 0;&#10; break;&#10; }&#10;&#10; tokencounter++;&#10; token = strtok(NULL, &quot;,&quot;);&#10; }&#10;#ifdef DEBUG&#10; pretty_print_all_values();&#10;#endif&#10;&#10; }&#10;}&#10;&#10;void work_uart(){&#10; unsigned int c = uart_getc();&#10;&#10; if ( !(c &amp; UART_NO_DATA) ) {&#10;&#10; data_in[data_count] = c;&#10;&#10; if (data_in[data_count] == 'B') { // finish reading when newline is received&#10; data_count = 0;&#10;&#10; memcpy(command_in, data_in, BUFSIZE);&#10;&#10; // Now clear data_in, the UART can reuse it now&#10; memset(data_in, 0, BUFSIZE);&#10;&#10; process_command();&#10; } else {&#10; data_count++;&#10; }&#10; }&#10;}&#10;&#10;&#10;&#10;&#10;int main(void) {&#10;&#9;ports_init();&#10;&#9;timer_init();&#10; uart_init(UART_BAUD_SELECT(19200,F_CPU));&#10; memset(data_in, 0, BUFSIZE);&#10;&#10;&#9;while(1) {&#10;&#10;&#9; work_uart();&#10;&#10; if(syscounter &gt;= 200) {&#10; uart_putc('a'); // send a to receive values&#10;&#10; print_sevenseg(0, power_gen);&#10; print_sevenseg(1, power_load);&#10;&#10; syscounter = 0;&#10; }&#10;&#9;}&#10;&#9;&#10;&#9;return(0);&#10;}&#10;&#10;// system timer&#10;SIGNAL(TIMER1_COMPA_vect) {&#10;&#9;syscounter++;&#10;&#10;&#9;// output to sevensegment and leds&#10;&#9;// make this here to reduce display flicker&#10; digit++;&#10; if(digit &gt;5) digit = 0;&#10; leddigit++;&#10; if(leddigit &gt;3) leddigit = 0;&#10;&#10; SEVENSEG_PORT = digitbuffer[digit];&#10; SEVENSEGDIG_PORT = _BV(digit+DIG0);&#10;&#10; LED_PORT = leddigitbuffer[leddigit];&#10; LEDDIG_PORT = _BV(leddigit);&#10;}#0" expanded="false" />
</folding>
</state>
</provider>
</entry>
</file>
<file leaf-file-name="main.c" pinned="false" current="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/powerboard/src/main.c">
<provider selected="true" editor-type-id="text-editor">
<state line="56" column="0" selection-start="1379" selection-end="2104" vertical-scroll-proportion="0.0">
<folding />
</state>
</provider>
</entry>
</file>
</leaf>
</component>
<component name="FindManager">
<FindUsagesManager>
<setting name="OPEN_NEW_TAB" value="false" />
</FindUsagesManager>
</component>
<component name="Git.Settings">
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$/../.." />
</component>
<component name="GitLogSettings">
<option name="myDateState">
<MyDateState />
</option>
</component>
<component name="IdeDocumentHistory">
<option name="changedFiles">
<list>
<option value="$PROJECT_DIR$/powerboard/src/uart.c" />
<option value="$PROJECT_DIR$/powerboard/src/asciiart.h" />
<option value="$PROJECT_DIR$/powerboard/src/adc.h" />
<option value="$PROJECT_DIR$/powerboard/src/adc.c" />
<option value="$PROJECT_DIR$/powerboard/src/uart.h" />
<option value="$PROJECT_DIR$/displayboard/src/utils.h" />
<option value="$PROJECT_DIR$/displayboard/Makefile" />
<option value="$PROJECT_DIR$/displayboard/src/main.h" />
<option value="$PROJECT_DIR$/displayboard/src/uart.h" />
<option value="$PROJECT_DIR$/powerboard/src/main.h" />
<option value="$PROJECT_DIR$/powerboard/Makefile" />
<option value="$PROJECT_DIR$/displayboard/src/uart.c" />
<option value="$PROJECT_DIR$/powerboard/src/utils.c" />
<option value="$PROJECT_DIR$/powerboard/src/utils.h" />
<option value="$PROJECT_DIR$/powerboard/src/main.c" />
<option value="$PROJECT_DIR$/displayboard/src/main.c" />
</list>
</option>
</component>
<component name="ProjectFrameBounds">
<option name="x" value="-4" />
<option name="y" value="25" />
<option name="width" value="1608" />
<option name="height" value="853" />
</component>
<component name="ProjectInspectionProfilesVisibleTreeState">
<entry key="Project Default">
<profile-state>
<expanded-state>
<State>
<id />
</State>
<State>
<id>CDI(Contexts and Dependency Injection) issues</id>
</State>
<State>
<id>GeneralJavaScript</id>
</State>
<State>
<id>JavaScript</id>
</State>
<State>
<id>Spring Model</id>
</State>
<State>
<id>Spring SecuritySpring Model</id>
</State>
</expanded-state>
<selected-state>
<State>
<id>Abstraction issues</id>
</State>
</selected-state>
</profile-state>
</entry>
</component>
<component name="ProjectLevelVcsManager" settingsEditedManually="true">
<OptionsSetting value="true" id="Add" />
<OptionsSetting value="true" id="Remove" />
<OptionsSetting value="true" id="Checkout" />
<OptionsSetting value="true" id="Update" />
<OptionsSetting value="true" id="Status" />
<OptionsSetting value="true" id="Edit" />
<ConfirmationsSetting value="0" id="Add" />
<ConfirmationsSetting value="0" id="Remove" />
</component>
<component name="ProjectReloadState">
<option name="STATE" value="0" />
</component>
<component name="ProjectView">
<navigator currentView="ProjectPane" proportions="" version="1" splitterProportion="0.5">
<flattenPackages />
<showMembers />
<showModules />
<showLibraryContents />
<hideEmptyPackages />
<abbreviatePackageNames />
<autoscrollToSource />
<autoscrollFromSource />
<sortByType />
</navigator>
<panes>
<pane id="PackagesPane" />
<pane id="ProjectPane">
<subPane>
<PATH>
<PATH_ELEMENT>
<option name="myItemId" value="bikegenerator" />
<option name="myItemType" value="com.intellij.ide.projectView.impl.nodes.ProjectViewProjectNode" />
</PATH_ELEMENT>
</PATH>
<PATH>
<PATH_ELEMENT>
<option name="myItemId" value="bikegenerator" />
<option name="myItemType" value="com.intellij.ide.projectView.impl.nodes.ProjectViewProjectNode" />
</PATH_ELEMENT>
<PATH_ELEMENT>
<option name="myItemId" value="powerboard" />
<option name="myItemType" value="com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode" />
</PATH_ELEMENT>
</PATH>
<PATH>
<PATH_ELEMENT>
<option name="myItemId" value="bikegenerator" />
<option name="myItemType" value="com.intellij.ide.projectView.impl.nodes.ProjectViewProjectNode" />
</PATH_ELEMENT>
<PATH_ELEMENT>
<option name="myItemId" value="powerboard" />
<option name="myItemType" value="com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode" />
</PATH_ELEMENT>
<PATH_ELEMENT>
<option name="myItemId" value="src" />
<option name="myItemType" value="com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode" />
</PATH_ELEMENT>
</PATH>
<PATH>
<PATH_ELEMENT>
<option name="myItemId" value="bikegenerator" />
<option name="myItemType" value="com.intellij.ide.projectView.impl.nodes.ProjectViewProjectNode" />
</PATH_ELEMENT>
<PATH_ELEMENT>
<option name="myItemId" value="displayboard" />
<option name="myItemType" value="com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode" />
</PATH_ELEMENT>
</PATH>
<PATH>
<PATH_ELEMENT>
<option name="myItemId" value="bikegenerator" />
<option name="myItemType" value="com.intellij.ide.projectView.impl.nodes.ProjectViewProjectNode" />
</PATH_ELEMENT>
<PATH_ELEMENT>
<option name="myItemId" value="displayboard" />
<option name="myItemType" value="com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode" />
</PATH_ELEMENT>
<PATH_ELEMENT>
<option name="myItemId" value="src" />
<option name="myItemType" value="com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode" />
</PATH_ELEMENT>
</PATH>
</subPane>
</pane>
<pane id="Scope" />
</panes>
</component>
<component name="PropertiesComponent">
<property name="project.structure.last.edited" value="Modules" />
<property name="GoToFile.includeJavaFiles" value="false" />
<property name="project.structure.proportion" value="0.0" />
<property name="options.splitter.main.proportions" value="0.3" />
<property name="MemberChooser.sorted" value="false" />
<property name="recentsLimit" value="5" />
<property name="options.lastSelected" value="File.Encoding" />
<property name="last_opened_file_path" value="$PROJECT_DIR$" />
<property name="project.structure.side.proportion" value="0.2" />
<property name="MemberChooser.copyJavadoc" value="false" />
<property name="GoToClass.toSaveIncludeLibraries" value="false" />
<property name="WebServerToolWindowFactoryState" value="false" />
<property name="restartRequiresConfirmation" value="true" />
<property name="MemberChooser.showClasses" value="true" />
<property name="GoToClass.includeLibraries" value="false" />
<property name="options.searchVisible" value="true" />
<property name="options.splitter.details.proportions" value="0.2" />
</component>
<component name="RecentsManager">
<key name="CopyFile.RECENT_KEYS">
<recent name="$PROJECT_DIR$/displayboard" />
</key>
<key name="MoveFile.RECENT_KEYS">
<recent name="$PROJECT_DIR$/powerboard/src" />
</key>
</component>
<component name="RunManager">
<configuration default="true" type="#org.jetbrains.idea.devkit.run.PluginConfigurationType" factoryName="Plugin">
<module name="" />
<option name="VM_PARAMETERS" value="-Xmx512m -Xms256m -XX:MaxPermSize=250m" />
<option name="PROGRAM_PARAMETERS" />
<method />
</configuration>
<configuration default="true" type="Remote" factoryName="Remote">
<option name="USE_SOCKET_TRANSPORT" value="true" />
<option name="SERVER_MODE" value="false" />
<option name="SHMEM_ADDRESS" value="javadebug" />
<option name="HOST" value="localhost" />
<option name="PORT" value="5005" />
<method />
</configuration>
<configuration default="true" type="TestNG" factoryName="TestNG">
<extension name="coverage" enabled="false" merge="false" sample_coverage="true" runner="idea" />
<module name="" />
<option name="ALTERNATIVE_JRE_PATH_ENABLED" value="false" />
<option name="ALTERNATIVE_JRE_PATH" />
<option name="SUITE_NAME" />
<option name="PACKAGE_NAME" />
<option name="MAIN_CLASS_NAME" />
<option name="METHOD_NAME" />
<option name="GROUP_NAME" />
<option name="TEST_OBJECT" value="CLASS" />
<option name="VM_PARAMETERS" value="-ea" />
<option name="PARAMETERS" />
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$" />
<option name="OUTPUT_DIRECTORY" />
<option name="ANNOTATION_TYPE" />
<option name="ENV_VARIABLES" />
<option name="PASS_PARENT_ENVS" value="true" />
<option name="TEST_SEARCH_SCOPE">
<value defaultName="moduleWithDependencies" />
</option>
<option name="USE_DEFAULT_REPORTERS" value="false" />
<option name="PROPERTIES_FILE" />
<envs />
<properties />
<listeners />
<method />
</configuration>
<configuration default="true" type="Applet" factoryName="Applet">
<module name="" />
<option name="MAIN_CLASS_NAME" />
<option name="HTML_FILE_NAME" />
<option name="HTML_USED" value="false" />
<option name="WIDTH" value="400" />
<option name="HEIGHT" value="300" />
<option name="POLICY_FILE" value="$APPLICATION_HOME_DIR$/bin/appletviewer.policy" />
<option name="VM_PARAMETERS" />
<option name="ALTERNATIVE_JRE_PATH_ENABLED" value="false" />
<option name="ALTERNATIVE_JRE_PATH" />
<method />
</configuration>
<configuration default="true" type="Application" factoryName="Application">
<extension name="coverage" enabled="false" merge="false" sample_coverage="true" runner="idea" />
<option name="MAIN_CLASS_NAME" />
<option name="VM_PARAMETERS" />
<option name="PROGRAM_PARAMETERS" />
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$" />
<option name="ALTERNATIVE_JRE_PATH_ENABLED" value="false" />
<option name="ALTERNATIVE_JRE_PATH" />
<option name="ENABLE_SWING_INSPECTOR" value="false" />
<option name="ENV_VARIABLES" />
<option name="PASS_PARENT_ENVS" value="true" />
<module name="" />
<envs />
<method />
</configuration>
<configuration default="true" type="CppRunConfigurationType" factoryName="Cpp">
<method />
</configuration>
<configuration default="true" type="JUnit" factoryName="JUnit">
<extension name="coverage" enabled="false" merge="false" sample_coverage="true" runner="idea" />
<module name="" />
<option name="ALTERNATIVE_JRE_PATH_ENABLED" value="false" />
<option name="ALTERNATIVE_JRE_PATH" />
<option name="PACKAGE_NAME" />
<option name="MAIN_CLASS_NAME" />
<option name="METHOD_NAME" />
<option name="TEST_OBJECT" value="class" />
<option name="VM_PARAMETERS" value="-ea" />
<option name="PARAMETERS" />
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$" />
<option name="ENV_VARIABLES" />
<option name="PASS_PARENT_ENVS" value="true" />
<option name="TEST_SEARCH_SCOPE">
<value defaultName="moduleWithDependencies" />
</option>
<envs />
<patterns />
<method />
</configuration>
<list size="0" />
<configuration name="&lt;template&gt;" type="WebApp" default="true" selected="false">
<Host>localhost</Host>
<Port>5050</Port>
</configuration>
</component>
<component name="ShelveChangesManager" show_recycled="false" />
<component name="SvnConfiguration" maxAnnotateRevisions="500" myUseAcceleration="nothing" myAutoUpdateAfterCommit="false" cleanupOnStartRun="false" SSL_PROTOCOLS="all">
<option name="USER" value="" />
<option name="PASSWORD" value="" />
<option name="mySSHConnectionTimeout" value="30000" />
<option name="mySSHReadTimeout" value="30000" />
<option name="LAST_MERGED_REVISION" />
<option name="MERGE_DRY_RUN" value="false" />
<option name="MERGE_DIFF_USE_ANCESTRY" value="true" />
<option name="UPDATE_LOCK_ON_DEMAND" value="false" />
<option name="IGNORE_SPACES_IN_MERGE" value="false" />
<option name="CHECK_NESTED_FOR_QUICK_MERGE" value="false" />
<option name="IGNORE_SPACES_IN_ANNOTATE" value="true" />
<option name="SHOW_MERGE_SOURCES_IN_ANNOTATE" value="true" />
<option name="FORCE_UPDATE" value="false" />
<option name="IGNORE_EXTERNALS" value="false" />
<myIsUseDefaultProxy>false</myIsUseDefaultProxy>
</component>
<component name="TaskManager">
<task active="true" id="Default" summary="Default task">
<changelist id="9fad4545-a424-4a82-86dc-76602cf3eef3" name="Default" comment="" />
<created>1370952913198</created>
<updated>1370952913198</updated>
</task>
<task id="LOCAL-00001" summary="- added 3rd party uart lib&#10;- added measurements for voltage and current">
<created>1370989849092</created>
<updated>1370989849092</updated>
</task>
<task id="LOCAL-00002" summary="added first draft of overvoltage protection by using dump load">
<created>1370994654693</created>
<updated>1370994654693</updated>
</task>
<task id="LOCAL-00003" summary="optimisations in adc code">
<created>1371043815539</created>
<updated>1371043815539</updated>
</task>
<task id="LOCAL-00004" summary="working, refactured a bit, optimised for size">
<created>1371043908804</created>
<updated>1371043908804</updated>
</task>
<task id="LOCAL-00005" summary="bugfixes, live check on avr&#10;working for now">
<created>1371075233272</created>
<updated>1371075233272</updated>
</task>
<task id="LOCAL-00006" summary="changed resistor values for 7-Seg&#10;removed lm371 due to lack of voltage">
<created>1371166480748</created>
<updated>1371166480748</updated>
</task>
<task id="LOCAL-00007" summary="changed counter (bugfix)&#10;changed baudrate to 19200">
<created>1371166541841</created>
<updated>1371166541841</updated>
</task>
<task id="LOCAL-00008" summary="made a first version with 7-seg number output">
<created>1371166559819</created>
<updated>1371166559819</updated>
</task>
<task id="LOCAL-00009" summary="minor changes, made counters 8bit">
<created>1371206855146</created>
<updated>1371206855146</updated>
</task>
<task id="LOCAL-00010" summary="changed power to 16bit&#10;added output of relais states">
<created>1371214968413</created>
<updated>1371214968413</updated>
</task>
<task id="LOCAL-00011" summary="removed unnecessary uart1 code">
<created>1371215016953</created>
<updated>1371215016953</updated>
</task>
<task id="LOCAL-00012" summary="began working on actual code for parsing values from uart&#10;not working yet!">
<created>1371215050508</created>
<updated>1371215050508</updated>
</task>
<task id="LOCAL-00013" summary="changed currents to unsigned int and checked while getting these values.">
<created>1371242761894</created>
<updated>1371242761894</updated>
</task>
<option name="localTasksCounter" value="14" />
<servers />
</component>
<component name="ToolWindowManager">
<frame x="-4" y="25" width="1608" height="853" extended-state="6" />
<editor active="false" />
<layout>
<window_info id="Changes" active="true" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" weight="0.3252841" sideWeight="0.5" order="11" side_tool="false" content_ui="tabs" />
<window_info id="Palette" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" sideWeight="0.5" order="3" side_tool="false" content_ui="tabs" />
<window_info id="Ant Build" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.25" sideWeight="0.5" order="1" side_tool="false" content_ui="tabs" />
<window_info id="Database" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" sideWeight="0.5" order="6" side_tool="false" content_ui="tabs" />
<window_info id="Debug" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.4" sideWeight="0.5" order="4" side_tool="false" content_ui="tabs" />
<window_info id="Event Log" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.32893288" sideWeight="0.5" order="8" side_tool="true" content_ui="tabs" />
<window_info id="Favorites" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" sideWeight="0.5" order="2" side_tool="true" content_ui="tabs" />
<window_info id="Version Control" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" sideWeight="0.5" order="9" side_tool="false" content_ui="tabs" />
<window_info id="Messages" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.32893288" sideWeight="0.5" order="0" side_tool="false" content_ui="tabs" />
<window_info id="CDI" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" sideWeight="0.5" order="4" side_tool="false" content_ui="tabs" />
<window_info id="TODO" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" sideWeight="0.5" order="7" side_tool="false" content_ui="tabs" />
<window_info id="Structure" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.25" sideWeight="0.5" order="1" side_tool="false" content_ui="tabs" />
<window_info id="Maven Projects" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" sideWeight="0.5" order="5" side_tool="false" content_ui="tabs" />
<window_info id="Commander" active="false" anchor="right" auto_hide="false" internal_type="SLIDING" type="SLIDING" visible="false" weight="0.4" sideWeight="0.5" order="0" side_tool="false" content_ui="tabs" />
<window_info id="Application Servers" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" sideWeight="0.5" order="10" side_tool="false" content_ui="tabs" />
<window_info id="Project" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" weight="0.3011583" sideWeight="0.67471594" order="0" side_tool="false" content_ui="combo" />
<window_info id="Run" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" sideWeight="0.5" order="3" side_tool="false" content_ui="tabs" />
<window_info id="Cvs" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.25" sideWeight="0.5" order="5" side_tool="false" content_ui="tabs" />
<window_info id="Message" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" sideWeight="0.5" order="1" side_tool="false" content_ui="tabs" />
<window_info id="Find" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" sideWeight="0.5" order="2" side_tool="false" content_ui="tabs" />
<window_info id="Hierarchy" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.25" sideWeight="0.5" order="2" side_tool="false" content_ui="combo" />
<window_info id="Inspection" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.4" sideWeight="0.5" order="6" side_tool="false" content_ui="tabs" />
</layout>
</component>
<component name="VcsContentAnnotationSettings">
<option name="myLimit" value="2678400000" />
</component>
<component name="VcsManagerConfiguration">
<option name="OFFER_MOVE_TO_ANOTHER_CHANGELIST_ON_PARTIAL_COMMIT" value="true" />
<option name="CHECK_CODE_SMELLS_BEFORE_PROJECT_COMMIT" value="false" />
<option name="CHECK_NEW_TODO" value="false" />
<option name="myTodoPanelSettings">
<value>
<are-packages-shown value="false" />
<are-modules-shown value="false" />
<flatten-packages value="false" />
<is-autoscroll-to-source value="false" />
</value>
</option>
<option name="PERFORM_UPDATE_IN_BACKGROUND" value="true" />
<option name="PERFORM_COMMIT_IN_BACKGROUND" value="true" />
<option name="PERFORM_EDIT_IN_BACKGROUND" value="true" />
<option name="PERFORM_CHECKOUT_IN_BACKGROUND" value="true" />
<option name="PERFORM_ADD_REMOVE_IN_BACKGROUND" value="true" />
<option name="PERFORM_ROLLBACK_IN_BACKGROUND" value="false" />
<option name="CHECK_LOCALLY_CHANGED_CONFLICTS_IN_BACKGROUND" value="false" />
<option name="CHANGED_ON_SERVER_INTERVAL" value="60" />
<option name="SHOW_ONLY_CHANGED_IN_SELECTION_DIFF" value="true" />
<option name="CHECK_COMMIT_MESSAGE_SPELLING" value="true" />
<option name="DEFAULT_PATCH_EXTENSION" value="patch" />
<option name="SHORT_DIFF_HORIZONTALLY" value="true" />
<option name="SHORT_DIFF_EXTRA_LINES" value="2" />
<option name="SOFT_WRAPS_IN_SHORT_DIFF" value="true" />
<option name="INCLUDE_TEXT_INTO_PATCH" value="false" />
<option name="INCLUDE_TEXT_INTO_SHELF" value="false" />
<option name="SHOW_FILE_HISTORY_DETAILS" value="true" />
<option name="SHOW_VCS_ERROR_NOTIFICATIONS" value="true" />
<option name="SHOW_DIRTY_RECURSIVELY" value="false" />
<option name="LIMIT_HISTORY" value="true" />
<option name="MAXIMUM_HISTORY_ROWS" value="1000" />
<option name="UPDATE_FILTER_SCOPE_NAME" />
<option name="USE_COMMIT_MESSAGE_MARGIN" value="false" />
<option name="COMMIT_MESSAGE_MARGIN_SIZE" value="72" />
<option name="WRAP_WHEN_TYPING_REACHES_RIGHT_MARGIN" value="false" />
<option name="FORCE_NON_EMPTY_COMMENT" value="false" />
<option name="CLEAR_INITIAL_COMMIT_MESSAGE" value="false" />
<option name="LAST_COMMIT_MESSAGE" value="changed currents to unsigned int and checked while getting these values." />
<option name="MAKE_NEW_CHANGELIST_ACTIVE" value="false" />
<option name="OPTIMIZE_IMPORTS_BEFORE_PROJECT_COMMIT" value="false" />
<option name="CHECK_FILES_UP_TO_DATE_BEFORE_COMMIT" value="false" />
<option name="REFORMAT_BEFORE_PROJECT_COMMIT" value="false" />
<option name="REFORMAT_BEFORE_FILE_COMMIT" value="false" />
<option name="FILE_HISTORY_DIALOG_COMMENTS_SPLITTER_PROPORTION" value="0.8" />
<option name="FILE_HISTORY_DIALOG_SPLITTER_PROPORTION" value="0.5" />
<option name="ACTIVE_VCS_NAME" />
<option name="UPDATE_GROUP_BY_PACKAGES" value="false" />
<option name="UPDATE_GROUP_BY_CHANGELIST" value="false" />
<option name="UPDATE_FILTER_BY_SCOPE" value="false" />
<option name="SHOW_FILE_HISTORY_AS_TREE" value="false" />
<option name="FILE_HISTORY_SPLITTER_PROPORTION" value="0.6" />
<MESSAGE value="- added 3rd party uart lib&#10;- added measurements for voltage and current" />
<MESSAGE value="added first draft of overvoltage protection by using dump load" />
<MESSAGE value="optimisations in adc code" />
<MESSAGE value="working, refactured a bit, optimised for size" />
<MESSAGE value="bugfixes, live check on avr&#10;working for now" />
<MESSAGE value="changed resistor values for 7-Seg&#10;removed lm371 due to lack of voltage" />
<MESSAGE value="changed counter (bugfix)&#10;changed baudrate to 19200" />
<MESSAGE value="made a first version with 7-seg number output" />
<MESSAGE value="minor changes, made counters 8bit" />
<MESSAGE value="changed power to 16bit&#10;added output of relais states" />
<MESSAGE value="removed unnecessary uart1 code" />
<MESSAGE value="began working on actual code for parsing values from uart&#10;not working yet!" />
<MESSAGE value="changed currents to unsigned int and checked while getting these values." />
</component>
<component name="XDebuggerManager">
<breakpoint-manager />
</component>
<component name="antWorkspaceConfiguration">
<option name="IS_AUTOSCROLL_TO_SOURCE" value="false" />
<option name="FILTER_TARGETS" value="false" />
</component>
<component name="editorHistoryManager">
<entry file="file://$PROJECT_DIR$/powerboard/src/adc.c">
<provider selected="true" editor-type-id="text-editor">
<state line="8" column="39" selection-start="169" selection-end="169" vertical-scroll-proportion="0.1843318" />
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/powerboard/src/adc.h">
<provider selected="true" editor-type-id="text-editor">
<state line="4" column="11" selection-start="73" selection-end="73" vertical-scroll-proportion="0.0921659" />
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/powerboard/src/uart.c">
<provider selected="true" editor-type-id="text-editor">
<state line="80" column="76" selection-start="2948" selection-end="2948" vertical-scroll-proportion="-1.9201807" />
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/powerboard/src/uart.h">
<provider selected="true" editor-type-id="text-editor">
<state line="176" column="0" selection-start="6326" selection-end="6326" vertical-scroll-proportion="0.7784343" />
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/displayboard/src/utils.h">
<provider selected="true" editor-type-id="text-editor">
<state line="4" column="45" selection-start="71" selection-end="112" vertical-scroll-proportion="0.08836524" />
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/displayboard/src/utils.c">
<provider selected="true" editor-type-id="text-editor">
<state line="30" column="22" selection-start="656" selection-end="673" vertical-scroll-proportion="0.66273934" />
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/powerboard/Makefile">
<provider selected="true" editor-type-id="text-editor">
<state line="62" column="28" selection-start="1637" selection-end="1637" vertical-scroll-proportion="0.33407572" />
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/powerboard/src/main.h">
<provider selected="true" editor-type-id="text-editor">
<state line="23" column="31" selection-start="648" selection-end="648" vertical-scroll-proportion="0.66592425">
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/displayboard/Makefile">
<provider selected="true" editor-type-id="text-editor">
<state line="21" column="22" selection-start="465" selection-end="465" vertical-scroll-proportion="-0.70469797" />
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/displayboard/src/uart.h">
<provider selected="true" editor-type-id="text-editor">
<state line="141" column="11" selection-start="5298" selection-end="5298" vertical-scroll-proportion="-0.40939596" />
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/powerboard/src/utils.h">
<provider selected="true" editor-type-id="text-editor">
<state line="5" column="44" selection-start="154" selection-end="154" vertical-scroll-proportion="0.110456556">
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/powerboard/src/utils.c">
<provider selected="true" editor-type-id="text-editor">
<state line="26" column="0" selection-start="548" selection-end="548" vertical-scroll-proportion="0.5743741">
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/displayboard/src/main.h">
<provider selected="true" editor-type-id="text-editor">
<state line="6" column="20" selection-start="117" selection-end="125" vertical-scroll-proportion="0.13254787">
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/displayboard/src/uart.c">
<provider selected="true" editor-type-id="text-editor">
<state line="479" column="0" selection-start="15703" selection-end="15703" vertical-scroll-proportion="1.5405406">
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/powerboard/src/main.c">
<provider selected="true" editor-type-id="text-editor">
<state line="56" column="0" selection-start="1379" selection-end="2104" vertical-scroll-proportion="0.0">
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/displayboard/src/main.c">
<provider selected="true" editor-type-id="text-editor">
<state line="198" column="6" selection-start="4939" selection-end="4939" vertical-scroll-proportion="1.4441965">
<folding>
<element signature="n#{&#10;&#9;// clock is 8MHz&#10;&#9;TCCR1B |= _BV(WGM12) | _BV(CS11) | _BV(CS10) ; // CTC Mode for Timer 1 (16Bit) with prescale of 64&#10;&#9;OCR1A = 250; // 500Hz&#10;&#9;TIMSK = _BV(OCIE1A);&#10;&#9;sei();&#9;// enable interrupts&#10;}#0;n#static void timer_init(void) {&#10;&#9;// clock is 8MHz&#10;&#9;TCCR1B |= _BV(WGM12) | _BV(CS11) | _BV(CS10) ; // CTC Mode for Timer 1 (16Bit) with prescale of 64&#10;&#9;OCR1A = 250; // 500Hz&#10;&#9;TIMSK = _BV(OCIE1A);&#10;&#9;sei();&#9;// enable interrupts&#10;}#0;n#const uint8_t digit_translate[10] = {&#10; 63, 6, 91, 79, 102, 109, 125, 7, 127, 111&#10;};&#10;&#10;&#10;static void timer_init(void) {&#10;&#9;// clock is 8MHz&#10;&#9;TCCR1B |= _BV(WGM12) | _BV(CS11) | _BV(CS10) ; // CTC Mode for Timer 1 (16Bit) with prescale of 64&#10;&#9;OCR1A = 250; // 500Hz&#10;&#9;TIMSK = _BV(OCIE1A);&#10;&#9;sei();&#9;// enable interrupts&#10;}&#10;&#10;static void ports_init(void) {&#10; // make column / digit driver pins to output&#10; LEDDIG_DDR |= _BV(LEDS_MID1) | _BV(LEDS_MID2) | _BV(LEDS_LOAD) | _BV(LEDS_GEN);&#10; SEVENSEGDIG_DDR |= _BV(DIG0) | _BV(DIG1) | _BV(DIG2) | _BV(DIG3) | _BV(DIG4) | _BV(DIG5);&#10;&#10; // make data ports to output&#10; LED_DDR = 0xff;&#10; SEVENSEG_DDR = 0xff;&#10;&#10; SEVENSEGDIG_PORT = 0;&#10; SEVENSEG_PORT = 0;&#10;&#10; LEDDIG_PORT = 0;&#10; LED_PORT = 0;&#10;}&#10;&#10;static void print_sevenseg(uint8_t display, uint16_t value) {&#10; uint8_t d[3];&#10; d[2] = (value % 1000 / 100 );&#10; d[1] = (value % 100 / 10 );&#10; d[0] = (value % 10);&#10;&#10; if(display == 0) {&#10; for(uint8_t i = 0; i&lt; 3; i++) {&#10; digitbuffer[i] = digit_translate[d[i]];&#10; }&#10; } else {&#10; for(uint8_t i = 0; i&lt; 3; i++) {&#10; digitbuffer[i+3] = digit_translate[d[i]];&#10; }&#10; }&#10;}&#10;&#10;#ifdef DEBUG&#10;void pretty_print_all_values(void) {&#10; uart_puts_P(&quot;Voltage: &quot;);&#10; uart_print_uint16(voltage);&#10; uart_puts_P(&quot;mV\r\n&quot;);&#10;&#10; uart_puts_P(&quot;Load: &quot;);&#10; uart_print_uint16(current_out);&#10; uart_puts_P(&quot;mA &quot;);&#10; uart_print_uint16( power_load);&#10; uart_puts_P(&quot;W\r\n&quot;);&#10;&#10; uart_puts_P(&quot;Generator: &quot;);&#10; uart_print_uint16(current_in);&#10; uart_puts_P(&quot;mA &quot;);&#10; uart_print_uint16( power_gen);&#10; uart_puts_P(&quot;W\r\n&quot;);&#10;&#10; uart_puts_P(&quot;switches (load, dump, gen): &quot;);&#10; uart_putc(48 + loadsw);&#10; uart_putc(',');&#10; uart_putc(48 + dumpsw);&#10; uart_putc(',');&#10; uart_putc(48 + gensw);&#10; uart_puts_P(&quot;\r\n&quot;);&#10;}&#10;#endif&#10;&#10;void process_command() {&#10; if(strstr(command_in,&quot;A&quot;) != NULL) {&#10; // we have an A and B (from check in work_uart()&#10; // so our message should be complete and consist of:&#10; // A$voltage,$current_in,$current_out,$power_in,$power_out,loadsw,dumpsw,gensw\n&#10;&#10; //A12.5,65464,00000,00000,00000,1,0,1B&#10;&#10; char *token;&#10; uint8_t tokencounter = 0;&#10;&#10; char *start = strrchr(command_in, 'A');&#10;&#10; // remove first (B is ignored by atoi)&#10; start++;&#10;&#10;#ifdef DEBUG&#10; uart_puts_P(&quot;from start: &quot;);&#10; uart_puts(start);&#10; uart_puts_P(&quot;\r\n&quot;);&#10;#endif&#10;&#10; token = strtok(start, &quot;,&quot;);&#10;&#10; while( token ) {&#10;#ifdef DEBUG&#10; uart_puts_P(&quot;token= &quot;);&#10; uart_puts(token);&#10; uart_puts_P(&quot;\r\n&quot;);&#10;#endif&#10;&#10; switch(tokencounter) {&#10; case 0:&#10; voltage = atoi(token);&#10; break;&#10; case 1:&#10; current_in = atoi(token);&#10; break;&#10; case 2:&#10; current_out = atoi(token);&#10; break;&#10; case 3:&#10; power_gen = atoi(token);&#10; break;&#10; case 4:&#10; power_load = atoi(token);&#10; break;&#10; case 5:&#10; if(atoi(token) == 1) loadsw = 1;&#10; else loadsw = 0;&#10; break;&#10; case 6:&#10; if(atoi(token) == 1) dumpsw = 1;&#10; else dumpsw = 0;&#10; break;&#10; case 7:&#10; if(atoi(token) == 1) gensw = 1;&#10; else gensw = 0;&#10; break;&#10; }&#10;&#10; tokencounter++;&#10; token = strtok(NULL, &quot;,&quot;);&#10; }&#10;#ifdef DEBUG&#10; pretty_print_all_values();&#10;#endif&#10;&#10; }&#10;}&#10;&#10;void work_uart(){&#10; unsigned int c = uart_getc();&#10;&#10; if ( !(c &amp; UART_NO_DATA) ) {&#10;&#10; data_in[data_count] = c;&#10;&#10; if (data_in[data_count] == 'B') { // finish reading when newline is received&#10; data_count = 0;&#10;&#10; memcpy(command_in, data_in, BUFSIZE);&#10;&#10; // Now clear data_in, the UART can reuse it now&#10; memset(data_in, 0, BUFSIZE);&#10;&#10; process_command();&#10; } else {&#10; data_count++;&#10; }&#10; }&#10;}&#10;&#10;&#10;&#10;&#10;int main(void) {&#10;&#9;ports_init();&#10;&#9;timer_init();&#10; uart_init(UART_BAUD_SELECT(19200,F_CPU));&#10; memset(data_in, 0, BUFSIZE);&#10;&#10;&#9;while(1) {&#10;&#10;&#9; work_uart();&#10;&#10; if(syscounter &gt;= 200) {&#10; uart_putc('a'); // send a to receive values&#10;&#10; print_sevenseg(0, power_gen);&#10; print_sevenseg(1, power_load);&#10;&#10; syscounter = 0;&#10; }&#10;&#9;}&#10;&#9;&#10;&#9;return(0);&#10;}&#10;&#10;// system timer&#10;SIGNAL(TIMER1_COMPA_vect) {&#10;&#9;syscounter++;&#10;&#10;&#9;// output to sevensegment and leds&#10;&#9;// make this here to reduce display flicker&#10; digit++;&#10; if(digit &gt;5) digit = 0;&#10; leddigit++;&#10; if(leddigit &gt;3) leddigit = 0;&#10;&#10; SEVENSEG_PORT = digitbuffer[digit];&#10; SEVENSEGDIG_PORT = _BV(digit+DIG0);&#10;&#10; LED_PORT = leddigitbuffer[leddigit];&#10; LEDDIG_PORT = _BV(leddigit);&#10;}#0;n#volatile uint8_t leddigitbuffer[4] = { 0,0,0,0 };&#10;uint8_t digit = 0;&#10;uint8_t leddigit = 0;&#10;&#10;// values send over uart from powerboard&#10;uint16_t voltage = 0;&#10;int16_t current_in = 0;&#10;int16_t current_out = 0;&#10;uint8_t dumpsw = 0; //TODO: make bitfield&#10;uint8_t loadsw = 0; //TODO: make bitfield&#10;uint8_t gensw = 0; //TODO: make bitfield&#10;&#10;uint16_t power_gen = 0;&#10;uint16_t power_load = 0;&#10;&#10;unsigned char data_count = 0;&#10;unsigned char data_in[BUFSIZE];&#10;char command_in[BUFSIZE];&#10;&#10;const uint8_t digit_translate[10] = {&#10; 63, 6, 91, 79, 102, 109, 125, 7, 127, 111&#10;};&#10;&#10;&#10;static void timer_init(void) {&#10;&#9;// clock is 8MHz&#10;&#9;TCCR1B |= _BV(WGM12) | _BV(CS11) | _BV(CS10) ; // CTC Mode for Timer 1 (16Bit) with prescale of 64&#10;&#9;OCR1A = 250; // 500Hz&#10;&#9;TIMSK = _BV(OCIE1A);&#10;&#9;sei();&#9;// enable interrupts&#10;}&#10;&#10;static void ports_init(void) {&#10; // make column / digit driver pins to output&#10; LEDDIG_DDR |= _BV(LEDS_MID1) | _BV(LEDS_MID2) | _BV(LEDS_LOAD) | _BV(LEDS_GEN);&#10; SEVENSEGDIG_DDR |= _BV(DIG0) | _BV(DIG1) | _BV(DIG2) | _BV(DIG3) | _BV(DIG4) | _BV(DIG5);&#10;&#10; // make data ports to output&#10; LED_DDR = 0xff;&#10; SEVENSEG_DDR = 0xff;&#10;&#10; SEVENSEGDIG_PORT = 0;&#10; SEVENSEG_PORT = 0;&#10;&#10; LEDDIG_PORT = 0;&#10; LED_PORT = 0;&#10;}&#10;&#10;static void print_sevenseg(uint8_t display, uint16_t value) {&#10; uint8_t d[3];&#10; d[2] = (value % 1000 / 100 );&#10; d[1] = (value % 100 / 10 );&#10; d[0] = (value % 10);&#10;&#10; if(display == 0) {&#10; for(uint8_t i = 0; i&lt; 3; i++) {&#10; digitbuffer[i] = digit_translate[d[i]];&#10; }&#10; } else {&#10; for(uint8_t i = 0; i&lt; 3; i++) {&#10; digitbuffer[i+3] = digit_translate[d[i]];&#10; }&#10; }&#10;}&#10;&#10;#ifdef DEBUG&#10;void pretty_print_all_values(void) {&#10; uart_puts_P(&quot;Voltage: &quot;);&#10; uart_print_uint16(voltage);&#10; uart_puts_P(&quot;mV\r\n&quot;);&#10;&#10; uart_puts_P(&quot;Load: &quot;);&#10; uart_print_uint16(current_out);&#10; uart_puts_P(&quot;mA &quot;);&#10; uart_print_uint16( power_load);&#10; uart_puts_P(&quot;W\r\n&quot;);&#10;&#10; uart_puts_P(&quot;Generator: &quot;);&#10; uart_print_uint16(current_in);&#10; uart_puts_P(&quot;mA &quot;);&#10; uart_print_uint16( power_gen);&#10; uart_puts_P(&quot;W\r\n&quot;);&#10;&#10; uart_puts_P(&quot;switches (load, dump, gen): &quot;);&#10; uart_putc(48 + loadsw);&#10; uart_putc(',');&#10; uart_putc(48 + dumpsw);&#10; uart_putc(',');&#10; uart_putc(48 + gensw);&#10; uart_puts_P(&quot;\r\n&quot;);&#10;}&#10;#endif&#10;&#10;void process_command() {&#10; if(strstr(command_in,&quot;A&quot;) != NULL) {&#10; // we have an A and B (from check in work_uart()&#10; // so our message should be complete and consist of:&#10; // A$voltage,$current_in,$current_out,$power_in,$power_out,loadsw,dumpsw,gensw\n&#10;&#10; //A12.5,65464,00000,00000,00000,1,0,1B&#10;&#10; char *token;&#10; uint8_t tokencounter = 0;&#10;&#10; char *start = strrchr(command_in, 'A');&#10;&#10; // remove first (B is ignored by atoi)&#10; start++;&#10;&#10;#ifdef DEBUG&#10; uart_puts_P(&quot;from start: &quot;);&#10; uart_puts(start);&#10; uart_puts_P(&quot;\r\n&quot;);&#10;#endif&#10;&#10; token = strtok(start, &quot;,&quot;);&#10;&#10; while( token ) {&#10;#ifdef DEBUG&#10; uart_puts_P(&quot;token= &quot;);&#10; uart_puts(token);&#10; uart_puts_P(&quot;\r\n&quot;);&#10;#endif&#10;&#10; switch(tokencounter) {&#10; case 0:&#10; voltage = atoi(token);&#10; break;&#10; case 1:&#10; current_in = atoi(token);&#10; break;&#10; case 2:&#10; current_out = atoi(token);&#10; break;&#10; case 3:&#10; power_gen = atoi(token);&#10; break;&#10; case 4:&#10; power_load = atoi(token);&#10; break;&#10; case 5:&#10; if(atoi(token) == 1) loadsw = 1;&#10; else loadsw = 0;&#10; break;&#10; case 6:&#10; if(atoi(token) == 1) dumpsw = 1;&#10; else dumpsw = 0;&#10; break;&#10; case 7:&#10; if(atoi(token) == 1) gensw = 1;&#10; else gensw = 0;&#10; break;&#10; }&#10;&#10; tokencounter++;&#10; token = strtok(NULL, &quot;,&quot;);&#10; }&#10;#ifdef DEBUG&#10; pretty_print_all_values();&#10;#endif&#10;&#10; }&#10;}&#10;&#10;void work_uart(){&#10; unsigned int c = uart_getc();&#10;&#10; if ( !(c &amp; UART_NO_DATA) ) {&#10;&#10; data_in[data_count] = c;&#10;&#10; if (data_in[data_count] == 'B') { // finish reading when newline is received&#10; data_count = 0;&#10;&#10; memcpy(command_in, data_in, BUFSIZE);&#10;&#10; // Now clear data_in, the UART can reuse it now&#10; memset(data_in, 0, BUFSIZE);&#10;&#10; process_command();&#10; } else {&#10; data_count++;&#10; }&#10; }&#10;}&#10;&#10;&#10;&#10;&#10;int main(void) {&#10;&#9;ports_init();&#10;&#9;timer_init();&#10; uart_init(UART_BAUD_SELECT(19200,F_CPU));&#10; memset(data_in, 0, BUFSIZE);&#10;&#10;&#9;while(1) {&#10;&#10;&#9; work_uart();&#10;&#10; if(syscounter &gt;= 200) {&#10; uart_putc('a'); // send a to receive values&#10;&#10; print_sevenseg(0, power_gen);&#10; print_sevenseg(1, power_load);&#10;&#10; syscounter = 0;&#10; }&#10;&#9;}&#10;&#9;&#10;&#9;return(0);&#10;}&#10;&#10;// system timer&#10;SIGNAL(TIMER1_COMPA_vect) {&#10;&#9;syscounter++;&#10;&#10;&#9;// output to sevensegment and leds&#10;&#9;// make this here to reduce display flicker&#10; digit++;&#10; if(digit &gt;5) digit = 0;&#10; leddigit++;&#10; if(leddigit &gt;3) leddigit = 0;&#10;&#10; SEVENSEG_PORT = digitbuffer[digit];&#10; SEVENSEGDIG_PORT = _BV(digit+DIG0);&#10;&#10; LED_PORT = leddigitbuffer[leddigit];&#10; LEDDIG_PORT = _BV(leddigit);&#10;}#0;n#volatile uint8_t digitbuffer[6] = { 0,0,0,0,0,0 };&#10;volatile uint8_t leddigitbuffer[4] = { 0,0,0,0 };&#10;uint8_t digit = 0;&#10;uint8_t leddigit = 0;&#10;&#10;// values send over uart from powerboard&#10;uint16_t voltage = 0;&#10;int16_t current_in = 0;&#10;int16_t current_out = 0;&#10;uint8_t dumpsw = 0; //TODO: make bitfield&#10;uint8_t loadsw = 0; //TODO: make bitfield&#10;uint8_t gensw = 0; //TODO: make bitfield&#10;&#10;uint16_t power_gen = 0;&#10;uint16_t power_load = 0;&#10;&#10;unsigned char data_count = 0;&#10;unsigned char data_in[BUFSIZE];&#10;char command_in[BUFSIZE];&#10;&#10;const uint8_t digit_translate[10] = {&#10; 63, 6, 91, 79, 102, 109, 125, 7, 127, 111&#10;};&#10;&#10;&#10;static void timer_init(void) {&#10;&#9;// clock is 8MHz&#10;&#9;TCCR1B |= _BV(WGM12) | _BV(CS11) | _BV(CS10) ; // CTC Mode for Timer 1 (16Bit) with prescale of 64&#10;&#9;OCR1A = 250; // 500Hz&#10;&#9;TIMSK = _BV(OCIE1A);&#10;&#9;sei();&#9;// enable interrupts&#10;}&#10;&#10;static void ports_init(void) {&#10; // make column / digit driver pins to output&#10; LEDDIG_DDR |= _BV(LEDS_MID1) | _BV(LEDS_MID2) | _BV(LEDS_LOAD) | _BV(LEDS_GEN);&#10; SEVENSEGDIG_DDR |= _BV(DIG0) | _BV(DIG1) | _BV(DIG2) | _BV(DIG3) | _BV(DIG4) | _BV(DIG5);&#10;&#10; // make data ports to output&#10; LED_DDR = 0xff;&#10; SEVENSEG_DDR = 0xff;&#10;&#10; SEVENSEGDIG_PORT = 0;&#10; SEVENSEG_PORT = 0;&#10;&#10; LEDDIG_PORT = 0;&#10; LED_PORT = 0;&#10;}&#10;&#10;static void print_sevenseg(uint8_t display, uint16_t value) {&#10; uint8_t d[3];&#10; d[2] = (value % 1000 / 100 );&#10; d[1] = (value % 100 / 10 );&#10; d[0] = (value % 10);&#10;&#10; if(display == 0) {&#10; for(uint8_t i = 0; i&lt; 3; i++) {&#10; digitbuffer[i] = digit_translate[d[i]];&#10; }&#10; } else {&#10; for(uint8_t i = 0; i&lt; 3; i++) {&#10; digitbuffer[i+3] = digit_translate[d[i]];&#10; }&#10; }&#10;}&#10;&#10;#ifdef DEBUG&#10;void pretty_print_all_values(void) {&#10; uart_puts_P(&quot;Voltage: &quot;);&#10; uart_print_uint16(voltage);&#10; uart_puts_P(&quot;mV\r\n&quot;);&#10;&#10; uart_puts_P(&quot;Load: &quot;);&#10; uart_print_uint16(current_out);&#10; uart_puts_P(&quot;mA &quot;);&#10; uart_print_uint16( power_load);&#10; uart_puts_P(&quot;W\r\n&quot;);&#10;&#10; uart_puts_P(&quot;Generator: &quot;);&#10; uart_print_uint16(current_in);&#10; uart_puts_P(&quot;mA &quot;);&#10; uart_print_uint16( power_gen);&#10; uart_puts_P(&quot;W\r\n&quot;);&#10;&#10; uart_puts_P(&quot;switches (load, dump, gen): &quot;);&#10; uart_putc(48 + loadsw);&#10; uart_putc(',');&#10; uart_putc(48 + dumpsw);&#10; uart_putc(',');&#10; uart_putc(48 + gensw);&#10; uart_puts_P(&quot;\r\n&quot;);&#10;}&#10;#endif&#10;&#10;void process_command() {&#10; if(strstr(command_in,&quot;A&quot;) != NULL) {&#10; // we have an A and B (from check in work_uart()&#10; // so our message should be complete and consist of:&#10; // A$voltage,$current_in,$current_out,$power_in,$power_out,loadsw,dumpsw,gensw\n&#10;&#10; //A12.5,65464,00000,00000,00000,1,0,1B&#10;&#10; char *token;&#10; uint8_t tokencounter = 0;&#10;&#10; char *start = strrchr(command_in, 'A');&#10;&#10; // remove first (B is ignored by atoi)&#10; start++;&#10;&#10;#ifdef DEBUG&#10; uart_puts_P(&quot;from start: &quot;);&#10; uart_puts(start);&#10; uart_puts_P(&quot;\r\n&quot;);&#10;#endif&#10;&#10; token = strtok(start, &quot;,&quot;);&#10;&#10; while( token ) {&#10;#ifdef DEBUG&#10; uart_puts_P(&quot;token= &quot;);&#10; uart_puts(token);&#10; uart_puts_P(&quot;\r\n&quot;);&#10;#endif&#10;&#10; switch(tokencounter) {&#10; case 0:&#10; voltage = atoi(token);&#10; break;&#10; case 1:&#10; current_in = atoi(token);&#10; break;&#10; case 2:&#10; current_out = atoi(token);&#10; break;&#10; case 3:&#10; power_gen = atoi(token);&#10; break;&#10; case 4:&#10; power_load = atoi(token);&#10; break;&#10; case 5:&#10; if(atoi(token) == 1) loadsw = 1;&#10; else loadsw = 0;&#10; break;&#10; case 6:&#10; if(atoi(token) == 1) dumpsw = 1;&#10; else dumpsw = 0;&#10; break;&#10; case 7:&#10; if(atoi(token) == 1) gensw = 1;&#10; else gensw = 0;&#10; break;&#10; }&#10;&#10; tokencounter++;&#10; token = strtok(NULL, &quot;,&quot;);&#10; }&#10;#ifdef DEBUG&#10; pretty_print_all_values();&#10;#endif&#10;&#10; }&#10;}&#10;&#10;void work_uart(){&#10; unsigned int c = uart_getc();&#10;&#10; if ( !(c &amp; UART_NO_DATA) ) {&#10;&#10; data_in[data_count] = c;&#10;&#10; if (data_in[data_count] == 'B') { // finish reading when newline is received&#10; data_count = 0;&#10;&#10; memcpy(command_in, data_in, BUFSIZE);&#10;&#10; // Now clear data_in, the UART can reuse it now&#10; memset(data_in, 0, BUFSIZE);&#10;&#10; process_command();&#10; } else {&#10; data_count++;&#10; }&#10; }&#10;}&#10;&#10;&#10;&#10;&#10;int main(void) {&#10;&#9;ports_init();&#10;&#9;timer_init();&#10; uart_init(UART_BAUD_SELECT(19200,F_CPU));&#10; memset(data_in, 0, BUFSIZE);&#10;&#10;&#9;while(1) {&#10;&#10;&#9; work_uart();&#10;&#10; if(syscounter &gt;= 200) {&#10; uart_putc('a'); // send a to receive values&#10;&#10; print_sevenseg(0, power_gen);&#10; print_sevenseg(1, power_load);&#10;&#10; syscounter = 0;&#10; }&#10;&#9;}&#10;&#9;&#10;&#9;return(0);&#10;}&#10;&#10;// system timer&#10;SIGNAL(TIMER1_COMPA_vect) {&#10;&#9;syscounter++;&#10;&#10;&#9;// output to sevensegment and leds&#10;&#9;// make this here to reduce display flicker&#10; digit++;&#10; if(digit &gt;5) digit = 0;&#10; leddigit++;&#10; if(leddigit &gt;3) leddigit = 0;&#10;&#10; SEVENSEG_PORT = digitbuffer[digit];&#10; SEVENSEGDIG_PORT = _BV(digit+DIG0);&#10;&#10; LED_PORT = leddigitbuffer[leddigit];&#10; LEDDIG_PORT = _BV(leddigit);&#10;}#0" expanded="false" />
<element signature="n#{&#10; // make column / digit driver pins to output&#10; LEDDIG_DDR |= _BV(LEDS_MID1) | _BV(LEDS_MID2) | _BV(LEDS_LOAD) | _BV(LEDS_GEN);&#10; SEVENSEGDIG_DDR |= _BV(DIG0) | _BV(DIG1) | _BV(DIG2) | _BV(DIG3) | _BV(DIG4) | _BV(DIG5);&#10;&#10; // make data ports to output&#10; LED_DDR = 0xff;&#10; SEVENSEG_DDR = 0xff;&#10;&#10; SEVENSEGDIG_PORT = 0;&#10; SEVENSEG_PORT = 0;&#10;&#10; LEDDIG_PORT = 0;&#10; LED_PORT = 0;&#10;}#0;n#static void ports_init(void) {&#10; // make column / digit driver pins to output&#10; LEDDIG_DDR |= _BV(LEDS_MID1) | _BV(LEDS_MID2) | _BV(LEDS_LOAD) | _BV(LEDS_GEN);&#10; SEVENSEGDIG_DDR |= _BV(DIG0) | _BV(DIG1) | _BV(DIG2) | _BV(DIG3) | _BV(DIG4) | _BV(DIG5);&#10;&#10; // make data ports to output&#10; LED_DDR = 0xff;&#10; SEVENSEG_DDR = 0xff;&#10;&#10; SEVENSEGDIG_PORT = 0;&#10; SEVENSEG_PORT = 0;&#10;&#10; LEDDIG_PORT = 0;&#10; LED_PORT = 0;&#10;}#0;n#const uint8_t digit_translate[10] = {&#10; 63, 6, 91, 79, 102, 109, 125, 7, 127, 111&#10;};&#10;&#10;&#10;static void timer_init(void) {&#10;&#9;// clock is 8MHz&#10;&#9;TCCR1B |= _BV(WGM12) | _BV(CS11) | _BV(CS10) ; // CTC Mode for Timer 1 (16Bit) with prescale of 64&#10;&#9;OCR1A = 250; // 500Hz&#10;&#9;TIMSK = _BV(OCIE1A);&#10;&#9;sei();&#9;// enable interrupts&#10;}&#10;&#10;static void ports_init(void) {&#10; // make column / digit driver pins to output&#10; LEDDIG_DDR |= _BV(LEDS_MID1) | _BV(LEDS_MID2) | _BV(LEDS_LOAD) | _BV(LEDS_GEN);&#10; SEVENSEGDIG_DDR |= _BV(DIG0) | _BV(DIG1) | _BV(DIG2) | _BV(DIG3) | _BV(DIG4) | _BV(DIG5);&#10;&#10; // make data ports to output&#10; LED_DDR = 0xff;&#10; SEVENSEG_DDR = 0xff;&#10;&#10; SEVENSEGDIG_PORT = 0;&#10; SEVENSEG_PORT = 0;&#10;&#10; LEDDIG_PORT = 0;&#10; LED_PORT = 0;&#10;}&#10;&#10;static void print_sevenseg(uint8_t display, uint16_t value) {&#10; uint8_t d[3];&#10; d[2] = (value % 1000 / 100 );&#10; d[1] = (value % 100 / 10 );&#10; d[0] = (value % 10);&#10;&#10; if(display == 0) {&#10; for(uint8_t i = 0; i&lt; 3; i++) {&#10; digitbuffer[i] = digit_translate[d[i]];&#10; }&#10; } else {&#10; for(uint8_t i = 0; i&lt; 3; i++) {&#10; digitbuffer[i+3] = digit_translate[d[i]];&#10; }&#10; }&#10;}&#10;&#10;#ifdef DEBUG&#10;void pretty_print_all_values(void) {&#10; uart_puts_P(&quot;Voltage: &quot;);&#10; uart_print_uint16(voltage);&#10; uart_puts_P(&quot;mV\r\n&quot;);&#10;&#10; uart_puts_P(&quot;Load: &quot;);&#10; uart_print_uint16(current_out);&#10; uart_puts_P(&quot;mA &quot;);&#10; uart_print_uint16( power_load);&#10; uart_puts_P(&quot;W\r\n&quot;);&#10;&#10; uart_puts_P(&quot;Generator: &quot;);&#10; uart_print_uint16(current_in);&#10; uart_puts_P(&quot;mA &quot;);&#10; uart_print_uint16( power_gen);&#10; uart_puts_P(&quot;W\r\n&quot;);&#10;&#10; uart_puts_P(&quot;switches (load, dump, gen): &quot;);&#10; uart_putc(48 + loadsw);&#10; uart_putc(',');&#10; uart_putc(48 + dumpsw);&#10; uart_putc(',');&#10; uart_putc(48 + gensw);&#10; uart_puts_P(&quot;\r\n&quot;);&#10;}&#10;#endif&#10;&#10;void process_command() {&#10; if(strstr(command_in,&quot;A&quot;) != NULL) {&#10; // we have an A and B (from check in work_uart()&#10; // so our message should be complete and consist of:&#10; // A$voltage,$current_in,$current_out,$power_in,$power_out,loadsw,dumpsw,gensw\n&#10;&#10; //A12.5,65464,00000,00000,00000,1,0,1B&#10;&#10; char *token;&#10; uint8_t tokencounter = 0;&#10;&#10; char *start = strrchr(command_in, 'A');&#10;&#10; // remove first (B is ignored by atoi)&#10; start++;&#10;&#10;#ifdef DEBUG&#10; uart_puts_P(&quot;from start: &quot;);&#10; uart_puts(start);&#10; uart_puts_P(&quot;\r\n&quot;);&#10;#endif&#10;&#10; token = strtok(start, &quot;,&quot;);&#10;&#10; while( token ) {&#10;#ifdef DEBUG&#10; uart_puts_P(&quot;token= &quot;);&#10; uart_puts(token);&#10; uart_puts_P(&quot;\r\n&quot;);&#10;#endif&#10;&#10; switch(tokencounter) {&#10; case 0:&#10; voltage = atoi(token);&#10; break;&#10; case 1:&#10; current_in = atoi(token);&#10; break;&#10; case 2:&#10; current_out = atoi(token);&#10; break;&#10; case 3:&#10; power_gen = atoi(token);&#10; break;&#10; case 4:&#10; power_load = atoi(token);&#10; break;&#10; case 5:&#10; if(atoi(token) == 1) loadsw = 1;&#10; else loadsw = 0;&#10; break;&#10; case 6:&#10; if(atoi(token) == 1) dumpsw = 1;&#10; else dumpsw = 0;&#10; break;&#10; case 7:&#10; if(atoi(token) == 1) gensw = 1;&#10; else gensw = 0;&#10; break;&#10; }&#10;&#10; tokencounter++;&#10; token = strtok(NULL, &quot;,&quot;);&#10; }&#10;#ifdef DEBUG&#10; pretty_print_all_values();&#10;#endif&#10;&#10; }&#10;}&#10;&#10;void work_uart(){&#10; unsigned int c = uart_getc();&#10;&#10; if ( !(c &amp; UART_NO_DATA) ) {&#10;&#10; data_in[data_count] = c;&#10;&#10; if (data_in[data_count] == 'B') { // finish reading when newline is received&#10; data_count = 0;&#10;&#10; memcpy(command_in, data_in, BUFSIZE);&#10;&#10; // Now clear data_in, the UART can reuse it now&#10; memset(data_in, 0, BUFSIZE);&#10;&#10; process_command();&#10; } else {&#10; data_count++;&#10; }&#10; }&#10;}&#10;&#10;&#10;&#10;&#10;int main(void) {&#10;&#9;ports_init();&#10;&#9;timer_init();&#10; uart_init(UART_BAUD_SELECT(19200,F_CPU));&#10; memset(data_in, 0, BUFSIZE);&#10;&#10;&#9;while(1) {&#10;&#10;&#9; work_uart();&#10;&#10; if(syscounter &gt;= 200) {&#10; uart_putc('a'); // send a to receive values&#10;&#10; print_sevenseg(0, power_gen);&#10; print_sevenseg(1, power_load);&#10;&#10; syscounter = 0;&#10; }&#10;&#9;}&#10;&#9;&#10;&#9;return(0);&#10;}&#10;&#10;// system timer&#10;SIGNAL(TIMER1_COMPA_vect) {&#10;&#9;syscounter++;&#10;&#10;&#9;// output to sevensegment and leds&#10;&#9;// make this here to reduce display flicker&#10; digit++;&#10; if(digit &gt;5) digit = 0;&#10; leddigit++;&#10; if(leddigit &gt;3) leddigit = 0;&#10;&#10; SEVENSEG_PORT = digitbuffer[digit];&#10; SEVENSEGDIG_PORT = _BV(digit+DIG0);&#10;&#10; LED_PORT = leddigitbuffer[leddigit];&#10; LEDDIG_PORT = _BV(leddigit);&#10;}#0;n#volatile uint8_t leddigitbuffer[4] = { 0,0,0,0 };&#10;uint8_t digit = 0;&#10;uint8_t leddigit = 0;&#10;&#10;// values send over uart from powerboard&#10;uint16_t voltage = 0;&#10;int16_t current_in = 0;&#10;int16_t current_out = 0;&#10;uint8_t dumpsw = 0; //TODO: make bitfield&#10;uint8_t loadsw = 0; //TODO: make bitfield&#10;uint8_t gensw = 0; //TODO: make bitfield&#10;&#10;uint16_t power_gen = 0;&#10;uint16_t power_load = 0;&#10;&#10;unsigned char data_count = 0;&#10;unsigned char data_in[BUFSIZE];&#10;char command_in[BUFSIZE];&#10;&#10;const uint8_t digit_translate[10] = {&#10; 63, 6, 91, 79, 102, 109, 125, 7, 127, 111&#10;};&#10;&#10;&#10;static void timer_init(void) {&#10;&#9;// clock is 8MHz&#10;&#9;TCCR1B |= _BV(WGM12) | _BV(CS11) | _BV(CS10) ; // CTC Mode for Timer 1 (16Bit) with prescale of 64&#10;&#9;OCR1A = 250; // 500Hz&#10;&#9;TIMSK = _BV(OCIE1A);&#10;&#9;sei();&#9;// enable interrupts&#10;}&#10;&#10;static void ports_init(void) {&#10; // make column / digit driver pins to output&#10; LEDDIG_DDR |= _BV(LEDS_MID1) | _BV(LEDS_MID2) | _BV(LEDS_LOAD) | _BV(LEDS_GEN);&#10; SEVENSEGDIG_DDR |= _BV(DIG0) | _BV(DIG1) | _BV(DIG2) | _BV(DIG3) | _BV(DIG4) | _BV(DIG5);&#10;&#10; // make data ports to output&#10; LED_DDR = 0xff;&#10; SEVENSEG_DDR = 0xff;&#10;&#10; SEVENSEGDIG_PORT = 0;&#10; SEVENSEG_PORT = 0;&#10;&#10; LEDDIG_PORT = 0;&#10; LED_PORT = 0;&#10;}&#10;&#10;static void print_sevenseg(uint8_t display, uint16_t value) {&#10; uint8_t d[3];&#10; d[2] = (value % 1000 / 100 );&#10; d[1] = (value % 100 / 10 );&#10; d[0] = (value % 10);&#10;&#10; if(display == 0) {&#10; for(uint8_t i = 0; i&lt; 3; i++) {&#10; digitbuffer[i] = digit_translate[d[i]];&#10; }&#10; } else {&#10; for(uint8_t i = 0; i&lt; 3; i++) {&#10; digitbuffer[i+3] = digit_translate[d[i]];&#10; }&#10; }&#10;}&#10;&#10;#ifdef DEBUG&#10;void pretty_print_all_values(void) {&#10; uart_puts_P(&quot;Voltage: &quot;);&#10; uart_print_uint16(voltage);&#10; uart_puts_P(&quot;mV\r\n&quot;);&#10;&#10; uart_puts_P(&quot;Load: &quot;);&#10; uart_print_uint16(current_out);&#10; uart_puts_P(&quot;mA &quot;);&#10; uart_print_uint16( power_load);&#10; uart_puts_P(&quot;W\r\n&quot;);&#10;&#10; uart_puts_P(&quot;Generator: &quot;);&#10; uart_print_uint16(current_in);&#10; uart_puts_P(&quot;mA &quot;);&#10; uart_print_uint16( power_gen);&#10; uart_puts_P(&quot;W\r\n&quot;);&#10;&#10; uart_puts_P(&quot;switches (load, dump, gen): &quot;);&#10; uart_putc(48 + loadsw);&#10; uart_putc(',');&#10; uart_putc(48 + dumpsw);&#10; uart_putc(',');&#10; uart_putc(48 + gensw);&#10; uart_puts_P(&quot;\r\n&quot;);&#10;}&#10;#endif&#10;&#10;void process_command() {&#10; if(strstr(command_in,&quot;A&quot;) != NULL) {&#10; // we have an A and B (from check in work_uart()&#10; // so our message should be complete and consist of:&#10; // A$voltage,$current_in,$current_out,$power_in,$power_out,loadsw,dumpsw,gensw\n&#10;&#10; //A12.5,65464,00000,00000,00000,1,0,1B&#10;&#10; char *token;&#10; uint8_t tokencounter = 0;&#10;&#10; char *start = strrchr(command_in, 'A');&#10;&#10; // remove first (B is ignored by atoi)&#10; start++;&#10;&#10;#ifdef DEBUG&#10; uart_puts_P(&quot;from start: &quot;);&#10; uart_puts(start);&#10; uart_puts_P(&quot;\r\n&quot;);&#10;#endif&#10;&#10; token = strtok(start, &quot;,&quot;);&#10;&#10; while( token ) {&#10;#ifdef DEBUG&#10; uart_puts_P(&quot;token= &quot;);&#10; uart_puts(token);&#10; uart_puts_P(&quot;\r\n&quot;);&#10;#endif&#10;&#10; switch(tokencounter) {&#10; case 0:&#10; voltage = atoi(token);&#10; break;&#10; case 1:&#10; current_in = atoi(token);&#10; break;&#10; case 2:&#10; current_out = atoi(token);&#10; break;&#10; case 3:&#10; power_gen = atoi(token);&#10; break;&#10; case 4:&#10; power_load = atoi(token);&#10; break;&#10; case 5:&#10; if(atoi(token) == 1) loadsw = 1;&#10; else loadsw = 0;&#10; break;&#10; case 6:&#10; if(atoi(token) == 1) dumpsw = 1;&#10; else dumpsw = 0;&#10; break;&#10; case 7:&#10; if(atoi(token) == 1) gensw = 1;&#10; else gensw = 0;&#10; break;&#10; }&#10;&#10; tokencounter++;&#10; token = strtok(NULL, &quot;,&quot;);&#10; }&#10;#ifdef DEBUG&#10; pretty_print_all_values();&#10;#endif&#10;&#10; }&#10;}&#10;&#10;void work_uart(){&#10; unsigned int c = uart_getc();&#10;&#10; if ( !(c &amp; UART_NO_DATA) ) {&#10;&#10; data_in[data_count] = c;&#10;&#10; if (data_in[data_count] == 'B') { // finish reading when newline is received&#10; data_count = 0;&#10;&#10; memcpy(command_in, data_in, BUFSIZE);&#10;&#10; // Now clear data_in, the UART can reuse it now&#10; memset(data_in, 0, BUFSIZE);&#10;&#10; process_command();&#10; } else {&#10; data_count++;&#10; }&#10; }&#10;}&#10;&#10;&#10;&#10;&#10;int main(void) {&#10;&#9;ports_init();&#10;&#9;timer_init();&#10; uart_init(UART_BAUD_SELECT(19200,F_CPU));&#10; memset(data_in, 0, BUFSIZE);&#10;&#10;&#9;while(1) {&#10;&#10;&#9; work_uart();&#10;&#10; if(syscounter &gt;= 200) {&#10; uart_putc('a'); // send a to receive values&#10;&#10; print_sevenseg(0, power_gen);&#10; print_sevenseg(1, power_load);&#10;&#10; syscounter = 0;&#10; }&#10;&#9;}&#10;&#9;&#10;&#9;return(0);&#10;}&#10;&#10;// system timer&#10;SIGNAL(TIMER1_COMPA_vect) {&#10;&#9;syscounter++;&#10;&#10;&#9;// output to sevensegment and leds&#10;&#9;// make this here to reduce display flicker&#10; digit++;&#10; if(digit &gt;5) digit = 0;&#10; leddigit++;&#10; if(leddigit &gt;3) leddigit = 0;&#10;&#10; SEVENSEG_PORT = digitbuffer[digit];&#10; SEVENSEGDIG_PORT = _BV(digit+DIG0);&#10;&#10; LED_PORT = leddigitbuffer[leddigit];&#10; LEDDIG_PORT = _BV(leddigit);&#10;}#0;n#volatile uint8_t digitbuffer[6] = { 0,0,0,0,0,0 };&#10;volatile uint8_t leddigitbuffer[4] = { 0,0,0,0 };&#10;uint8_t digit = 0;&#10;uint8_t leddigit = 0;&#10;&#10;// values send over uart from powerboard&#10;uint16_t voltage = 0;&#10;int16_t current_in = 0;&#10;int16_t current_out = 0;&#10;uint8_t dumpsw = 0; //TODO: make bitfield&#10;uint8_t loadsw = 0; //TODO: make bitfield&#10;uint8_t gensw = 0; //TODO: make bitfield&#10;&#10;uint16_t power_gen = 0;&#10;uint16_t power_load = 0;&#10;&#10;unsigned char data_count = 0;&#10;unsigned char data_in[BUFSIZE];&#10;char command_in[BUFSIZE];&#10;&#10;const uint8_t digit_translate[10] = {&#10; 63, 6, 91, 79, 102, 109, 125, 7, 127, 111&#10;};&#10;&#10;&#10;static void timer_init(void) {&#10;&#9;// clock is 8MHz&#10;&#9;TCCR1B |= _BV(WGM12) | _BV(CS11) | _BV(CS10) ; // CTC Mode for Timer 1 (16Bit) with prescale of 64&#10;&#9;OCR1A = 250; // 500Hz&#10;&#9;TIMSK = _BV(OCIE1A);&#10;&#9;sei();&#9;// enable interrupts&#10;}&#10;&#10;static void ports_init(void) {&#10; // make column / digit driver pins to output&#10; LEDDIG_DDR |= _BV(LEDS_MID1) | _BV(LEDS_MID2) | _BV(LEDS_LOAD) | _BV(LEDS_GEN);&#10; SEVENSEGDIG_DDR |= _BV(DIG0) | _BV(DIG1) | _BV(DIG2) | _BV(DIG3) | _BV(DIG4) | _BV(DIG5);&#10;&#10; // make data ports to output&#10; LED_DDR = 0xff;&#10; SEVENSEG_DDR = 0xff;&#10;&#10; SEVENSEGDIG_PORT = 0;&#10; SEVENSEG_PORT = 0;&#10;&#10; LEDDIG_PORT = 0;&#10; LED_PORT = 0;&#10;}&#10;&#10;static void print_sevenseg(uint8_t display, uint16_t value) {&#10; uint8_t d[3];&#10; d[2] = (value % 1000 / 100 );&#10; d[1] = (value % 100 / 10 );&#10; d[0] = (value % 10);&#10;&#10; if(display == 0) {&#10; for(uint8_t i = 0; i&lt; 3; i++) {&#10; digitbuffer[i] = digit_translate[d[i]];&#10; }&#10; } else {&#10; for(uint8_t i = 0; i&lt; 3; i++) {&#10; digitbuffer[i+3] = digit_translate[d[i]];&#10; }&#10; }&#10;}&#10;&#10;#ifdef DEBUG&#10;void pretty_print_all_values(void) {&#10; uart_puts_P(&quot;Voltage: &quot;);&#10; uart_print_uint16(voltage);&#10; uart_puts_P(&quot;mV\r\n&quot;);&#10;&#10; uart_puts_P(&quot;Load: &quot;);&#10; uart_print_uint16(current_out);&#10; uart_puts_P(&quot;mA &quot;);&#10; uart_print_uint16( power_load);&#10; uart_puts_P(&quot;W\r\n&quot;);&#10;&#10; uart_puts_P(&quot;Generator: &quot;);&#10; uart_print_uint16(current_in);&#10; uart_puts_P(&quot;mA &quot;);&#10; uart_print_uint16( power_gen);&#10; uart_puts_P(&quot;W\r\n&quot;);&#10;&#10; uart_puts_P(&quot;switches (load, dump, gen): &quot;);&#10; uart_putc(48 + loadsw);&#10; uart_putc(',');&#10; uart_putc(48 + dumpsw);&#10; uart_putc(',');&#10; uart_putc(48 + gensw);&#10; uart_puts_P(&quot;\r\n&quot;);&#10;}&#10;#endif&#10;&#10;void process_command() {&#10; if(strstr(command_in,&quot;A&quot;) != NULL) {&#10; // we have an A and B (from check in work_uart()&#10; // so our message should be complete and consist of:&#10; // A$voltage,$current_in,$current_out,$power_in,$power_out,loadsw,dumpsw,gensw\n&#10;&#10; //A12.5,65464,00000,00000,00000,1,0,1B&#10;&#10; char *token;&#10; uint8_t tokencounter = 0;&#10;&#10; char *start = strrchr(command_in, 'A');&#10;&#10; // remove first (B is ignored by atoi)&#10; start++;&#10;&#10;#ifdef DEBUG&#10; uart_puts_P(&quot;from start: &quot;);&#10; uart_puts(start);&#10; uart_puts_P(&quot;\r\n&quot;);&#10;#endif&#10;&#10; token = strtok(start, &quot;,&quot;);&#10;&#10; while( token ) {&#10;#ifdef DEBUG&#10; uart_puts_P(&quot;token= &quot;);&#10; uart_puts(token);&#10; uart_puts_P(&quot;\r\n&quot;);&#10;#endif&#10;&#10; switch(tokencounter) {&#10; case 0:&#10; voltage = atoi(token);&#10; break;&#10; case 1:&#10; current_in = atoi(token);&#10; break;&#10; case 2:&#10; current_out = atoi(token);&#10; break;&#10; case 3:&#10; power_gen = atoi(token);&#10; break;&#10; case 4:&#10; power_load = atoi(token);&#10; break;&#10; case 5:&#10; if(atoi(token) == 1) loadsw = 1;&#10; else loadsw = 0;&#10; break;&#10; case 6:&#10; if(atoi(token) == 1) dumpsw = 1;&#10; else dumpsw = 0;&#10; break;&#10; case 7:&#10; if(atoi(token) == 1) gensw = 1;&#10; else gensw = 0;&#10; break;&#10; }&#10;&#10; tokencounter++;&#10; token = strtok(NULL, &quot;,&quot;);&#10; }&#10;#ifdef DEBUG&#10; pretty_print_all_values();&#10;#endif&#10;&#10; }&#10;}&#10;&#10;void work_uart(){&#10; unsigned int c = uart_getc();&#10;&#10; if ( !(c &amp; UART_NO_DATA) ) {&#10;&#10; data_in[data_count] = c;&#10;&#10; if (data_in[data_count] == 'B') { // finish reading when newline is received&#10; data_count = 0;&#10;&#10; memcpy(command_in, data_in, BUFSIZE);&#10;&#10; // Now clear data_in, the UART can reuse it now&#10; memset(data_in, 0, BUFSIZE);&#10;&#10; process_command();&#10; } else {&#10; data_count++;&#10; }&#10; }&#10;}&#10;&#10;&#10;&#10;&#10;int main(void) {&#10;&#9;ports_init();&#10;&#9;timer_init();&#10; uart_init(UART_BAUD_SELECT(19200,F_CPU));&#10; memset(data_in, 0, BUFSIZE);&#10;&#10;&#9;while(1) {&#10;&#10;&#9; work_uart();&#10;&#10; if(syscounter &gt;= 200) {&#10; uart_putc('a'); // send a to receive values&#10;&#10; print_sevenseg(0, power_gen);&#10; print_sevenseg(1, power_load);&#10;&#10; syscounter = 0;&#10; }&#10;&#9;}&#10;&#9;&#10;&#9;return(0);&#10;}&#10;&#10;// system timer&#10;SIGNAL(TIMER1_COMPA_vect) {&#10;&#9;syscounter++;&#10;&#10;&#9;// output to sevensegment and leds&#10;&#9;// make this here to reduce display flicker&#10; digit++;&#10; if(digit &gt;5) digit = 0;&#10; leddigit++;&#10; if(leddigit &gt;3) leddigit = 0;&#10;&#10; SEVENSEG_PORT = digitbuffer[digit];&#10; SEVENSEGDIG_PORT = _BV(digit+DIG0);&#10;&#10; LED_PORT = leddigitbuffer[leddigit];&#10; LEDDIG_PORT = _BV(leddigit);&#10;}#0" expanded="false" />
<element signature="n#{&#10; uint8_t d[3];&#10; d[2] = (value % 1000 / 100 );&#10; d[1] = (value % 100 / 10 );&#10; d[0] = (value % 10);&#10;&#10; if(display == 0) {&#10; for(uint8_t i = 0; i&lt; 3; i++) {&#10; digitbuffer[i] = digit_translate[d[i]];&#10; }&#10; } else {&#10; for(uint8_t i = 0; i&lt; 3; i++) {&#10; digitbuffer[i+3] = digit_translate[d[i]];&#10; }&#10; }&#10;}#0;n#static void print_sevenseg(uint8_t display, uint16_t value) {&#10; uint8_t d[3];&#10; d[2] = (value % 1000 / 100 );&#10; d[1] = (value % 100 / 10 );&#10; d[0] = (value % 10);&#10;&#10; if(display == 0) {&#10; for(uint8_t i = 0; i&lt; 3; i++) {&#10; digitbuffer[i] = digit_translate[d[i]];&#10; }&#10; } else {&#10; for(uint8_t i = 0; i&lt; 3; i++) {&#10; digitbuffer[i+3] = digit_translate[d[i]];&#10; }&#10; }&#10;}#0;n#const uint8_t digit_translate[10] = {&#10; 63, 6, 91, 79, 102, 109, 125, 7, 127, 111&#10;};&#10;&#10;&#10;static void timer_init(void) {&#10;&#9;// clock is 8MHz&#10;&#9;TCCR1B |= _BV(WGM12) | _BV(CS11) | _BV(CS10) ; // CTC Mode for Timer 1 (16Bit) with prescale of 64&#10;&#9;OCR1A = 250; // 500Hz&#10;&#9;TIMSK = _BV(OCIE1A);&#10;&#9;sei();&#9;// enable interrupts&#10;}&#10;&#10;static void ports_init(void) {&#10; // make column / digit driver pins to output&#10; LEDDIG_DDR |= _BV(LEDS_MID1) | _BV(LEDS_MID2) | _BV(LEDS_LOAD) | _BV(LEDS_GEN);&#10; SEVENSEGDIG_DDR |= _BV(DIG0) | _BV(DIG1) | _BV(DIG2) | _BV(DIG3) | _BV(DIG4) | _BV(DIG5);&#10;&#10; // make data ports to output&#10; LED_DDR = 0xff;&#10; SEVENSEG_DDR = 0xff;&#10;&#10; SEVENSEGDIG_PORT = 0;&#10; SEVENSEG_PORT = 0;&#10;&#10; LEDDIG_PORT = 0;&#10; LED_PORT = 0;&#10;}&#10;&#10;static void print_sevenseg(uint8_t display, uint16_t value) {&#10; uint8_t d[3];&#10; d[2] = (value % 1000 / 100 );&#10; d[1] = (value % 100 / 10 );&#10; d[0] = (value % 10);&#10;&#10; if(display == 0) {&#10; for(uint8_t i = 0; i&lt; 3; i++) {&#10; digitbuffer[i] = digit_translate[d[i]];&#10; }&#10; } else {&#10; for(uint8_t i = 0; i&lt; 3; i++) {&#10; digitbuffer[i+3] = digit_translate[d[i]];&#10; }&#10; }&#10;}&#10;&#10;#ifdef DEBUG&#10;void pretty_print_all_values(void) {&#10; uart_puts_P(&quot;Voltage: &quot;);&#10; uart_print_uint16(voltage);&#10; uart_puts_P(&quot;mV\r\n&quot;);&#10;&#10; uart_puts_P(&quot;Load: &quot;);&#10; uart_print_uint16(current_out);&#10; uart_puts_P(&quot;mA &quot;);&#10; uart_print_uint16( power_load);&#10; uart_puts_P(&quot;W\r\n&quot;);&#10;&#10; uart_puts_P(&quot;Generator: &quot;);&#10; uart_print_uint16(current_in);&#10; uart_puts_P(&quot;mA &quot;);&#10; uart_print_uint16( power_gen);&#10; uart_puts_P(&quot;W\r\n&quot;);&#10;&#10; uart_puts_P(&quot;switches (load, dump, gen): &quot;);&#10; uart_putc(48 + loadsw);&#10; uart_putc(',');&#10; uart_putc(48 + dumpsw);&#10; uart_putc(',');&#10; uart_putc(48 + gensw);&#10; uart_puts_P(&quot;\r\n&quot;);&#10;}&#10;#endif&#10;&#10;void process_command() {&#10; if(strstr(command_in,&quot;A&quot;) != NULL) {&#10; // we have an A and B (from check in work_uart()&#10; // so our message should be complete and consist of:&#10; // A$voltage,$current_in,$current_out,$power_in,$power_out,loadsw,dumpsw,gensw\n&#10;&#10; //A12.5,65464,00000,00000,00000,1,0,1B&#10;&#10; char *token;&#10; uint8_t tokencounter = 0;&#10;&#10; char *start = strrchr(command_in, 'A');&#10;&#10; // remove first (B is ignored by atoi)&#10; start++;&#10;&#10;#ifdef DEBUG&#10; uart_puts_P(&quot;from start: &quot;);&#10; uart_puts(start);&#10; uart_puts_P(&quot;\r\n&quot;);&#10;#endif&#10;&#10; token = strtok(start, &quot;,&quot;);&#10;&#10; while( token ) {&#10;#ifdef DEBUG&#10; uart_puts_P(&quot;token= &quot;);&#10; uart_puts(token);&#10; uart_puts_P(&quot;\r\n&quot;);&#10;#endif&#10;&#10; switch(tokencounter) {&#10; case 0:&#10; voltage = atoi(token);&#10; break;&#10; case 1:&#10; current_in = atoi(token);&#10; break;&#10; case 2:&#10; current_out = atoi(token);&#10; break;&#10; case 3:&#10; power_gen = atoi(token);&#10; break;&#10; case 4:&#10; power_load = atoi(token);&#10; break;&#10; case 5:&#10; if(atoi(token) == 1) loadsw = 1;&#10; else loadsw = 0;&#10; break;&#10; case 6:&#10; if(atoi(token) == 1) dumpsw = 1;&#10; else dumpsw = 0;&#10; break;&#10; case 7:&#10; if(atoi(token) == 1) gensw = 1;&#10; else gensw = 0;&#10; break;&#10; }&#10;&#10; tokencounter++;&#10; token = strtok(NULL, &quot;,&quot;);&#10; }&#10;#ifdef DEBUG&#10; pretty_print_all_values();&#10;#endif&#10;&#10; }&#10;}&#10;&#10;void work_uart(){&#10; unsigned int c = uart_getc();&#10;&#10; if ( !(c &amp; UART_NO_DATA) ) {&#10;&#10; data_in[data_count] = c;&#10;&#10; if (data_in[data_count] == 'B') { // finish reading when newline is received&#10; data_count = 0;&#10;&#10; memcpy(command_in, data_in, BUFSIZE);&#10;&#10; // Now clear data_in, the UART can reuse it now&#10; memset(data_in, 0, BUFSIZE);&#10;&#10; process_command();&#10; } else {&#10; data_count++;&#10; }&#10; }&#10;}&#10;&#10;&#10;&#10;&#10;int main(void) {&#10;&#9;ports_init();&#10;&#9;timer_init();&#10; uart_init(UART_BAUD_SELECT(19200,F_CPU));&#10; memset(data_in, 0, BUFSIZE);&#10;&#10;&#9;while(1) {&#10;&#10;&#9; work_uart();&#10;&#10; if(syscounter &gt;= 200) {&#10; uart_putc('a'); // send a to receive values&#10;&#10; print_sevenseg(0, power_gen);&#10; print_sevenseg(1, power_load);&#10;&#10; syscounter = 0;&#10; }&#10;&#9;}&#10;&#9;&#10;&#9;return(0);&#10;}&#10;&#10;// system timer&#10;SIGNAL(TIMER1_COMPA_vect) {&#10;&#9;syscounter++;&#10;&#10;&#9;// output to sevensegment and leds&#10;&#9;// make this here to reduce display flicker&#10; digit++;&#10; if(digit &gt;5) digit = 0;&#10; leddigit++;&#10; if(leddigit &gt;3) leddigit = 0;&#10;&#10; SEVENSEG_PORT = digitbuffer[digit];&#10; SEVENSEGDIG_PORT = _BV(digit+DIG0);&#10;&#10; LED_PORT = leddigitbuffer[leddigit];&#10; LEDDIG_PORT = _BV(leddigit);&#10;}#0;n#volatile uint8_t leddigitbuffer[4] = { 0,0,0,0 };&#10;uint8_t digit = 0;&#10;uint8_t leddigit = 0;&#10;&#10;// values send over uart from powerboard&#10;uint16_t voltage = 0;&#10;int16_t current_in = 0;&#10;int16_t current_out = 0;&#10;uint8_t dumpsw = 0; //TODO: make bitfield&#10;uint8_t loadsw = 0; //TODO: make bitfield&#10;uint8_t gensw = 0; //TODO: make bitfield&#10;&#10;uint16_t power_gen = 0;&#10;uint16_t power_load = 0;&#10;&#10;unsigned char data_count = 0;&#10;unsigned char data_in[BUFSIZE];&#10;char command_in[BUFSIZE];&#10;&#10;const uint8_t digit_translate[10] = {&#10; 63, 6, 91, 79, 102, 109, 125, 7, 127, 111&#10;};&#10;&#10;&#10;static void timer_init(void) {&#10;&#9;// clock is 8MHz&#10;&#9;TCCR1B |= _BV(WGM12) | _BV(CS11) | _BV(CS10) ; // CTC Mode for Timer 1 (16Bit) with prescale of 64&#10;&#9;OCR1A = 250; // 500Hz&#10;&#9;TIMSK = _BV(OCIE1A);&#10;&#9;sei();&#9;// enable interrupts&#10;}&#10;&#10;static void ports_init(void) {&#10; // make column / digit driver pins to output&#10; LEDDIG_DDR |= _BV(LEDS_MID1) | _BV(LEDS_MID2) | _BV(LEDS_LOAD) | _BV(LEDS_GEN);&#10; SEVENSEGDIG_DDR |= _BV(DIG0) | _BV(DIG1) | _BV(DIG2) | _BV(DIG3) | _BV(DIG4) | _BV(DIG5);&#10;&#10; // make data ports to output&#10; LED_DDR = 0xff;&#10; SEVENSEG_DDR = 0xff;&#10;&#10; SEVENSEGDIG_PORT = 0;&#10; SEVENSEG_PORT = 0;&#10;&#10; LEDDIG_PORT = 0;&#10; LED_PORT = 0;&#10;}&#10;&#10;static void print_sevenseg(uint8_t display, uint16_t value) {&#10; uint8_t d[3];&#10; d[2] = (value % 1000 / 100 );&#10; d[1] = (value % 100 / 10 );&#10; d[0] = (value % 10);&#10;&#10; if(display == 0) {&#10; for(uint8_t i = 0; i&lt; 3; i++) {&#10; digitbuffer[i] = digit_translate[d[i]];&#10; }&#10; } else {&#10; for(uint8_t i = 0; i&lt; 3; i++) {&#10; digitbuffer[i+3] = digit_translate[d[i]];&#10; }&#10; }&#10;}&#10;&#10;#ifdef DEBUG&#10;void pretty_print_all_values(void) {&#10; uart_puts_P(&quot;Voltage: &quot;);&#10; uart_print_uint16(voltage);&#10; uart_puts_P(&quot;mV\r\n&quot;);&#10;&#10; uart_puts_P(&quot;Load: &quot;);&#10; uart_print_uint16(current_out);&#10; uart_puts_P(&quot;mA &quot;);&#10; uart_print_uint16( power_load);&#10; uart_puts_P(&quot;W\r\n&quot;);&#10;&#10; uart_puts_P(&quot;Generator: &quot;);&#10; uart_print_uint16(current_in);&#10; uart_puts_P(&quot;mA &quot;);&#10; uart_print_uint16( power_gen);&#10; uart_puts_P(&quot;W\r\n&quot;);&#10;&#10; uart_puts_P(&quot;switches (load, dump, gen): &quot;);&#10; uart_putc(48 + loadsw);&#10; uart_putc(',');&#10; uart_putc(48 + dumpsw);&#10; uart_putc(',');&#10; uart_putc(48 + gensw);&#10; uart_puts_P(&quot;\r\n&quot;);&#10;}&#10;#endif&#10;&#10;void process_command() {&#10; if(strstr(command_in,&quot;A&quot;) != NULL) {&#10; // we have an A and B (from check in work_uart()&#10; // so our message should be complete and consist of:&#10; // A$voltage,$current_in,$current_out,$power_in,$power_out,loadsw,dumpsw,gensw\n&#10;&#10; //A12.5,65464,00000,00000,00000,1,0,1B&#10;&#10; char *token;&#10; uint8_t tokencounter = 0;&#10;&#10; char *start = strrchr(command_in, 'A');&#10;&#10; // remove first (B is ignored by atoi)&#10; start++;&#10;&#10;#ifdef DEBUG&#10; uart_puts_P(&quot;from start: &quot;);&#10; uart_puts(start);&#10; uart_puts_P(&quot;\r\n&quot;);&#10;#endif&#10;&#10; token = strtok(start, &quot;,&quot;);&#10;&#10; while( token ) {&#10;#ifdef DEBUG&#10; uart_puts_P(&quot;token= &quot;);&#10; uart_puts(token);&#10; uart_puts_P(&quot;\r\n&quot;);&#10;#endif&#10;&#10; switch(tokencounter) {&#10; case 0:&#10; voltage = atoi(token);&#10; break;&#10; case 1:&#10; current_in = atoi(token);&#10; break;&#10; case 2:&#10; current_out = atoi(token);&#10; break;&#10; case 3:&#10; power_gen = atoi(token);&#10; break;&#10; case 4:&#10; power_load = atoi(token);&#10; break;&#10; case 5:&#10; if(atoi(token) == 1) loadsw = 1;&#10; else loadsw = 0;&#10; break;&#10; case 6:&#10; if(atoi(token) == 1) dumpsw = 1;&#10; else dumpsw = 0;&#10; break;&#10; case 7:&#10; if(atoi(token) == 1) gensw = 1;&#10; else gensw = 0;&#10; break;&#10; }&#10;&#10; tokencounter++;&#10; token = strtok(NULL, &quot;,&quot;);&#10; }&#10;#ifdef DEBUG&#10; pretty_print_all_values();&#10;#endif&#10;&#10; }&#10;}&#10;&#10;void work_uart(){&#10; unsigned int c = uart_getc();&#10;&#10; if ( !(c &amp; UART_NO_DATA) ) {&#10;&#10; data_in[data_count] = c;&#10;&#10; if (data_in[data_count] == 'B') { // finish reading when newline is received&#10; data_count = 0;&#10;&#10; memcpy(command_in, data_in, BUFSIZE);&#10;&#10; // Now clear data_in, the UART can reuse it now&#10; memset(data_in, 0, BUFSIZE);&#10;&#10; process_command();&#10; } else {&#10; data_count++;&#10; }&#10; }&#10;}&#10;&#10;&#10;&#10;&#10;int main(void) {&#10;&#9;ports_init();&#10;&#9;timer_init();&#10; uart_init(UART_BAUD_SELECT(19200,F_CPU));&#10; memset(data_in, 0, BUFSIZE);&#10;&#10;&#9;while(1) {&#10;&#10;&#9; work_uart();&#10;&#10; if(syscounter &gt;= 200) {&#10; uart_putc('a'); // send a to receive values&#10;&#10; print_sevenseg(0, power_gen);&#10; print_sevenseg(1, power_load);&#10;&#10; syscounter = 0;&#10; }&#10;&#9;}&#10;&#9;&#10;&#9;return(0);&#10;}&#10;&#10;// system timer&#10;SIGNAL(TIMER1_COMPA_vect) {&#10;&#9;syscounter++;&#10;&#10;&#9;// output to sevensegment and leds&#10;&#9;// make this here to reduce display flicker&#10; digit++;&#10; if(digit &gt;5) digit = 0;&#10; leddigit++;&#10; if(leddigit &gt;3) leddigit = 0;&#10;&#10; SEVENSEG_PORT = digitbuffer[digit];&#10; SEVENSEGDIG_PORT = _BV(digit+DIG0);&#10;&#10; LED_PORT = leddigitbuffer[leddigit];&#10; LEDDIG_PORT = _BV(leddigit);&#10;}#0;n#volatile uint8_t digitbuffer[6] = { 0,0,0,0,0,0 };&#10;volatile uint8_t leddigitbuffer[4] = { 0,0,0,0 };&#10;uint8_t digit = 0;&#10;uint8_t leddigit = 0;&#10;&#10;// values send over uart from powerboard&#10;uint16_t voltage = 0;&#10;int16_t current_in = 0;&#10;int16_t current_out = 0;&#10;uint8_t dumpsw = 0; //TODO: make bitfield&#10;uint8_t loadsw = 0; //TODO: make bitfield&#10;uint8_t gensw = 0; //TODO: make bitfield&#10;&#10;uint16_t power_gen = 0;&#10;uint16_t power_load = 0;&#10;&#10;unsigned char data_count = 0;&#10;unsigned char data_in[BUFSIZE];&#10;char command_in[BUFSIZE];&#10;&#10;const uint8_t digit_translate[10] = {&#10; 63, 6, 91, 79, 102, 109, 125, 7, 127, 111&#10;};&#10;&#10;&#10;static void timer_init(void) {&#10;&#9;// clock is 8MHz&#10;&#9;TCCR1B |= _BV(WGM12) | _BV(CS11) | _BV(CS10) ; // CTC Mode for Timer 1 (16Bit) with prescale of 64&#10;&#9;OCR1A = 250; // 500Hz&#10;&#9;TIMSK = _BV(OCIE1A);&#10;&#9;sei();&#9;// enable interrupts&#10;}&#10;&#10;static void ports_init(void) {&#10; // make column / digit driver pins to output&#10; LEDDIG_DDR |= _BV(LEDS_MID1) | _BV(LEDS_MID2) | _BV(LEDS_LOAD) | _BV(LEDS_GEN);&#10; SEVENSEGDIG_DDR |= _BV(DIG0) | _BV(DIG1) | _BV(DIG2) | _BV(DIG3) | _BV(DIG4) | _BV(DIG5);&#10;&#10; // make data ports to output&#10; LED_DDR = 0xff;&#10; SEVENSEG_DDR = 0xff;&#10;&#10; SEVENSEGDIG_PORT = 0;&#10; SEVENSEG_PORT = 0;&#10;&#10; LEDDIG_PORT = 0;&#10; LED_PORT = 0;&#10;}&#10;&#10;static void print_sevenseg(uint8_t display, uint16_t value) {&#10; uint8_t d[3];&#10; d[2] = (value % 1000 / 100 );&#10; d[1] = (value % 100 / 10 );&#10; d[0] = (value % 10);&#10;&#10; if(display == 0) {&#10; for(uint8_t i = 0; i&lt; 3; i++) {&#10; digitbuffer[i] = digit_translate[d[i]];&#10; }&#10; } else {&#10; for(uint8_t i = 0; i&lt; 3; i++) {&#10; digitbuffer[i+3] = digit_translate[d[i]];&#10; }&#10; }&#10;}&#10;&#10;#ifdef DEBUG&#10;void pretty_print_all_values(void) {&#10; uart_puts_P(&quot;Voltage: &quot;);&#10; uart_print_uint16(voltage);&#10; uart_puts_P(&quot;mV\r\n&quot;);&#10;&#10; uart_puts_P(&quot;Load: &quot;);&#10; uart_print_uint16(current_out);&#10; uart_puts_P(&quot;mA &quot;);&#10; uart_print_uint16( power_load);&#10; uart_puts_P(&quot;W\r\n&quot;);&#10;&#10; uart_puts_P(&quot;Generator: &quot;);&#10; uart_print_uint16(current_in);&#10; uart_puts_P(&quot;mA &quot;);&#10; uart_print_uint16( power_gen);&#10; uart_puts_P(&quot;W\r\n&quot;);&#10;&#10; uart_puts_P(&quot;switches (load, dump, gen): &quot;);&#10; uart_putc(48 + loadsw);&#10; uart_putc(',');&#10; uart_putc(48 + dumpsw);&#10; uart_putc(',');&#10; uart_putc(48 + gensw);&#10; uart_puts_P(&quot;\r\n&quot;);&#10;}&#10;#endif&#10;&#10;void process_command() {&#10; if(strstr(command_in,&quot;A&quot;) != NULL) {&#10; // we have an A and B (from check in work_uart()&#10; // so our message should be complete and consist of:&#10; // A$voltage,$current_in,$current_out,$power_in,$power_out,loadsw,dumpsw,gensw\n&#10;&#10; //A12.5,65464,00000,00000,00000,1,0,1B&#10;&#10; char *token;&#10; uint8_t tokencounter = 0;&#10;&#10; char *start = strrchr(command_in, 'A');&#10;&#10; // remove first (B is ignored by atoi)&#10; start++;&#10;&#10;#ifdef DEBUG&#10; uart_puts_P(&quot;from start: &quot;);&#10; uart_puts(start);&#10; uart_puts_P(&quot;\r\n&quot;);&#10;#endif&#10;&#10; token = strtok(start, &quot;,&quot;);&#10;&#10; while( token ) {&#10;#ifdef DEBUG&#10; uart_puts_P(&quot;token= &quot;);&#10; uart_puts(token);&#10; uart_puts_P(&quot;\r\n&quot;);&#10;#endif&#10;&#10; switch(tokencounter) {&#10; case 0:&#10; voltage = atoi(token);&#10; break;&#10; case 1:&#10; current_in = atoi(token);&#10; break;&#10; case 2:&#10; current_out = atoi(token);&#10; break;&#10; case 3:&#10; power_gen = atoi(token);&#10; break;&#10; case 4:&#10; power_load = atoi(token);&#10; break;&#10; case 5:&#10; if(atoi(token) == 1) loadsw = 1;&#10; else loadsw = 0;&#10; break;&#10; case 6:&#10; if(atoi(token) == 1) dumpsw = 1;&#10; else dumpsw = 0;&#10; break;&#10; case 7:&#10; if(atoi(token) == 1) gensw = 1;&#10; else gensw = 0;&#10; break;&#10; }&#10;&#10; tokencounter++;&#10; token = strtok(NULL, &quot;,&quot;);&#10; }&#10;#ifdef DEBUG&#10; pretty_print_all_values();&#10;#endif&#10;&#10; }&#10;}&#10;&#10;void work_uart(){&#10; unsigned int c = uart_getc();&#10;&#10; if ( !(c &amp; UART_NO_DATA) ) {&#10;&#10; data_in[data_count] = c;&#10;&#10; if (data_in[data_count] == 'B') { // finish reading when newline is received&#10; data_count = 0;&#10;&#10; memcpy(command_in, data_in, BUFSIZE);&#10;&#10; // Now clear data_in, the UART can reuse it now&#10; memset(data_in, 0, BUFSIZE);&#10;&#10; process_command();&#10; } else {&#10; data_count++;&#10; }&#10; }&#10;}&#10;&#10;&#10;&#10;&#10;int main(void) {&#10;&#9;ports_init();&#10;&#9;timer_init();&#10; uart_init(UART_BAUD_SELECT(19200,F_CPU));&#10; memset(data_in, 0, BUFSIZE);&#10;&#10;&#9;while(1) {&#10;&#10;&#9; work_uart();&#10;&#10; if(syscounter &gt;= 200) {&#10; uart_putc('a'); // send a to receive values&#10;&#10; print_sevenseg(0, power_gen);&#10; print_sevenseg(1, power_load);&#10;&#10; syscounter = 0;&#10; }&#10;&#9;}&#10;&#9;&#10;&#9;return(0);&#10;}&#10;&#10;// system timer&#10;SIGNAL(TIMER1_COMPA_vect) {&#10;&#9;syscounter++;&#10;&#10;&#9;// output to sevensegment and leds&#10;&#9;// make this here to reduce display flicker&#10; digit++;&#10; if(digit &gt;5) digit = 0;&#10; leddigit++;&#10; if(leddigit &gt;3) leddigit = 0;&#10;&#10; SEVENSEG_PORT = digitbuffer[digit];&#10; SEVENSEGDIG_PORT = _BV(digit+DIG0);&#10;&#10; LED_PORT = leddigitbuffer[leddigit];&#10; LEDDIG_PORT = _BV(leddigit);&#10;}#0" expanded="false" />
</folding>
</state>
</provider>
</entry>
</component>
<component name="masterDetails">
<states>
<state key="ArtifactsStructureConfigurable.UI">
<settings>
<artifact-editor />
<splitter-proportions>
<option name="proportions">
<list>
<option value="0.2" />
</list>
</option>
</splitter-proportions>
</settings>
</state>
<state key="FacetStructureConfigurable.UI">
<settings>
<last-edited>No facets are configured</last-edited>
<splitter-proportions>
<option name="proportions">
<list>
<option value="0.2" />
</list>
</option>
</splitter-proportions>
</settings>
</state>
<state key="GlobalLibrariesConfigurable.UI">
<settings>
<last-edited>Node.js v0.8.17 Core Modules</last-edited>
<splitter-proportions>
<option name="proportions">
<list>
<option value="0.2" />
</list>
</option>
</splitter-proportions>
</settings>
</state>
<state key="JdkListConfigurable.UI">
<settings>
<last-edited>1.6</last-edited>
<splitter-proportions>
<option name="proportions">
<list>
<option value="0.2" />
</list>
</option>
</splitter-proportions>
</settings>
</state>
<state key="ModuleStructureConfigurable.UI">
<settings>
<last-edited>displayboard</last-edited>
<splitter-proportions>
<option name="proportions">
<list>
<option value="0.2" />
<option value="0.5" />
</list>
</option>
</splitter-proportions>
</settings>
</state>
<state key="ProjectLibrariesConfigurable.UI">
<settings>
<splitter-proportions>
<option name="proportions">
<list>
<option value="0.2" />
</list>
</option>
</splitter-proportions>
</settings>
</state>
</states>
</component>
</project>