Browse Source

first commit

Your Name 6 years ago
commit
01b4bba2f6

+ 5 - 0
Readme.md

@@ -0,0 +1,5 @@
+Install Minecraft Serialled status
+(attiny,arduino,teensy)
+
+test.py permet de tester le port avec un bouclage des pin4 et pin5
+

+ 49 - 0
raspberry/install.sh

@@ -0,0 +1,49 @@
+#!/bin/bash
+set -e
+Version=1.0
+##Configuration:##
+RPI3=YES # YES/NO
+SERIAL=NO #YES for serial (attiny), NO for USB (teensy/arduino)
+
+echo -e "Serial Minecraft LedStatus installer $Version:"
+echo
+echo -e "Install dependencies, libraries and tools :"
+
+if ! [ -x "$(command -v pip)" ]
+then
+sudo apt-get update
+sudo apt-get install python-pip -y
+fi
+
+if ! [ -x "$(command -v mcstatus)" ]
+then
+sudo pip install mcstatus
+fi
+
+echo -e "Done";
+
+
+echo
+if [ $RPI3 = "YES" ] && [ $SERIAL = "YES" ]
+then
+echo "Raspberry 3 Serial setup:"
+
+if ! grep "dtoverlay=pi3-disable-bt" /boot/config.txt >/dev/null
+then
+sudo bash -c 'echo "" >>/boot/config.txt'
+sudo bash -c 'echo "# Disable internal BT" >>/boot/config.txt'
+sudo bash -c 'echo "dtoverlay=pi3-disable-bt" >>/boot/config.txt'
+sudo systemctl disable hciuart >/dev/null
+sleep 1
+fi
+if ! grep "consoleblank=0" /boot/cmdline.txt >/dev/null
+then
+sudo bash -c 'sed -i -e "s/rootwait/rootwait consoleblank=0/g" /boot/cmdline.txt'
+fi
+if ! grep "console=serial0,115200" /boot/cmdline.txt >/dev/null
+then
+sudo bash -c 'sed -i -e "s/console=serial0,115200/console=serial0,115200/g" /boot/cmdline.txt'
+fi
+echo "Done"
+fi
+

+ 94 - 0
raspberry/scripts/mcledstatus/mcled_status

@@ -0,0 +1,94 @@
+#!/bin/bash
+Mode=USB # (UART / USB )
+Output=0
+Beep=0
+
+# echo "T" >/dev/ttyAMA0
+
+
+
+
+echo -n "Serial ledStatus v1.0 : "
+if [ $Mode = "UART" ]
+then
+echo -e "UART mode\n"
+Output=ttyAMA0
+else
+echo -e "USB mode\n"
+Output=ttyACM0
+fi
+
+stty -F /dev/ttyACM0 ispeed 9600 ospeed 9600 -ignpar cs8 -cstopb -echo
+
+ip=$(ifconfig | sed -En 's/127.0.0.1//;s/.*inet (addr:)?(([0-9]*\.){3}[0-9]*).*/\2/p')
+test=$(mcstatus $ip status | grep players: |  awk '{print$2}' |  sed 's/\x2F20//g')
+player1=$(mcstatus $ip status | grep players: | awk '{print$3}' | sed 's/\[\x2E//g')
+date_raw=$(date +%H%M)
+
+case $Beep in
+0*)
+echo "Buzzer:OFF"
+echo "z" >/dev/$Output
+sleep 1
+;;
+1*)
+echo "Buzzer:ON"
+echo "Z" >/dev/$Output
+sleep 1
+;;
+*)
+;;
+esac
+
+case $date_raw in
+[0700-2200]*)
+echo "Day:ON"
+echo "D" >/dev/$Output
+sleep 1
+;;
+[2201-0659]*)
+echo "Day:OFF"
+echo "N" >/dev/$Output
+sleep 1
+;;
+*)
+;;
+esac
+
+case $test in
+0*)
+echo "O"
+echo "0" >/dev/$Output
+;;
+1*)
+if [ $player1 = "Tristus51" ]
+then
+echo "Code:Tristan only"
+echo "T" >/dev/$Output
+echo $tristan
+elif [ $player1 = "MisterPig51" ]
+then
+echo "Code:MisterPig only"
+echo "V" >/dev/$Output
+elif [ $player1 = "BobBadin" ]
+then
+echo "Code: Ethan Only"
+echo "E" >/dev/$Output
+else
+echo "1" >/dev/$Output
+fi
+;;
+2*)
+echo "Code: two"
+echo "2" >/dev/$Output
+;;
+[3-9]|[1-2][0-0]*)
+echo "Code: further"
+echo "3" >/dev/$Output
+;;
+*)
+echo $test
+echo "Code: Error"
+echo "X" >/dev/$Output
+;;
+esac

