Nathan Monk / Mbed 2 deprecated CITY3032_Template

Dependencies:   mbed PinDetect

Files at this revision

API Documentation at this revision

Comitter:
reedas
Date:
Sat Oct 16 08:10:02 2021 +0000
Parent:
1:402b32a1025f
Child:
3:a14b2aa7546e
Commit message:
binary/digital/hex counter and light level display

Changed in this revision

PinDetect.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
middleware-emwin.lib Show annotated file Show diff for this revision Revisions of this file
stats_report.h Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/PinDetect.lib	Sat Oct 16 08:10:02 2021 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/reedas/code/PinDetect/#d552d2899765
--- a/main.cpp	Tue Nov 19 10:04:48 2019 +0000
+++ b/main.cpp	Sat Oct 16 08:10:02 2021 +0000
@@ -1,8 +1,25 @@
-/* Hello World! for the TextLCD Enhanced Library*/
+/* Hello World! for the Emwin TFT Library */
 
 #include "mbed.h"
 #include "GUI.h"
 #include "cy8ckit_028_tft.h"
+#include "PinDetect.h"
+
+PinDetect pb1(SWITCH2);
+uint8 counter = 0;
+AnalogIn lightLevel(P10_0);
+
+// Callback routine is interrupt activated by a debounced pb1 hit
+void pb1_hit_callback (void)
+{
+    counter = 0;
+}
+
+int readLightLevel() {
+    int lightPercent;
+    lightPercent = (lightLevel.read_u16()*100)/65535;
+    return lightPercent;
+    }
 
 void Display_Init(void)
 {
@@ -20,17 +37,38 @@
 
 int main()
 {
+
     /* Initialise EmWin driver*/
     GUI_Init();
 
     /* Initialise display */
     Display_Init();
+    pb1.mode(PullUp);
+    // Delay for initial pullup to take effect
+    ThisThread::sleep_for(10);
+    // Setup Interrupt callback functions for a pb hit
+    pb1.attach_deasserted(&pb1_hit_callback);
+
+    // Start sampling pb inputs using interrupts
+    pb1.setSampleFrequency();
 
 
     GUI_SetFont(GUI_FONT_8X16X2X2);
+    GUI_SetTextAlign(GUI_TA_HCENTER);
+    GUI_DispStringAt("Hello World!", 160, 200);
+    while(1) {
         GUI_SetTextAlign(GUI_TA_HCENTER);
-        GUI_DispStringAt("Hello World!", 160, 200);
+        GUI_DispHexAt(counter, 160, 70, 2);
+        GUI_SetTextAlign(GUI_TA_HCENTER);
+        GUI_DispDecAt(counter, 160, 130, 3);
+        GUI_SetTextAlign(GUI_TA_HCENTER);
+        GUI_DispBinAt(counter++, 160, 100, 8);
+        GUI_DispStringAt("Light is: ", 10, 160);
+        GUI_DispDec(readLightLevel(), 3);
+        GUI_DispString("%");
+        ThisThread::sleep_for(500);
 
+    }
 }
 
 
--- a/middleware-emwin.lib	Tue Nov 19 10:04:48 2019 +0000
+++ b/middleware-emwin.lib	Sat Oct 16 08:10:02 2021 +0000
@@ -1,1 +1,1 @@
-https://github.com/cypresssemiconductorco/middleware-emwin/#4f7b679659cb7696659d1a5bc084b1a5b3be6c70
+https://github.com/cypresssemiconductorco/middleware-emwin/#f628fb3e66c51b9a7abe0bfa2a6a46aff8efd062
--- a/stats_report.h	Tue Nov 19 10:04:48 2019 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,132 +0,0 @@
-/* mbed Microcontroller Library
- * Copyright (c) 2018 ARM Limited
- * SPDX-License-Identifier: Apache-2.0
- */
-
-#ifndef STATS_REPORT_H
-#define STATS_REPORT
-
-#include "mbed.h"
-
-/**
- *  System Reporting library. Provides runtime information on device:
- *      - CPU sleep, idle, and wake times
- *      - Heap and stack usage
- *      - Thread information
- *      - Static system information
- */
-class SystemReport {
-    mbed_stats_heap_t   heap_stats;
-    mbed_stats_cpu_t    cpu_stats;
-    mbed_stats_sys_t    sys_stats;
-
-    mbed_stats_thread_t *thread_stats;
-    uint8_t   thread_count;
-    uint8_t   max_thread_count;
-    uint32_t  sample_time_ms;
-
-public:
-    /**
-     *  SystemReport - Sample rate in ms is required to handle the CPU percent awake logic
-     */
-    SystemReport(uint32_t sample_rate) : max_thread_count(8), sample_time_ms(sample_rate)
-    {
-        thread_stats = new mbed_stats_thread_t[max_thread_count];
-
-        // Collect the static system information
-        mbed_stats_sys_get(&sys_stats);
-
-        printf("=============================== SYSTEM INFO  ================================\r\n");
-        printf("Mbed OS Version: %ld \r\n", sys_stats.os_version);
-        printf("CPU ID: 0x%lx \r\n", sys_stats.cpu_id);
-        printf("Compiler ID: %d \r\n", sys_stats.compiler_id);
-        printf("Compiler Version: %ld \r\n", sys_stats.compiler_version);
-
-        for (int i = 0; i < MBED_MAX_MEM_REGIONS; i++) {
-            if (sys_stats.ram_size[i] != 0) {
-                printf("RAM%d: Start 0x%lx Size: 0x%lx \r\n", i, sys_stats.ram_start[i], sys_stats.ram_size[i]);
-            }
-        }
-        for (int i = 0; i < MBED_MAX_MEM_REGIONS; i++) {
-            if (sys_stats.rom_size[i] != 0) {
-                printf("ROM%d: Start 0x%lx Size: 0x%lx \r\n", i, sys_stats.rom_start[i], sys_stats.rom_size[i]);
-            }
-        }
-    }
-
-    ~SystemReport(void)
-    {
-        free(thread_stats);
-    }
-
-    /**
-     *  Report on each Mbed OS Platform stats API
-     */
-    void report_state(void)
-    {
-        report_cpu_stats();
-        report_heap_stats();
-        report_thread_stats();
-
-        // Clear next line to separate subsequent report logs
-        printf("\r\n");
-    }
-
-    /**
-     *  Report CPU idle and awake time in terms of percentage
-     */
-    void report_cpu_stats(void)
-    {
-        static uint64_t prev_idle_time = 0;
-
-        printf("================= CPU STATS =================\r\n");
-
-        // Collect and print cpu stats
-        mbed_stats_cpu_get(&cpu_stats);
-
-        uint64_t diff = (cpu_stats.idle_time - prev_idle_time);
-        uint8_t idle = (diff * 100) / (sample_time_ms * 1000);  // usec;
-        uint8_t usage = 100 - ((diff * 100) / (sample_time_ms * 1000));  // usec;;
-        prev_idle_time = cpu_stats.idle_time;
-
-        printf("Idle: %d%% Usage: %d%% \r\n", idle, usage);
-    }
-
-    /**
-     *  Report current heap stats. Current heap refers to the current amount of
-     *  allocated heap. Max heap refers to the highest amount of heap allocated
-     *  since reset.
-     */
-    void report_heap_stats(void)
-    {
-        printf("================ HEAP STATS =================\r\n");
-
-        // Collect and print heap stats
-        mbed_stats_heap_get(&heap_stats);
-
-        printf("Current heap: %lu\r\n", heap_stats.current_size);
-        printf("Max heap size: %lu\r\n", heap_stats.max_size);
-    }
-
-    /**
-     *  Report active thread stats
-     */
-    void report_thread_stats(void)
-    {
-        printf("================ THREAD STATS ===============\r\n");
-
-        // Collect and print running thread stats
-        int count = mbed_stats_thread_get_each(thread_stats, max_thread_count);
-
-        for (int i = 0; i < count; i++) {
-            printf("ID: 0x%lx \r\n",        thread_stats[i].id);
-            printf("Name: %s \r\n",         thread_stats[i].name);
-            printf("State: %ld \r\n",       thread_stats[i].state);
-            printf("Priority: %ld \r\n",    thread_stats[i].priority);
-            printf("Stack Size: %ld \r\n",  thread_stats[i].stack_size);
-            printf("Stack Space: %ld \r\n", thread_stats[i].stack_space);
-        }
-    }
-};
-
-#endif // STATS_REPORT_H