From cff4ba2cde77a3c4c7ec19b5c29f14f5d22ab391 Mon Sep 17 00:00:00 2001 From: lemairec Date: Sat, 15 Apr 2017 19:08:37 +0200 Subject: [PATCH] Commit --- .gitignore | 3 + lib/MP3Player_KT403A/MP3Player_KT403A.cpp | 14 +-- src/rasika.cpp | 131 ++++++++++++++++++---- vim | 42 +++++++ 4 files changed, 163 insertions(+), 27 deletions(-) create mode 100644 .gitignore create mode 100755 vim diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..03d512a --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +.pioenvs/* +*.DS_Store +*.swp diff --git a/lib/MP3Player_KT403A/MP3Player_KT403A.cpp b/lib/MP3Player_KT403A/MP3Player_KT403A.cpp index f1b2fa8..d581db8 100755 --- a/lib/MP3Player_KT403A/MP3Player_KT403A.cpp +++ b/lib/MP3Player_KT403A/MP3Player_KT403A.cpp @@ -300,13 +300,13 @@ uint8_t QueryPlayStatus(void) { c[i] = mp3.read(); i++; - delay(1); - if (i == 10) break; -// Serial.print(" 0x"); -// Serial.print(c[i], HEX); + delay(1); + if (i == 10) break; + // Serial.print(" 0x"); + // Serial.print(c[i], HEX); } -// Serial.println(" "); - + // Serial.println(" "); + if(c[3] == 0x3C || c[3] == 0x3D || c[3] == 0x3E) { return 0; @@ -315,4 +315,4 @@ uint8_t QueryPlayStatus(void) { return 1; } -} \ No newline at end of file +} diff --git a/src/rasika.cpp b/src/rasika.cpp index 9a7a039..da07710 100755 --- a/src/rasika.cpp +++ b/src/rasika.cpp @@ -25,7 +25,18 @@ const byte EVENEMENT_PRESSE = 1; const byte EVENEMENT_RELACHE = 2; - +bool endOfSong(){ + int a=mp3.read(); + bool res = (a !=-1); + if(res){ + Serial.println("end of song "); + Serial.println(a); + for(int i = 0; i < 10; ++i){ + int a=mp3.read(); + } + } + return res; +} int lirePoussoirs() @@ -88,23 +99,31 @@ void inde(){ analogWrite(BLUEPIN, 0); analogWrite(GREENPIN,0); + SpecifyMusicPlay(1); + bool play = true; // fade from red to yellow - for (int g = 0; g < 256; g++) { - analogWrite(GREENPIN, g); - delay(FADESPEED); - } - for( int i=0; i0; r--) { - analogWrite(REDPIN, r); - delay(FADESPEED); + play = play && !endOfSong(); if(!play){ break; } + for( int i=0; i0; r--) { + analogWrite(REDPIN, r); + delay(FADESPEED); + play = play && !endOfSong(); if(!play){ break; } + } } + play = play && !endOfSong(); if(!play){ break; } } analogWrite(REDPIN, 0); analogWrite(BLUEPIN, 0); @@ -122,19 +141,24 @@ void belgique(){ analogWrite(REDPIN, 200); delay(500); - for( int i=0; i0; g--) { analogWrite(GREENPIN, g); delay(FADESPEED); } + play = play && !endOfSong(); if(!play){ break; } for (int r = 200; r<256; r++) { analogWrite(REDPIN, r); delay(FADESPEED); } + play = play && !endOfSong(); if(!play){ break; } for (int r = 256; r>200; r--) { analogWrite(REDPIN, r); delay(FADESPEED); } + play = play && !endOfSong(); if(!play){ break; } for (int g = 0; g < 256; g++) { analogWrite(GREENPIN, g); delay(FADESPEED); @@ -146,7 +170,6 @@ void belgique(){ Serial.println("finbelgique"); } - void angleterre(){ Serial.println("angleterre"); analogWrite(REDPIN, 0); @@ -154,9 +177,8 @@ void angleterre(){ analogWrite(GREENPIN,0); analogWrite(WHITEPIN,0); SpecifyMusicPlay(4); - int a=mp3.read(); - for(int i= 0;i<39;i++){ - + bool play = true; + while(play){ analogWrite(REDPIN, 255); analogWrite(BLUEPIN, 0); delay(125); @@ -167,6 +189,7 @@ void angleterre(){ analogWrite(GREENPIN,255); analogWrite(WHITEPIN,255); delay(125); + play = play && !endOfSong(); if(!play){ break; } analogWrite(WHITEPIN,0); analogWrite(REDPIN, 0); analogWrite(BLUEPIN, 0); @@ -178,6 +201,7 @@ void angleterre(){ delay(125); analogWrite(BLUEPIN, 0); delay(75); + play = play && !endOfSong(); if(!play){ break; } } delay(1000); analogWrite(REDPIN, 125); @@ -323,4 +347,71 @@ void loop(){ } delay(3); -} +} + + + + + +void setup2() +{ + mp3.begin(9600); + Serial.begin(9600); + delay(100); + + SelectPlayerDevice(0x02); // Select SD card as the player device. + SetVolume(0x0E); // Set the volume, the range is 0x00 to 0x1E. +} + +void loop2() +{ + char recvChar = 0; + while(Serial.available()) + { + recvChar = Serial.read(); + } + Serial.print("Send: "); + Serial.println( recvChar ); + + switch (recvChar) + { + case '1': + SpecifyMusicPlay(1); + Serial.println("Specify the music index to play"); + break; + case '2': + PlayPause(); + Serial.println("Pause the MP3 player"); + break; + case '3': + PlayResume(); + Serial.println("Resume the MP3 player"); + break; + case '4': + PlayNext(); + Serial.println("Play the next song"); + break; + case '5': + PlayPrevious(); + Serial.println("Play the previous song"); + break; + case '6': + PlayLoop(); + Serial.println("Play loop for all the songs"); + break; + case '7': + IncreaseVolume(); + Serial.println("Increase volume"); + break; + case '8': + DecreaseVolume(); + Serial.println("Decrease volume"); + break; + default: + break; + } + + delay(1000); + + printReturnedData(); +} diff --git a/vim b/vim new file mode 100755 index 0000000..247f917 --- /dev/null +++ b/vim @@ -0,0 +1,42 @@ +#!/usr/bin/env python + +import sys, optparse, subprocess, urllib2, os, os.path, errno, zipfile, string, json, platform, shutil, tarfile, urlparse, tempfile, multiprocessing +from subprocess import Popen, PIPE +import argparse +import sys + +def callWithoutPrint(cmdline): + ret = subprocess.call(cmdline, shell=True) + if ret != 0: + print >> sys.stderr, 'Running: ' + cmdline + ' failed with exit code ' + str(ret) + '!' + return ret + +def call(cmdline): + print 'Running: ' + cmdline + callWithoutPrint(cmdline) + + +class VimExec(object): + + def __init__(self): + parser = argparse.ArgumentParser( description='WeedVision'); + parser.add_argument('command', help='Subcommand to run' + , choices=['vim_f5', 'vim_f6', 'vim_f7', 'vim_f8']); + args = parser.parse_args(sys.argv[1:2]) + if not hasattr(self, args.command): + print 'Unrecognized command' + parser.print_help() + exit(1) + getattr(self, args.command)() + + + + def vim_f5(self): + call('platformio run -t upload && platformio device monitor'); + + def vim_f6(self): + call('python test.py'); + + +if __name__ == '__main__': + VimExec()