Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 23:28 17 Feb 2026 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : terminal concept for picomite whitout display

Author Message
tenij000
Regular Member

Joined: 30/05/2025
Location: Netherlands
Posts: 69
Posted: 01:53am 15 Feb 2026
Copy link to clipboard 
Print this post




little extra code send info to python
// Stuur het tekencommando naar de Python Terminal
   void DrawLine(int x1, int y1, int x2, int y2, int w, int c) {
   // We voegen 'w' (width) toe als 6e parameter
   printf("\033[DRAWL:%d,%d,%d,%d,%d,%d]\r\n", x1, y1, x2, y2, c, w);
   fflush(stdout);



import serial
import tkinter as tk
from tkinter import scrolledtext
import re

# --- CONFIGURATIE ---
SERIAL_PORT = 'COM7'
BAUD_RATE = 115200

class PicoTerminal:
   def __init__(self, master):
       self.master = master
       self.master.title("PicoMite Ultimate Console - Line Width & Color Update")
       self.master.geometry("900x950")

       # 1. INPUT BALK (Onderaan)
       self.input_frame = tk.Frame(master)
       self.input_frame.pack(side='bottom', fill='x', padx=5, pady=10)
       
       self.entry = tk.Entry(self.input_frame, font=("Consolas", 12))
       self.entry.pack(side='left', expand=True, fill='x', padx=5)
       self.entry.bind("<Return>", self.send_command)
       self.entry.focus_set()
       
       self.send_button = tk.Button(self.input_frame, text="Send", command=self.send_command, width=10)
       self.send_button.pack(side='right', padx=5)

       # 2. GRAFISCH CANVAS (Midden)
       self.canvas = tk.Canvas(master, height=500, bg="black", highlightthickness=1, highlightbackground="gray")
       self.canvas.pack(side='bottom', fill='both', padx=5, pady=5)

       # 3. TEKST OUTPUT (Boven)
       self.text_area = scrolledtext.ScrolledText(master, bg="black", fg="#00FF00", font=("Consolas", 10))
       self.text_area.pack(side='top', expand=True, fill='both', padx=5, pady=5)

       self.ser = None
       try:
           self.ser = serial.Serial(SERIAL_PORT, BAUD_RATE, timeout=0.01)
           self.text_area.insert(tk.END, f"--- Verbonden met {SERIAL_PORT} ---\n")
       except:
           self.text_area.insert(tk.END, f"FOUT: Kan {SERIAL_PORT} niet openen.\n")

       self.poll_serial()

   def send_command(self, event=None):
       cmd = self.entry.get()
       if self.ser and self.ser.is_open:
           self.ser.write((cmd + '\r\n').encode('utf-8'))
           self.entry.delete(0, tk.END)

   def m_color(self, mm_color):
       """Vertaal MMBasic kleurcodes naar Python/Tkinter kleuren"""
       try:
           c = int(mm_color)
           if c <= 0: return "black"
           # 24-bit & 16-bit Kleur-mapping
           if c == 16777215 or c == 65535: return "white"
           if c == 16711680 or c == 31: return "red"       # Rood (24b vs 16b)
           if c == 65280 or c == 2016: return "green"     # Groen
           if c == 255 or c == 63488: return "blue"       # Blauw
           if c == 16776960 or c == 2047: return "yellow" # Geel
           if c == 16711935: return "magenta"
           if c == 65535: return "cyan"
       except:
           pass
       return "white"

   def poll_serial(self):
       if self.ser and self.ser.is_open and self.ser.in_waiting > 0:
           try:
               raw_data = self.ser.read(self.ser.in_waiting)
               text = raw_data.decode('utf-8', errors='replace')

               # --- VERWERK COMMANDO'S ---

               # 1. LIJNEN: DRAWL:x1,y1,x2,y2,kleur,dikte
               # Zoekt naar 6 getallen gescheiden door komma's
               line_matches = re.findall(r"DRAWL:(-?\d+),(-?\d+),(-?\d+),(-?\d+),(-?\d+),(-?\d+)", text)
               for m in line_matches:
                   x1, y1, x2, y2, c, w = map(int, m)
                   dikte = max(1, w) # Zorg dat dikte minimaal 1 is
                   self.canvas.create_line(x1, y1, x2, y2, fill=self.m_color(c), width=dikte)

               # 2. BOXEN: DRAWB:x1,y1,x2,y2,kleur,vulling
               box_matches = re.findall(r"DRAWB:(-?\d+),(-?\d+),(-?\d+),(-?\d+),(-?\d+),(-?\d+)", text)
               for m in box_matches:
                   x1, y1, x2, y2, c, f = map(int, m)
                   f_col = self.m_color(f) if f != -1 else ""
                   self.canvas.create_rectangle(x1, y1, x2, y2, outline=self.m_color(c), fill=f_col, width=1)

               # 3. CIRKELS: DRAWC:x,y,radius,kleur,vulling
               circ_matches = re.findall(r"DRAWC:(-?\d+),(-?\d+),(-?\d+),(-?\d+),(-?\d+)", text)
               for m in circ_matches:
                   x, y, r, c, f = map(int, m)
                   f_col = self.m_color(f) if f != -1 else ""
                   self.canvas.create_oval(x-r, y-r, x+r, y+r, outline=self.m_color(c), fill=f_col, width=1)

               # Schone tekst tonen in het logvenster
               clean_text = re.sub(r"?\[?DRAW.*?\]\r\n", "", text)
               if clean_text:
                   self.text_area.insert(tk.END, clean_text)
                   self.text_area.see(tk.END)

           except Exception as e:
               # print(f"Error: {e}") # Voor debugging
               pass

       self.master.after(10, self.poll_serial)

if __name__ == "__main__":
   root = tk.Tk()
   app = PicoTerminal(root)
   root.mainloop()

Edited 2026-02-15 11:59 by tenij000
 
Print this page


To reply to this topic, you need to log in.

The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2026