diff --git a/.gitignore b/.gitignore index adefc18..f9463f4 100644 --- a/.gitignore +++ b/.gitignore @@ -34,13 +34,15 @@ docs/* *.out *.app -#VSCode +# VSCode .vscode/* .history/ *.vsix *.workspace -# Build artifacts and cache -build/ +# Tool-generated files .cache/ -compile_commands.json \ No newline at end of file +compile_commands.json + +# Build directories +build/ diff --git a/example/advanced/Power_Measurements/Display/Display.ino b/example/advanced/Power_Measurements/Display/Display.ino index c455fc4..7cab3a0 100644 --- a/example/advanced/Power_Measurements/Display/Display.ino +++ b/example/advanced/Power_Measurements/Display/Display.ino @@ -3,7 +3,7 @@ Dezibot dezibot = Dezibot(); // How many times to run a command on the display consecutively; -const uint16_t iterations = 5000; +const uint16_t iterations = 1000; void setup() { dezibot.begin(); @@ -23,4 +23,10 @@ void loop() { dezibot.display.println(iter); } delay(10); + //Completely off + dezibot.display.clear(); + sleep(10); + //Completely on + dezibot.display.invertColor(); + sleep(10); } \ No newline at end of file diff --git a/example/advanced/Power_Measurements/ESP32_baseline/ESP32_baseline.ino b/example/advanced/Power_Measurements/ESP32_baseline/ESP32_baseline.ino index e587853..0144439 100644 --- a/example/advanced/Power_Measurements/ESP32_baseline/ESP32_baseline.ino +++ b/example/advanced/Power_Measurements/ESP32_baseline/ESP32_baseline.ino @@ -1,10 +1,10 @@ #include "Dezibot.h" -#include "esp_pm.h" +#include "esp_pm.h" #include "esp_task_wdt.h" Dezibot dezibot; -const uint16_t cycleTime = 2e4; //20000 ms = 20 s +const uint16_t cycleTime = 20e3; esp_pm_lock_handle_t cpuFreqLock; esp_pm_lock_handle_t apbFreqLock; @@ -12,39 +12,39 @@ esp_pm_lock_handle_t lightSleepLock; static bool pmLocksCreated = false; -void stress_task0(void *pvParameters) { - // Register ourselves with the task watchdog - if (esp_task_wdt_add(NULL) != ESP_OK) { - Serial.println("Failed to add task 0 to TWDT"); - } - while (1) { +void stress_task(void *pvParameters) { + // Register with task watchdog + ESP_ERROR_CHECK(esp_task_wdt_add(NULL)); + + // Variables for load generation volatile uint32_t x = 0; - for (uint32_t i = 0; i < 10000; i++) { - x += i; + TickType_t last_wake_time = xTaskGetTickCount(); + + while (1) { + // Compute-intensive period + for (uint32_t i = 0; i < 10000; i++) { + x += i; + // Mix in some memory operations + if (i % 100 == 0) { + // Force cache misses occasionally + void* temp = malloc(32); + if (temp) { + free(temp); + } + } + } + + // Reset watchdog + ESP_ERROR_CHECK(esp_task_wdt_reset()); + } - esp_task_wdt_reset(); - } -} - -void stress_task1(void *pvParameters) { - // Register ourselves with the task watchdog - if (esp_task_wdt_add(NULL) != ESP_OK) { - Serial.println("Failed to add task 0 to TWDT"); - } - while (1) { - volatile uint32_t x = 0; - for (uint32_t i = 0; i < 10000; i++) { - x += i; - } - esp_task_wdt_reset(); - } } void setup() { Serial.begin(115200); - while (!Serial) { - ; - } + // while (!Serial) { + // ; + // } uint32_t Freq = getCpuFrequencyMhz(); Serial.print("CPU Freq = "); Serial.print(Freq); @@ -87,6 +87,17 @@ void setup() { Serial.end(); } +void blip_io(int times) { + constexpr int ioPin = 17; + pinMode(ioPin, OUTPUT); + for(int i = 0; i 2) + j = 0; + else + j = 1; + + if (j < 1 ) + j = 1; + else + j = 0; + } +#ifdef POUT + pout(n4, j, j, x1, x2, x3, x4); +#endif + +/* MODULE 5: omitted */ + +/* MODULE 6: integer arithmetic */ + + j = 1; + k = 2; + l = 3; + + for (i = 1; i <= n6; i += 1) { + j = j * (k - j) * (l -k); + k = l * k - (l - j) * k; + l = (l - k) * (k + j); + + e1[l - 2] = j + k + l; /* C arrays are zero based */ + e1[k - 2] = j * k * l; + } +#ifdef POUT + pout(n6, j, k, e1[0], e1[1], e1[2], e1[3]); +#endif + +/* MODULE 7: trig. functions */ + + x = y = 0.5; + + for(i = 1; i <= n7; i +=1) { + x = t * atan(t2*sin(x)*cos(x)/(cos(x+y)+cos(x-y)-1.0)); + y = t * atan(t2*sin(y)*cos(y)/(cos(x+y)+cos(x-y)-1.0)); + } +#ifdef POUT + pout(n7, j, k, x, x, y, y); +#endif + +/* MODULE 8: procedure calls */ + + x = y = z = 1.0; + + for (i = 1; i <= n8; i +=1) + p3(x, y, &z); +#ifdef POUT + pout(n8, j, k, x, y, z, z); +#endif + +/* MODULE9: array references */ + + j = 1; + k = 2; + l = 3; + + e1[0] = 1.0; + e1[1] = 2.0; + e1[2] = 3.0; + + for(i = 1; i <= n9; i += 1) + p0(); +#ifdef POUT + pout(n9, j, k, e1[0], e1[1], e1[2], e1[3]); +#endif + +/* MODULE10: integer arithmetic */ + + j = 2; + k = 3; + + for(i = 1; i <= n10; i +=1) { + j = j + k; + k = j + k; + j = k - j; + k = k - j - j; + } +#ifdef POUT + pout(n10, j, k, x1, x2, x3, x4); +#endif + +/* MODULE11: standard functions */ + + x = 0.75; + for(i = 1; i <= n11; i +=1) + x = sqrt( exp( log(x) / t1)); + +#ifdef POUT + pout(n11, j, k, x, x, x, x); +#endif +} + +pa(e) +double e[4]; +{ + register int j; + + j = 0; + lab: + e[0] = ( e[0] + e[1] + e[2] - e[3] ) * t; + e[1] = ( e[0] + e[1] - e[2] + e[3] ) * t; + e[2] = ( e[0] - e[1] + e[2] + e[3] ) * t; + e[3] = ( -e[0] + e[1] + e[2] + e[3] ) / t2; + j += 1; + if (j < 6) + goto lab; +} + + +p3(x, y, z) +double x, y, *z; +{ + x = t * (x + y); + y = t * (x + y); + *z = (x + y) /t2; +} + + +p0() +{ + e1[j] = e1[k]; + e1[k] = e1[l]; + e1[l] = e1[j]; +} + +#ifdef POUT +pout(n, j, k, x1, x2, x3, x4) +int n, j, k; +double x1, x2, x3, x4; +{ + printf("%6d%6d%6d %5e %5e %5e %5e\n", + n, j, k, x1, x2, x3, x4); +} +#endif diff --git a/example/advanced/Power_Measurements/IR_LED/IR_LED.ino b/example/advanced/Power_Measurements/IR_LED/IR_LED.ino index 3bffc84..cc19a12 100644 --- a/example/advanced/Power_Measurements/IR_LED/IR_LED.ino +++ b/example/advanced/Power_Measurements/IR_LED/IR_LED.ino @@ -9,15 +9,26 @@ void setup() { dezibot.infraredLight.begin(); } +void blink_times(int times) { + constexpr int ioPin = 17; + pinMode(ioPin, OUTPUT); + for(int i = 0; i + +/* +╔══════════════════════════════════════════════════════════════════════════════╗ +║ WARNING: This example controls the RGB-LEDs directly, bypassing the ║ +║ MultiColorLight component. This is not recommended for normal use, as it ║ +║ bypasses the safety checks and color normalization. This is only intended ║ +║ for diagnostic purposes. ║ +╚══════════════════════════════════════════════════════════════════════════════╝ +*/ + +Adafruit_NeoPixel rgbLeds(3, 48); + +void setup() { rgbLeds.begin(); } + +void loop() { + // Ramp up the brightness of each color channel + // Allows for the PWM behaviour to quickly be observed on an oscilloscope + // Red + for (int bri = 0; bri < 0xFF; bri += 0x1) { + rgbLeds.setPixelColor(0, rgbLeds.Color(bri, 0, 0)); + rgbLeds.show(); + delay(10); + } + // Red + for (int bri = 0; bri < 0xFF; bri += 0x1) { + rgbLeds.setPixelColor(0, rgbLeds.Color(0, bri, 0)); + rgbLeds.show(); + delay(10); + } + // Blue + for (int bri = 0; bri < 0xFF; bri += 0x1) { + rgbLeds.setPixelColor(0, rgbLeds.Color(0, 0, bri)); + rgbLeds.show(); + delay(10); + } + // Combinations of the color channels + // Yellow (Red + Green) + for (int bri = 0; bri < 0xFF; bri += 0x1) { + rgbLeds.setPixelColor(0, rgbLeds.Color(bri, bri, 0)); + rgbLeds.show(); + delay(10); + } + // Purple (Red + Blue) + for (int bri = 0; bri < 0xFF; bri += 0x1) { + rgbLeds.setPixelColor(0, rgbLeds.Color(bri, 0, bri)); + rgbLeds.show(); + delay(10); + } + // Cyan (Green + Blue) + for (int bri = 0; bri < 0xFF; bri += 0x1) { + rgbLeds.setPixelColor(0, rgbLeds.Color(0, bri, bri)); + rgbLeds.show(); + delay(10); + } + // White (Red + Green + Blue) + for (int bri = 0; bri < 0xFF; bri += 0x1) { + rgbLeds.setPixelColor(0, rgbLeds.Color(bri, bri, bri)); + rgbLeds.show(); + delay(10); + } + + // Now some constant states for comparable measurements + // Full brightness R+G+B + rgbLeds.setPixelColor(0, rgbLeds.Color(255, 255, 255)); + rgbLeds.show(); + sleep(5); + // Half brightness R+G+B + rgbLeds.setPixelColor(0, rgbLeds.Color(127, 127, 127)); + rgbLeds.show(); + sleep(5); + // Minimum brightness R+G+B + rgbLeds.setPixelColor(0, rgbLeds.Color(1, 1, 1)); + rgbLeds.show(); + sleep(5); + // Off (baseline) + rgbLeds.setPixelColor(0, rgbLeds.Color(0, 0, 0)); + rgbLeds.show(); + sleep(5); +} diff --git a/example/advanced/Power_Measurements/VEML6040/VEML6040.ino b/example/advanced/Power_Measurements/VEML6040/VEML6040.ino index 6c821be..07a87e1 100644 --- a/example/advanced/Power_Measurements/VEML6040/VEML6040.ino +++ b/example/advanced/Power_Measurements/VEML6040/VEML6040.ino @@ -3,7 +3,7 @@ Dezibot dezibot; void setup() { - dezibot.lightDetection.begin(); + dezibot.colorDetection.begin(); //dezibot.motion.detection.end(); // put your setup code here, to run once: Serial.begin(115200); @@ -13,7 +13,7 @@ void setup() { } delay(1000); // Test if VEML6040 is working correctly - char light_value = dezibot.lightDetection.getValue(DL_FRONT); + char light_value = dezibot.colorDetection.getColorValue(VEML_WHITE); if (light_value != UINT16_MAX) { Serial.printf("Light detection seems to be working (detected value: %d). Starting measurements...\r\n", light_value); } else { @@ -29,6 +29,6 @@ void setup() { void loop() { // put your main code here, to run repeatedly: - dezibot.lightDetection.getValue(DL_FRONT); + dezibot.colorDetection.getColorValue(VEML_WHITE); delay(10); } \ No newline at end of file diff --git a/example/advanced/Power_Measurements/WLAN/WLAN.ino b/example/advanced/Power_Measurements/WLAN/WLAN.ino index 26b10a4..180b2aa 100644 --- a/example/advanced/Power_Measurements/WLAN/WLAN.ino +++ b/example/advanced/Power_Measurements/WLAN/WLAN.ino @@ -3,40 +3,46 @@ Dezibot dezibot = Dezibot(); -const uint16_t cycleTime = 5e3; //5000 ms = 5 s +void blip_io(int times) { + constexpr int ioPin = 17; + pinMode(ioPin, OUTPUT); + for(int i = 0; i