+ 21 - 0
raspberry/test.py

@@ -0,0 +1,21 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+#
+# Test du port série
+import serial
+test_string = "Je teste le port série 1 2 3 4 5"
+port_list = ["/dev/ttyAMA0", "/dev/ttyAMA0", "/dev/ttyS0", "/dev/ttyS0",]
+for port in port_list:
+  try:
+    serialPort = serial.Serial(port, 9600, timeout = 2)
+    print "Port Série ", port, " ouvert pour le test :"
+    bytes_sent = serialPort.write(test_string)
+    print "Envoyé ", bytes_sent, " octets"
+    loopback = serialPort.read(bytes_sent)
+    if loopback == test_string:
+      print "Reçu ", len(loopback), "octets identiques. Le port", port, "fonctionne bien ! \n"
+    else:
+      print "Reçu des données incorrectes : ", loopback, " sur le port série ", port, " bouclé \n"
+    serialPort.close()
+  except IOError:
+    print "Erreur sur ", port, "\n"

+ 11 - 0
serial_arduino/arduino_code/serial_led_minecraft_tiny/buzzer.ino

@@ -0,0 +1,11 @@
+void buzzer_bip (int lng) {
+  if ( BUZ == 1 ) {
+    if ( Day_mode == 1 ) {
+      digitalWrite(BUZZER, HIGH);
+      delay(lng);
+      digitalWrite(BUZZER, LOW);
+    }
+  }
+}
+
+

+ 99 - 0
serial_arduino/arduino_code/serial_led_minecraft_tiny/color_code.ino

@@ -0,0 +1,99 @@
+void tristan()
+{ 
+     pixel_clear();
+     pixels.setPixelColor(0, pixels.Color(32,178,170)); 
+     pixels.show();
+     in_error=0;
+}
+
+void ethan()
+{
+     pixel_clear();
+     pixels.setPixelColor(2, pixels.Color(255,165,0)); // Moderately bright green color.
+     pixels.show(); // This sends the updated pixel color to the hardware.
+     in_error=0;
+}
+void valentin()
+{
+     pixel_clear();
+     pixels.setPixelColor(1, pixels.Color(255,0,255)); // Moderately bright green color.
+     pixels.show(); // This sends the updated pixel color to the hardware.
+     in_error=0;
+}
+
+void one()
+{
+     pixel_clear();
+     pixels.setPixelColor(0, pixels.Color(0,255,0)); // Moderately bright green color.
+     pixels.show(); // This sends the updated pixel color to the hardware.
+     in_error=0;
+}
+
+void two()
+{
+     pixel_clear();
+     pixels.setPixelColor(0, pixels.Color(0,255,0)); // Moderately bright green color.
+     pixels.setPixelColor(1, pixels.Color(0,255,0)); // Moderately bright green color.
+     pixels.show(); // This sends the updated pixel color to the hardware.
+     in_error=0;
+}
+
+void three()
+{
+     pixel_clear();
+     pixels.setPixelColor(0, pixels.Color(0,255,0)); // Moderately bright green color.
+     pixels.setPixelColor(1, pixels.Color(0,255,0)); // Moderately bright green color.
+     pixels.setPixelColor(2, pixels.Color(0,255,0)); // Moderately bright green color.
+     pixels.show(); // This sends the updated pixel color to the hardware.
+     in_error=0;
+}
+
+void more()
+{
+     pixel_clear();
+     pixels.setPixelColor(0, pixels.Color(0,0,255)); // Moderately bright green color.
+     pixels.setPixelColor(1, pixels.Color(0,0,255)); // Moderately bright green color.
+     pixels.setPixelColor(2, pixels.Color(0,0,255)); // Moderately bright green color.
+     pixels.show(); // This sends the updated pixel color to the hardware.
+     in_error=0;
+}
+
+void error_blink()
+{
+    if (flag == 0){
+     for(uint16_t i=0; i<pixels.numPixels(); i++) {
+      pixels.setPixelColor(i, pixels.Color(255,0,0)); // Moderately bright green color.
+      pixels.show();
+     }
+     flag=1 ;
+     delay (100);
+     }
+    if (flag == 1){
+      for(uint16_t i=0; i<pixels.numPixels(); i++) {
+      pixels.setPixelColor(i, pixels.Color(0,0,0)); // Moderately bright green color.
+      pixels.show();
+      }
+     flag=0 ;
+     delay (300);
+     }
+     error_count++;
+     if (error_count >= 5) {
+      buzzer_bip(30);
+       error_count=0;
+     }
+}
+
+void off_()
+{
+    pixel_clear();
+    in_error = 0;
+}
+
+void pixel_clear()
+{
+     for(uint16_t i=0; i<pixels.numPixels(); i++) {
+     pixels.setPixelColor(i, pixels.Color(0,0,0)); // Moderately bright green color.
+     pixels.show(); // This sends the updated pixel color to the hardware.
+     }
+}
+

