LED displej – ovládání řadiče – první verze
authorFrantišek Kučera <franta-hg@frantovo.cz>
Tue Apr 24 21:02:52 2012 +0200 (2012-04-24)
changeset 16131d2652b241
parent 15 b166c6f49719
child 17 a594ee3c93a5
LED displej – ovládání řadiče – první verze
c++/led-displej/kompiluj.sh
c++/led-displej/led-displej
c++/led-displej/led-displej.cpp
java/ObrazkovyApplet/src/cz/frantovo/obrazkovyApplet/ObrazkovyApplet.form
java/ObrazkovyApplet/src/cz/frantovo/obrazkovyApplet/ObrazkovyApplet.java
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/c++/led-displej/kompiluj.sh	Tue Apr 24 21:02:52 2012 +0200
     1.3 @@ -0,0 +1,4 @@
     1.4 +#!/bin/bash
     1.5 +
     1.6 +g++ led-displej.cpp -o led-displej;
     1.7 +
     2.1 Binary file c++/led-displej/led-displej has changed
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/c++/led-displej/led-displej.cpp	Tue Apr 24 21:02:52 2012 +0200
     3.3 @@ -0,0 +1,64 @@
     3.4 +#include <stdlib.h>
     3.5 +#include <iostream>
     3.6 +
     3.7 +/**
     3.8 + * Slouží k ovládání LED displeje pomocí řadiče M5482 připojeného na LPT port.
     3.9 + * Používají se jen dva piny: DATA a CLOCK signál.
    3.10 + */
    3.11 +
    3.12 +/**
    3.13 + * = 1 → normální běh
    3.14 + * > 1 → zpomalené pro ladění
    3.15 + */
    3.16 +const int BRZDA = 100000;
    3.17 +
    3.18 +void zapisSeriove(bool hodnoty[]);
    3.19 +void zapisData(bool hodnota);
    3.20 +void zapisClock(bool hodnota);
    3.21 +void cekej(int mikroSekund);
    3.22 +
    3.23 +int main() {
    3.24 +	std::cout << "spouštím program LED Displej" << std::endl;
    3.25 +	
    3.26 +	bool hodnoty[] = {1,1,1,1,1,1,0,0,0,0,0,1,1,1,1,1,0,0,0,0,0,1,1,1,1,1,0,0,0,0,0,1,1,1,1,1};
    3.27 +	
    3.28 +	std::cout << "velikost pole: " << sizeof(hodnoty) << std::endl; // vypíše 36
    3.29 +	
    3.30 +	zapisSeriove(hodnoty);
    3.31 +}
    3.32 +
    3.33 +void zapisSeriove(bool hodnoty[]) {
    3.34 +	std::cout << "velikost pole ve funkci: " << sizeof(hodnoty) << std::endl; // vypíše 8
    3.35 +	for (int i = 0; i < sizeof(hodnoty); i++) {
    3.36 +		zapisData(hodnoty[i]);
    3.37 +		cekej(1);
    3.38 +		zapisClock(true);
    3.39 +		cekej(1);
    3.40 +		zapisClock(false);
    3.41 +		cekej(1);
    3.42 +		std::cout << "---" << std::endl;
    3.43 +	}
    3.44 +}
    3.45 +
    3.46 +void zapisData(bool hodnota) {
    3.47 +	std::cout << "DATA  = " << hodnota << std::endl;
    3.48 +	if (hodnota) {
    3.49 +		// TODO: zapsat na LPT
    3.50 +	} else {
    3.51 +		// TODO: zapsat na LPT
    3.52 +	}
    3.53 +}
    3.54 +
    3.55 +void zapisClock(bool hodnota) {
    3.56 +	std::cout << "CLOCK = " << hodnota << std::endl;
    3.57 +	if (hodnota) {
    3.58 +		// TODO: zapsat na LPT
    3.59 +	} else {
    3.60 +		// TODO: zapsat na LPT
    3.61 +	}
    3.62 +}
    3.63 +
    3.64 +void cekej(int mikroSekund) {
    3.65 +	usleep(mikroSekund*BRZDA);
    3.66 +}
    3.67 +
     4.1 --- a/java/ObrazkovyApplet/src/cz/frantovo/obrazkovyApplet/ObrazkovyApplet.form	Mon Mar 14 21:54:03 2011 +0100
     4.2 +++ b/java/ObrazkovyApplet/src/cz/frantovo/obrazkovyApplet/ObrazkovyApplet.form	Tue Apr 24 21:02:52 2012 +0200
     4.3 @@ -19,7 +19,7 @@
     4.4            <Group type="102" alignment="0" attributes="0">
     4.5                <EmptySpace max="-2" attributes="0"/>
     4.6                <Group type="103" groupAlignment="0" attributes="0">
     4.7 -                  <Component id="platno" alignment="0" max="32767" attributes="0"/>
     4.8 +                  <Component id="panel" alignment="0" max="32767" attributes="0"/>
     4.9                    <Group type="102" alignment="0" attributes="0">
    4.10                        <Component id="stavovyRadek" pref="243" max="32767" attributes="0"/>
    4.11                        <EmptySpace max="-2" attributes="0"/>
    4.12 @@ -34,7 +34,7 @@
    4.13        <Group type="103" groupAlignment="0" attributes="0">
    4.14            <Group type="102" alignment="1" attributes="0">
    4.15                <EmptySpace max="-2" attributes="0"/>
    4.16 -              <Component id="platno" max="32767" attributes="0"/>
    4.17 +              <Component id="panel" max="32767" attributes="0"/>
    4.18                <EmptySpace max="-2" attributes="0"/>
    4.19                <Group type="103" groupAlignment="3" attributes="0">
    4.20                    <Component id="odeslat" alignment="3" min="-2" max="-2" attributes="0"/>
    4.21 @@ -59,7 +59,7 @@
    4.22          <Property name="text" type="java.lang.String" value=" "/>
    4.23        </Properties>
    4.24      </Component>
    4.25 -    <Container class="javax.swing.JPanel" name="platno">
    4.26 +    <Container class="javax.swing.JPanel" name="panel">
    4.27  
    4.28        <Layout>
    4.29          <DimensionLayout dim="0">
     5.1 --- a/java/ObrazkovyApplet/src/cz/frantovo/obrazkovyApplet/ObrazkovyApplet.java	Mon Mar 14 21:54:03 2011 +0100
     5.2 +++ b/java/ObrazkovyApplet/src/cz/frantovo/obrazkovyApplet/ObrazkovyApplet.java	Tue Apr 24 21:02:52 2012 +0200
     5.3 @@ -1,12 +1,11 @@
     5.4  package cz.frantovo.obrazkovyApplet;
     5.5  
     5.6 +import java.awt.BorderLayout;
     5.7  import java.awt.Color;
     5.8  import java.awt.Graphics;
     5.9 -import java.awt.Graphics2D;
    5.10  import java.awt.event.MouseEvent;
    5.11  import java.awt.event.MouseListener;
    5.12  import java.awt.event.MouseMotionListener;
    5.13 -import java.awt.image.BufferedImage;
    5.14  import java.io.BufferedReader;
    5.15  import java.io.InputStreamReader;
    5.16  import java.io.OutputStream;
    5.17 @@ -18,6 +17,9 @@
    5.18  import javax.swing.UIManager;
    5.19  import javax.swing.UIManager.LookAndFeelInfo;
    5.20  
    5.21 +/**
    5.22 + * @author František Kučera, podnik.frantovo.cz
    5.23 + */
    5.24  public class ObrazkovyApplet extends javax.swing.JApplet implements MouseMotionListener, MouseListener {
    5.25  
    5.26  	private static final Logger log = Logger.getLogger(ObrazkovyApplet.class.getSimpleName());
    5.27 @@ -25,9 +27,7 @@
    5.28  	private int stareX;
    5.29  	private int stareY;
    5.30  	private boolean kresli;
    5.31 -	private Graphics g;
    5.32 -	private Graphics2D vystupniGrafika;
    5.33 -	private BufferedImage obrazek;
    5.34 +	private Platno platno;
    5.35  
    5.36  	private void odesliData() {
    5.37  		try {
    5.38 @@ -36,7 +36,7 @@
    5.39  			spojeni.setDoOutput(true);
    5.40  			spojeni.connect();
    5.41  			OutputStream os = spojeni.getOutputStream();
    5.42 -			ImageIO.write(obrazek, "png", os);
    5.43 +			ImageIO.write(platno.getObrazek(), "png", os);
    5.44  			os.flush();
    5.45  			os.close();
    5.46  
    5.47 @@ -52,8 +52,8 @@
    5.48  	}
    5.49  
    5.50  	private void smazGrafiku() {
    5.51 -		getVystupniGrafika().clearRect(0, 0, platno.getWidth(), platno.getHeight());
    5.52 -		g.clearRect(0, 0, platno.getWidth(), platno.getHeight());
    5.53 +		platno.getObrazek().getGraphics().fillRect(0, 0, panel.getWidth(), panel.getHeight());
    5.54 +		platno.repaint();
    5.55  	}
    5.56  
    5.57  	public void mouseDragged(MouseEvent e) {
    5.58 @@ -62,14 +62,12 @@
    5.59  
    5.60  		if (kresli) {
    5.61  			vypisStav("kreslím: " + stareX + "x" + stareY + "→" + x + "x" + y);
    5.62 -			g = platno.getGraphics();
    5.63 +
    5.64 +			Graphics g = platno.getObrazek().getGraphics();
    5.65  			g.setColor(Color.BLUE);
    5.66  			g.drawLine(stareX, stareY, x, y);
    5.67  
    5.68 -			platno.pa
    5.69 -
    5.70 -			
    5.71 -			getVystupniGrafika().drawLine(stareX, stareY, x, y);
    5.72 +			platno.repaint();
    5.73  		}
    5.74  
    5.75  		stareX = x;
    5.76 @@ -99,19 +97,6 @@
    5.77  		kresli = false;
    5.78  	}
    5.79  
    5.80 -	private Graphics2D getVystupniGrafika() {
    5.81 -		if (obrazek == null) {
    5.82 -			obrazek = new BufferedImage(platno.getWidth(), platno.getHeight(), BufferedImage.TYPE_INT_RGB);
    5.83 -		}
    5.84 -		if (vystupniGrafika == null) {
    5.85 -			vystupniGrafika = obrazek.createGraphics();
    5.86 -			vystupniGrafika.setBackground(Color.WHITE);
    5.87 -			vystupniGrafika.setColor(Color.BLUE);
    5.88 -			vystupniGrafika.clearRect(0, 0, platno.getWidth(), platno.getHeight());
    5.89 -		}
    5.90 -		return vystupniGrafika;
    5.91 -	}
    5.92 -
    5.93  	@Override
    5.94  	public void init() {
    5.95  
    5.96 @@ -131,7 +116,11 @@
    5.97  			java.awt.EventQueue.invokeAndWait(new Runnable() {
    5.98  
    5.99  				public void run() {
   5.100 +					platno = new Platno();
   5.101 +					platno.repaint();
   5.102  					initComponents();
   5.103 +					panel.setLayout(new BorderLayout());
   5.104 +					panel.add(platno, BorderLayout.CENTER);
   5.105  				}
   5.106  			});
   5.107  		} catch (Exception e) {
   5.108 @@ -139,8 +128,8 @@
   5.109  		}
   5.110  
   5.111  		/** Nastavení plátna */
   5.112 -		platno.addMouseMotionListener(ObrazkovyApplet.this);
   5.113 -		platno.addMouseListener(ObrazkovyApplet.this);
   5.114 +		panel.addMouseMotionListener(ObrazkovyApplet.this);
   5.115 +		panel.addMouseListener(ObrazkovyApplet.this);
   5.116  		log.log(Level.INFO, "plátno nastaveno");
   5.117  	}
   5.118  
   5.119 @@ -150,7 +139,7 @@
   5.120  
   5.121          odeslat = new javax.swing.JButton();
   5.122          stavovyRadek = new javax.swing.JLabel();
   5.123 -        platno = new javax.swing.JPanel();
   5.124 +        panel = new javax.swing.JPanel();
   5.125  
   5.126          odeslat.setText("Odeslat na server");
   5.127          odeslat.addActionListener(new java.awt.event.ActionListener() {
   5.128 @@ -161,16 +150,14 @@
   5.129  
   5.130          stavovyRadek.setText(" ");
   5.131  
   5.132 -        platno.setDoubleBuffered(true);
   5.133 -
   5.134 -        javax.swing.GroupLayout platnoLayout = new javax.swing.GroupLayout(platno);
   5.135 -        platno.setLayout(platnoLayout);
   5.136 -        platnoLayout.setHorizontalGroup(
   5.137 -            platnoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
   5.138 +        javax.swing.GroupLayout panelLayout = new javax.swing.GroupLayout(panel);
   5.139 +        panel.setLayout(panelLayout);
   5.140 +        panelLayout.setHorizontalGroup(
   5.141 +            panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
   5.142              .addGap(0, 388, Short.MAX_VALUE)
   5.143          );
   5.144 -        platnoLayout.setVerticalGroup(
   5.145 -            platnoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
   5.146 +        panelLayout.setVerticalGroup(
   5.147 +            panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
   5.148              .addGap(0, 255, Short.MAX_VALUE)
   5.149          );
   5.150  
   5.151 @@ -181,7 +168,7 @@
   5.152              .addGroup(layout.createSequentialGroup()
   5.153                  .addContainerGap()
   5.154                  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
   5.155 -                    .addComponent(platno, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
   5.156 +                    .addComponent(panel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
   5.157                      .addGroup(layout.createSequentialGroup()
   5.158                          .addComponent(stavovyRadek, javax.swing.GroupLayout.DEFAULT_SIZE, 243, Short.MAX_VALUE)
   5.159                          .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
   5.160 @@ -192,7 +179,7 @@
   5.161              layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
   5.162              .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
   5.163                  .addContainerGap()
   5.164 -                .addComponent(platno, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
   5.165 +                .addComponent(panel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
   5.166                  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
   5.167                  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
   5.168                      .addComponent(odeslat)
   5.169 @@ -210,7 +197,7 @@
   5.170  	}
   5.171      // Variables declaration - do not modify//GEN-BEGIN:variables
   5.172      private javax.swing.JButton odeslat;
   5.173 -    private javax.swing.JPanel platno;
   5.174 +    private javax.swing.JPanel panel;
   5.175      private javax.swing.JLabel stavovyRadek;
   5.176      // End of variables declaration//GEN-END:variables
   5.177  }