void adc_read(unsigned char *buf) { unsigned char i; cli(); for (i = 0; i < 8; i++) { buf[0] = adc_value[i] >> 8; buf[1] = adc_value[i] & 0x00ff; buf += 2; } sei(); #if 0 unsigned char leftover; unsigned int value; leftover = 0; for (i = 0; i < 4; i++) { value = adc_sample(i); *buf++ = value & 0xff; leftover |= ((value & 0x0300) >> ((i + 1) * 2)); } *buf++ = leftover; leftover = 0; for (i = 4; i < 8; i++) { value = adc_sample(i); *buf++ = value & 0xff; leftover |= ((value & 0x0300) >> ((i - 3) * 2)); } *buf = leftover; #endif }
int main(void) { int key; adc_setup(); draw_text(); char temp[5]; while (1) { for (i = 0; i < 4; i++) { if (adc_isdone(adcchannels[i]) == 1) adc_sample(adcchannels[i], 128); tsample = adc_getsample(adcchannels[i]); if (! tsample == 0) { sprintf(temp, "%d", adcchannels[i]); term_puts(1, i + 4, temp); sprintf(temp, "%d", adcsmoothing[i]); term_puts(5, i + 4, temp); sprintf(temp, "%d", tsample); term_puts(11, i + 4, temp); } } key = term_getchar(NOWAIT); if (key != -1) { if (handle_kbd((int)key)) break; } } term_clrscr(); term_moveto(1, 1); return 0; }
//---------------------------------------------------------- //SYSTICK --> INTERRUPT call every 1ms //---------------------------------------------------------- void SysTick_Handler(void) { timestamp++; if(timestamp%10==0) adc_sample(); //temp control goes in here //temp0 = chan 5 = adc_read(5) etc (returns unsigned absolute millivolt value). //temp1 = chan 3 //temp2 = chan 1 //temp3 = chan 2 //if(timestamp%1000==0)//every 1 second //{ // for(i=1;i<9;i++) // printf("Channel %u : %u mV\n", i,adc_read(i)); // if(timestamp%250==0) //every 100 ms { manage_heaters(); } }
int main(void) { uint32_t last = xtimer_now(); int sample = 0; puts("\nRIOT ADC peripheral driver test\n"); puts("This test will sample all available ADC lines once every 100ms with\n" "a 10-bit resolution and print the sampled results to STDIO\n\n"); /* initialize all available ADC lines */ for (int i = 0; i < ADC_NUMOF; i++) { if (adc_init(ADC_LINE(i)) < 0) { printf("Initialization of ADC_LINE(%i) failed\n", i); return 1; } else { printf("Successfully initialized ADC_LINE(%i)\n", i); } } while (1) { for (int i = 0; i < ADC_NUMOF; i++) { sample = adc_sample(ADC_LINE(i), RES); if (sample < 0) { printf("ADC_LINE(%i): 10-bit resolution not applicable\n", i); } else { printf("ADC_LINE(%i): %i\n", i, sample); } } xtimer_usleep_until(&last, DELAY); } return 0; }
uint16_t adc_sampleAverage(uint8_t pin, uint8_t samples) { uint32_t total = 0; for (int i = 0; i < samples; i++) { total = total + adc_sample(pin); _delay_us(100); } return (uint16_t)(total/(uint32_t)samples); }
static int read_adc(void *dev, phydat_t *res) { const saul_adc_params_t *params = *((const saul_adc_params_t **)dev); res->val[0] = adc_sample(params->line, params->res); memset(&(res->val[1]), 0, 2 * sizeof(res->val[1])); /* Raw ADC reading has no unit */ res->unit = UNIT_NONE; res->scale = 0; return 1; }
int main(void) { printf("Testing ADC measurements\n"); adc_init(ADC_DEVICE_NUMBER, ADC_RESOLUTION); for (;;) { int value = adc_sample(ADC_DEVICE_NUMBER, ADC_CHANNEL_NUMBER); printf("adc=%d\n", value); } }
void ADCC0_IrqHandler(void) { status = ADC12_GetStatus(AT91C_BASE_ADC); for(i=0;i<7;i++) { if ((enchan&(1<<chns[i]) )&&ADC12_IsChannelInterruptStatusSet(status, chns[i])) { advalue[i] = ConvHex2mV(ADC12_GetConvertedData(AT91C_BASE_ADC, chns[i])); conversionDone |= 1<<chns[i]; } } if(autosample) adc_sample(); }
void app_demo(void) { uint16_t adc_result = avg_get(&(app.adc_avg)) << 4; if (tick_is_expired(&(app.adc_tick))) { app.adc_tick = tick_from_ms(1); avg_moving(&(app.adc_avg), adc_sample(ADC_0)); } if (tick_is_expired(&(app.tlc5971_tick))) { app.tlc5971_tick = tick_from_ms(50); //for (i=0; i<12; i++) { // app.bgr_buf[i] = adc_result; //} tlc5971_show(&(app.bgr_buf[0]), 4); //tlc5971_testpattern(&(app.bgr_buf[0]), 12); tlc5971_set_bgr(&(app.tlc), &(app.bgr_buf[0])); gpio_toggle(GPIO_LED_R); //max31855_read(&app.max31855); } if (tick_is_expired(&(app.servo_tick))) { app.servo_tick = tick_from_ms(30); /* Small deadband */ /* TODO: Add deadband to PWM? */ if ((adc_result > servo_last+16) || (adc_result < servo_last-16)) { pwm_set_freq(&(app.pwm_servo), 50000+(((190000-50000)/0xFFFF)*adc_result)); servo_last = adc_result; } } if (tick_is_expired(&(app.lcd_tick))) { app.lcd_tick = tick_from_ms(500); serlcd_set_cursor(&(app.serlcd), SERLCD_ROW1_POS); serlcd_print_decimal(&(app.serlcd), adc_result); } }
uint16_t hal_vdd_get_level(void) { uint8_t i; uint16_t adc_value = 0; for (i = 0; i < 4; i++) { adc_value += adc_sample(); } // Converting the sum of 4 10-bit samples to the number of mV // Which is: (adc_value * 3600) / (1024 * 4) // Reduced to: (adc_value * 225) / 256 // adc_value * 225 MD0 = (uint8_t)(adc_value & 0x00FF); MD4 = 225; MD1 = (uint8_t)(adc_value >> 8); MD5 = 0; // Wait for the calculation to complete for (i = 0; i < 11; i++) { _nop_(); } // Charging the result for division MD0 = MD0; MD1 = MD1; MD2 = MD2; MD3 = MD3; // Divide by 256 (0x0100) MD4 = 0x00; MD5 = 0x01; // Wait for the calculation to complete for (i = 0; i < 17; i++) { _nop_(); } return (uint16_t)((MD1<<8) | MD0); }
__interrupt void USCI0RX_ISR(void) { while(UCA0STAT & UCBUSY); if (UCA0RXBUF == TAKE_10_SAMPLES) { adc_sample(10); uart_send(output, 6); } else if (UCA0RXBUF == START_OPERATIONS) { RUNNING = 1; uart_send(">", 1); } else if (UCA0RXBUF == STOP_OPERATIONS) { RUNNING = 0; uart_send(".", 1); } else if (UCA0RXBUF == HELLO) { uart_send("h", 1); } else { uart_send("x", 1); } }
/* * main.c */ int main(void) { uart_init(); adc_init(); //Set serial as standard I/O stdout = stdin = &uart_stdout; printf("PowerLogger version 0.0.1 by deadbok.\r\n"); //Run this code forever, but put the CPU to sleep while(1) { printf("\nVCC: %u\n", adc_get_vcc()); printf("Temperature: %u\n", adc_get_temp()); for(unsigned char i = 0; i < 4; i++) { printf("Channel %u: %u\n", i, adc_sample(ADC_REF_AVCC, i)); } _delay_ms(1000); } }
void temperature_display(void) { char buffer[LCD_CHARACTERS]; int t_ref, t_tc1, t_tc2, t_tc3, t_tc4, t_tc5 = 0; float v_tc1, v_tc2, v_tc3, v_tc4, v_tc5 = 0; int v_ref = 0; // while OK or ESC are not pressed // show temperatures while (OK_SWITCH && ESC_SWITCH) { v_tc1 = adc_sample(0); v_tc2 = adc_sample(1); v_tc3 = adc_sample(2); v_tc4 = adc_sample(3); v_tc5 = adc_sample(4); v_ref = adc_sample(5); t_ref = reference_temperature(v_ref); t_tc1 = temperature(v_tc1, v_ref); t_tc2 = temperature(v_tc2, v_ref); t_tc3 = temperature(v_tc3, v_ref); t_tc4 = temperature(v_tc4, v_ref); t_tc5 = temperature(v_tc5, v_ref); lcd_goto(1, 1); sprintf(buffer, "T0: %3d\001C T3: %3d\001C", t_ref, t_tc3); lcd_write(buffer); lcd_goto(2, 1); sprintf(buffer, "T1: %3d\001C T4: %3d\001C", t_tc1, t_tc4); lcd_write(buffer); lcd_goto(3, 1); sprintf(buffer, "T2: %3d\001C T5: %3d\001C", t_tc2, t_tc5); lcd_write(buffer); // delay between measurements Delay10KTCYx(255); Delay10KTCYx(255); Delay10KTCYx(255); Delay10KTCYx(255); } }
static void lcd_panel_server(cyg_addrword_t p) { int iX, iY, newX, newY, diffX, diffY, timeout, samples; cyg_uint32 event; diag_printf("LCD panel server here\n"); while (TRUE) { cyg_semaphore_wait(&lcd_panel_sem); samples = 0; iX = 0; iY = 0; // Wait for press to go away (no drag support) timeout = 0; while (timeout < LCD_PANEL_TIMEOUT) { *(volatile cyg_uint8 *)TOUCH_CTL = 0x00; // Disable drives while (*(volatile cyg_uint32 *)INTSR1 & INTSR1_EINT2) ; *(volatile cyg_uint8 *)TOUCH_CTL = 0x70; // Idle state (so interrupt works) cyg_thread_delay(2); // Wait 20 ms if (*(volatile cyg_uint32 *)INTSR1 & INTSR1_EINT2) { // Still pressed // Drive TSPY, ground TSMY, and disconnect TSPX and TSMX *(volatile cyg_uint8 *)TOUCH_CTL = 0x50; panel_delay(); newY = adc_sample(2); // Drive TSPX, ground TSMX, and disconnect TSPY and TSMY *(volatile cyg_uint8 *)TOUCH_CTL = 0xA0; panel_delay(); newX = adc_sample(7); #if 0 diag_printf("timeout: %d, ISR: %x, newX: %d, newY: %d\n", timeout, *(volatile cyg_uint32 *)INTSR1, newX, newY); #endif // See if this sample makes any sense if (samples) { diffX = abs(iX/samples - newX); diffY = abs(iY/samples - newY); if ((diffX <= ((iX/samples)/4)) && (diffY <= ((iY/samples)/4))) { samples++; iX += newX; iY += newY; } else { #if 0 diag_printf("Discard - newX: %d, X: %d, newY: %d, Y: %d\n", newX, iX/samples, newY, iY/samples); #endif break; } } else { iX = newX; iY = newY; samples = 1; } timeout = 0; } else { timeout++; } } if (samples) { // Send event to user level event = (iX/samples)<<16 | (iY/samples); if (!cyg_mbox_tryput(lcd_panel_events_mbox_handle, (void *)event)) { diag_printf("LCD event lost: %x\n", event); } } *(volatile cyg_uint8 *)TOUCH_CTL = 0x00; // Disable drives while (*(volatile cyg_uint32 *)INTSR1 & INTSR1_EINT2) ; *(volatile cyg_uint8 *)TOUCH_CTL = 0x70; // Idle state (so interrupt works) cyg_thread_delay(10); cyg_drv_interrupt_unmask(CYGNUM_HAL_INTERRUPT_EINT2); } }
/*---------------------------------------------------------------*/ PROCESS_THREAD(null_app_process, ev, data) { static struct etimer rxtimer; PROCESS_BEGIN(); printf("Hello world Started.\n"); #ifdef SF_FEATURE_SHELL_OPT serial_shell_init(); remote_shell_init(); shell_reboot_init(); shell_blink_init(); shell_sky_init(); #endif app_conn_open(&nullApp_callback); #ifdef ADC_SENSOR static uint16_t samples[ADC_SAMPLES_PER_FRAME]={0}; uint8_t i; // static uint8_t samples_sorted_bytes[2*ADC_SAMPLES_PER_FRAME]; static uint8_t sample_num = 0; //increments from 0 to samples_per_frame-1 if (node_id != 0){ adc_on(); //adc_configure(0); //to sample reference voltage (Vref/2), ~2048. etimer_set( &rxtimer, (unsigned long)(CLOCK_SECOND/(ADC_SAMPLING_FREQ))); } else etimer_set(&rxtimer,CLOCK_SECOND/20); if(node_id != 0) { while(1) { PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&rxtimer)); etimer_reset(&rxtimer); samples[sample_num]=adc_sample(); sample_num++; if(sample_num == ADC_SAMPLES_PER_FRAME){ sample_num=0; /* * Byte order needs to be reversed because of low-endian system. * Can be done at AP level too, if needed. */ // for(i=0;i<ADC_SAMPLES_PER_FRAME;i++){ // samples_sorted_bytes[2*i]=(samples[i]>>8); // samples_sorted_bytes[2*i+1]= (samples[i]& 0xff); // } //app_conn_send(samples_sorted_bytes,sizeof(uint8_t)*ADC_SAMPLES_PER_FRAME*2); tdma_rdc_buf_ptr = 0; tdma_rdc_buf_send_ptr = 0; tdma_rdc_buf_full_flg = 0; app_conn_send(samples,sizeof(uint16_t)*ADC_SAMPLES_PER_FRAME/sizeof(uint8_t)); } } } #endif #ifdef I2C_SENSOR //static rtimer_clock_t rt, del; int i; static uint8_t MPU_status = 0; static uint8_t sample_count = 0; /* static uint8_t samples_sorted_bytes[14*MPU_SAMPLES_PER_FRAME],comp_samples_sorted_bytes[14*MPU_SAMPLES_PER_FRAME]; static uint8_t sample_num=0, uncomp_data_len=14*MPU_SAMPLES_PER_FRAME,comp_data_len; static uint8_t *st; */ static mpu_data sampleArray[MPU_SAMPLES_PER_FRAME]; if (node_id != 0){ MPU_status = 0; for(i = 0; i < 100 & (~MPU_status);i++) { MPU_status = mpu_enable(); } if (MPU_status == 0) printf("MPU could not be enabled.\n"); MPU_status = 0; for(i = 0; i < 100 & (~MPU_status);i++) { MPU_status = mpu_wakeup(); } if (MPU_status == 0) printf("MPU could not be awakened.\n"); etimer_set(&rxtimer, (unsigned long)(CLOCK_SECOND/MPU_SAMPLING_FREQ)); } else etimer_set(&rxtimer,CLOCK_SECOND/20); if(node_id != 0) { while(1){ PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&rxtimer)); etimer_reset(&rxtimer); mpu_data_union samples; int m=mpu_sample_all(&samples); app_conn_send((uint8_t *)(&samples),MPU_DATA_SIZE); /* sampleArray[sample_count] = samples.data; sample_count = sample_count + 1; if(sample_count == MPU_SAMPLES_PER_FRAME) { sample_count = 0; tdma_rdc_buf_clear(); app_conn_send(sampleArray,MPU_DATA_SIZE*MPU_SAMPLES_PER_FRAME); } */ /* st = &samples; for(i=0;i<7;i++){ samples_sorted_bytes[2*i+14*sample_num]=*(st+2*i+1); samples_sorted_bytes[2*i+1+14*sample_num]= *(st+2*i); } sample_num++; if(sample_num==MPU_SAMPLES_PER_FRAME){ sample_num=0; app_conn_send(samples_sorted_bytes,sizeof(uint8_t)*14*MPU_SAMPLES_PER_FRAME); } PRINTF("%d,%d,%d,%d,%d,%d,%d\n",samples.data.accel_x,samples.data.accel_y,samples.data.accel_z,samples.data.gyro_x,samples.data.gyro_y, samples.data.gyro_z,samples.data.temperature); */ // app_conn_send(&samples,sizeof(mpu_data)/sizeof(uint8_t)); } } #endif PROCESS_END(); }
int main(void) { uint8_t last_min = 0; cli(); DDRC = _BV(C_SCL); DDRD = _BV(D_LCD_BL) | _BV(D_LCD_SEL) | _BV(D_LCD_SCK) | _BV(D_LCD_MOSI) | _BV(D_LCD_RESET) | _BV(D_ALERT); #if (FOSC == 18432000UL) /* * Fosc = 18432000 * Fping = 100 Hz * * Fosc / Fping / 1024 = 180; */ set_timer2(_BV(CS22) | _BV(CS21) | _BV(CS20), 180); #elif (FOSC == 7372800UL) /* * Fosc = 7372800 * Fping = 100 Hz * * Fosc / Fping / 1024 = 72; */ set_timer2(_BV(CS22) | _BV(CS21) | _BV(CS20), 72); #elif (FOSC == 16000000UL) /* * Fosc = 16000000 * Fping = 100 Hz * * Fosc / Fping / 1024 = 156; */ set_timer2(_BV(CS22) | _BV(CS21) | _BV(CS20), 156); #else #error "unsupported FOSC freq" #endif twi_master_init(); twi_add_device(rtc_begin, rtc_end); twi_add_device(relay_begin, relay_end); sei(); lcd_init(); lcd_fill(0, 0, 131, 131, 0x000); ow_init(); ds18b20_init(); adc_sample(); set_point = 25 << 8; while (1) { ds18b20_ping(); if (last_min != time[1]) { temp_history[temp_history_idx] = ds18b20_temps[1]; temp_history_idx++; if (temp_history_idx == ARRAY_SIZE(temp_history)) temp_history_idx = 0; last_min = time[1]; } if (ph == 0) { ph = (uint32_t)adc_data[2] << PH_IIR_SHIFT; } else { ph -= ph >> PH_IIR_SHIFT; ph += adc_data[2]; } ui(); if (alert) PORTD |= _BV(D_ALERT); else PORTD &= ~_BV(D_ALERT); cli(); if (ds18b20_temps[1] < set_point) relays &= ~0x1; else if(ds18b20_temps[1] > (set_point + (1 << 4))) relays |= 0x1; sei(); } }
int main(void) { unsigned char adc_result; // Initialize the LCD lcd_init(); // Initialize the ADC adc_init(3); // Use the ADC to find a seed for rand(); adc_result = adc_sample(); srand(adc_result << 8 | adc_result); // Make a 16-bit number for srand() // Write splash screen lcd_writecommand(1); lcd_stringout("Melissa Ahn"); // Use lcd_moveto to start at an appropriate column //in the bottom row to appear centered lcd_moveto(1, 4); lcd_stringout("ee109 Lab6"); // Delay 1 second _delay_ms(1000); // Find a random initial position of the 'X' // n = 16; returns a value 0 - 15 int pos_x = rand() % 16; // Display the 'X' on the screen lcd_writecommand(1); lcd_moveto(0, pos_x); lcd_writedata('X'); //initializes carrot's position int pos_carrot = adc_sample() / 16;//rounds down int second_counter = 0; lcd_moveto(1, pos_carrot); lcd_writedata('^'); while (1) // Loop forever { // Do a conversion int new_pos_carrot = adc_sample() / 16; // Move '^' to new position if (pos_carrot != new_pos_carrot) { lcd_moveto(1, pos_carrot); lcd_writedata(' '); lcd_moveto(1, new_pos_carrot); lcd_writedata('^'); pos_carrot = new_pos_carrot; } // Delay _delay_ms(10); // Check if '^' is aligned with 'X' if (pos_carrot == pos_x) { second_counter++; //increase 10ms counter } else { second_counter = 0; //reset to 0 } if (second_counter != 0 && second_counter % 200 == 0) { lcd_moveto(1, 0); lcd_stringout("You won!!!"); while(1){} //infinite loop; game ends } } return 0; /* never reached */ }
float adc_sampleFloat(uint8_t pin) { return adc_sample(pin)/4096.0f; }
int main() { uint16_t adc_value[6]; uint8_t digit[6][4]; uint8_t i; uint8_t leds[9] = {0, 0, 0, 0, 0, 0, 0, 0, 0}; uint8_t imu_comm_ctr = 0; uint8_t uart_buffer[3] = {0, 0, 0}; uint8_t byte; // get the subsystems up and running uart_init(); adc_init(); leds_init(); timer_init(); timer_reset(); while (1) { // is it time to do a sample (has 1/10th of a second passed?) if (timer_get() >= 11520) { // yes! do the adc sample and send it off down the uart // sample all 6 channels for (i = 0; i < 6; i++) { adc_value[i] = adc_sample(i); } // convert to digits for (i = 0; i < 6; i++) { digit[i][3] = adc_value[i] / 1000; adc_value[i] = adc_value[i] % 1000; digit[i][2] = adc_value[i] / 100; adc_value[i] = adc_value[i] % 100; digit[i][1] = adc_value[i] / 10; adc_value[i] = adc_value[i] % 10; digit[i][0] = adc_value[i]; } // output to the uart uart_send('$'); // start of line character for (i = 0; i < 6; i++) { uart_send(digit[i][3] + 48); uart_send(digit[i][2] + 48); uart_send(digit[i][1] + 48); uart_send(digit[i][0] + 48); uart_send('\t'); } uart_send('\r'); uart_send('\n'); // increment the imu comm counter imu_comm_ctr++; // restart the timer timer_reset(); } // update imu comm led status if (imu_comm_ctr > 0) { leds[IMU_COMM] = !leds[IMU_COMM]; led_set(IMU_COMM, leds[IMU_COMM]); imu_comm_ctr = 0; } // try to get a byte from the uart if (uart_receive(&byte)) { // shift the buffer uart_buffer[0] = uart_buffer[1]; uart_buffer[1] = uart_buffer[2]; uart_buffer[2] = byte; // middle byte MUST be a '=' for any of these to be true if (uart_buffer[1] == '=') { switch (uart_buffer[0]) { case 'x': led_set(XBEE_COMM, uart_buffer[2] - 48); break; case 'g': led_set(GPS_LOCK, uart_buffer[2] - 48); break; case 'h': led_set(HEAD_LTS, uart_buffer[2] - 48); break; case 'b': led_set(BRAKE_LTS, uart_buffer[2] - 48); break; case 'l': led_set(LTURN_LTS, uart_buffer[2] - 48); break; case 'r': led_set(RTURN_LTS, uart_buffer[2] - 48); break; case 's': led_set(STARTER, uart_buffer[2] - 48); break; case 'n': led_set(HORN, uart_buffer[2] - 48); break; default: break; } } } } return 0; }
float adc_sampleBattery() { return adc_sample(ADC_BATTERY)*0.003; }
/* start sampling on all channels at the same time */ void start_sampling(void) { for (i = 0; i < 4; i++) adc_sample(adcchannels[i], 128); }
PROCESS_THREAD(debug_process, ev, data) { char line[MAX_LINE_LENGTH]; uint16_t read; uint8_t b; uint32_t flashAddress = 0; uint32_t flashCount = 0; uint32_t t = 0; PROCESS_BEGIN(); while (1) { PROCESS_YIELD(); while (dma_ring_buffer_readline(&g_debugUsartDmaInputRingBuffer, line, MAX_LINE_LENGTH)) { if (strcmp(line, "!CONNECT\n") == 0) { debug_write_line("+OK"); debug_write_line("!clear"); debug_write_line("!set name,dc-electronic-load"); debug_write_line("!set description,'DC Electonic Load'"); } else if (strcmp(line, "!RESET\n") == 0) { debug_write_line("+OK"); NVIC_SystemReset(); } #ifdef ADC_ENABLE else if (strcmp(line, "!ADCLAST\n") == 0) { debug_write("+OK "); debug_write_u16(lastAdcValue[0], 10); debug_write(","); debug_write_u16(lastAdcValue[1], 10); debug_write(","); debug_write_u16(lastAdcValue[2], 10); debug_write(","); debug_write_u16(lastAdcValue[3], 10); debug_write(","); debug_write_u16(setCurrentMilliamps, 10); debug_write_line(""); } else if (strcmp(line, "!ADCRAW\n") == 0) { debug_write("+OK "); debug_write_u16(adc_sample(ADC_CH0_SINGLE), 10); debug_write(","); debug_write_u16(adc_sample(ADC_CH1_SINGLE), 10); debug_write(","); debug_write_u16(adc_sample(ADC_CH2_SINGLE), 10); debug_write(","); debug_write_u16(adc_sample(ADC_CH3_SINGLE), 10); debug_write_line(""); } #endif #ifdef FAN_ENABLE else if (strncmp(line, "!FANSET ", 8) == 0) { uint8_t fanSetOverride = atoi(line + 8); fan_set(fanSetOverride); debug_write_line("+OK"); } else if (strcmp(line, "!FANGET\n") == 0) { debug_write("+OK "); debug_write_u8(fan_get(), 10); debug_write_line(""); } #endif #ifdef DISP6800_ENABLE else if (strcmp(line, "!DISPON\n") == 0) { disp6800_set_display_onoff(DISP6800_DISPLAY_ON); debug_write_line("+OK"); } else if (strcmp(line, "!DISPOFF\n") == 0) { disp6800_set_display_onoff(DISP6800_DISPLAY_OFF); debug_write_line("+OK"); } #endif #ifdef FLASH_ENABLE else if (strcmp(line, "!FLASHCLEAR\n") == 0) { flashsst25_erase_chip(); debug_write_line("+OK"); } else if (strncmp(line, "!FLASHWRITE ", 12) == 0) { flashAddress = atoi(line + 12); flashCount = FLASH_BLOCK_SIZE; debug_write_line("+READY"); t = time_ms(); while (1) { if (flashCount <= 0) { debug_write("+OK "); debug_write_u32(flashAddress, 10); debug_write_line(""); break; } if ((time_ms() - t) > 5000) { debug_write_line("-FAIL"); break; } if ((read = dma_ring_buffer_read(&g_debugUsartDmaInputRingBuffer, (uint8_t*)line, MIN(flashCount, sizeof(line)))) <= 0) { continue; } flashsst25_write(flashAddress, (uint8_t*)line, read); flashAddress += read; flashCount -= read; t = time_ms(); } } else if (strncmp(line, "!FLASHREAD ", 11) == 0) { flashAddress = atoi(line + 11); flashCount = FLASH_BLOCK_SIZE; debug_write_line("+OK"); flashsst25_read_begin(flashAddress); while (flashCount > 0) { b = flashsst25_read(); debug_write_bytes(&b, 1); flashCount--; } flashsst25_read_end(); } #endif else { debug_write("?Unknown command: "); debug_write_line(line); } } } PROCESS_END(); }