+ 158 - 0
serial_arduino/arduino_code/serial_led_minecraft_tiny/serial_led_minecraft_tiny.ino

@@ -0,0 +1,158 @@
+// Serial Led pour Minecraft mcstatus
+//
+// devellopé pour attiny85, Teensy 3.1 et Arduino
+
+#define NUMPIXELS      3
+#define Bri_D 40
+#define Bri_N 5
+
+
+
+// Attiny:
+// ***
+// *** Define the RX and TX pins. Choose any two
+// *** pins that are unused. Try to avoid D0 (pin 5)
+// *** and D2 (pin 7) if you plan to use I2C.
+// ***
+//               ___
+//        PB5  *|+  |*  VCC
+//  -> RX PB3  *|   |*  PB2
+//  -> TX PB4  *|   |*  PB1   --> Buzzer
+//        GND  *|___|*  PB0   --> NeoPixel
+//
+
+#if defined (__AVR_ATtiny85__)
+#include <SoftwareSerial.h>
+#define LEDPIN         0
+#define BUZZER         1
+#define RX    3   // *** D3, Pin 2
+#define TX    4   // *** D4, Pin 3
+SoftwareSerial Serial(RX, TX);
+#endif
+
+//Teensy :
+#if defined (CORE_TEENSY) // Teensy 3.0 
+#define LEDPIN         9
+#define BUZZER        10
+#endif
+
+
+//Arduino
+// 168 and 328 Arduinos
+#if defined(__AVR_ATmega168__) ||defined(__AVR_ATmega168P__) ||defined(__AVR_ATmega328P__)
+#define LEDPIN         11
+#define BUZZER         12
+#endif
+
+
+#include <Adafruit_NeoPixel.h>
+#ifdef __AVR__
+#include <avr/power.h>
+#endif
+
+int flag = 0;
+int in_error = 0;
+int lng = 0;
+int error_count = 0;
+int Day_mode = 0;
+int BUZ = 0;
+
+Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, LEDPIN, NEO_GRB + NEO_KHZ800);
+
+int incomingByte;      // a variable to read incoming serial data into
+void setup() {
+#if defined (__AVR_ATtiny85__)
+  if (F_CPU == 16000000) clock_prescale_set(clock_div_1);
+#endif
+
+  // initialize serial communication:
+  Serial.begin(9600);
+  // initialize the LED pin as an output:
+  pixels.begin(); // This initializes the NeoPixel library.
+  pixels.setBrightness(Bri_D);
+  // init buzzer
+  pinMode(BUZZER, OUTPUT);
+  #if defined (CORE_TEENSY)
+  BUZ=1;Day_mode=1;buzzer_bip(100);
+  #endif
+  off_();
+}
+
+
+void loop() {
+  // see if there's incoming serial data:
+  if (Serial.available() > 0) {
+    // read the oldest byte in the serial buffer:
+    incomingByte = Serial.read();
+    Serial.println(incomingByte, DEC); //debug
+
+    switch (incomingByte) {
+      case 68: //D = DAY
+        pixels.setBrightness(Bri_D);
+        pixels.show();
+        Day_mode = 1;
+        break;
+      case 78: //N = NIGHT
+        pixels.setBrightness(Bri_N);
+        pixels.show();
+        Day_mode = 0;
+        break;
+      case 48: //0 = off
+        off_();
+        break;
+      case 84: //T
+        tristan();
+        buzzer_bip(10);
+        break;
+      case 86: //V
+        valentin();
+        buzzer_bip(10);
+        break;
+      case 69: //E
+        ethan();
+        buzzer_bip(10);
+        break;
+      case 49: //1
+        one();
+        buzzer_bip(10);
+        break;
+      case 50: //2
+        two();
+        buzzer_bip(10);
+        break;
+      case 51: //3
+        three();
+        buzzer_bip(10);
+        break;
+      case 52: //4
+        more();
+        buzzer_bip(10);
+        break;
+      case 88: //X
+        in_error = 1;
+        break;
+      case 90:
+        BUZ = 1;
+        break;
+      case 122:
+        BUZ = 0;
+        break;
+      case 120:
+        in_error = 2;
+        break;
+    }
+  }
+
+  if ( in_error == 1)
+  {
+    error_blink();
+  }
+  if ( in_error == 2)
+  {
+    pixels.setBrightness(Bri_N);
+    error_blink();
+  }
+
+}
+
+

BIN
serial_arduino/deps/Arduino15.tar.xz


BIN
serial_arduino/deps/libraries.tar.xz