#include #include "Nextion.h" #include "HID-Project.h" #include #include #include #include "TimedAction.h" uint32_t Volume; String mySt; String myString; NexButton vol_up=NexButton(0,4,"vol_up"); NexButton vol_down=NexButton(0,5,"vol_down"); NexButton prev_button=NexButton(0,1,"prev_b"); NexDSButton toggle_button=NexDSButton(0,14,"pause_b"); NexButton next_button=NexButton(0,2,"next_b"); NexButton mute_button=NexButton(0,13,"mute"); //NexButton page_up=NexButton(1,7,"page_up"); //NexButton page_down=NexButton(1,8,"page_do"); NexButton win_lock=NexButton(0,10,"win_lock"); NexText win_unlock=NexText(1,1,"lock"); NexVariable win_val=NexVariable(0,0,"lockval"); NexVariable vol_val=NexVariable(0,14,"va0"); NexVariable page_val=NexVariable(0,14,"pageval"); NexNumber vol_dis=NexNumber(0,12,"vol_dis"); NexText info=NexText(0,3,"info"); void read_it(); TimedAction read_it_action=TimedAction(1000, read_it); NexTouch *nex_listen_list[] = { &vol_up, &vol_down, &prev_button, &toggle_button, &next_button, //&page_up, //&page_down, &win_lock, &win_unlock, &mute_button, NULL }; uint32_t vol_Status; void vol_upPopCallback(void *ptr){ vol_val.getValue(&vol_Status); Serial.println("up"); while (vol_Status>0){ Consumer.write(MEDIA_VOLUME_UP); Consumer.write(MEDIA_VOLUME_UP); Consumer.write(MEDIA_VOLUME_UP); Consumer.write(MEDIA_VOLUME_UP); Consumer.write(MEDIA_VOLUME_UP); Volume=Volume+10; if(Volume>100){ Volume=100; } vol_dis.setValue(Volume); vol_val.getValue(&vol_Status); delay(100); } EEPROM.write(0,Volume); } void vol_downPopCallback(void *ptr){ vol_val.getValue(&vol_Status); Serial.println("down"); while (vol_Status>0){ Consumer.write(MEDIA_VOLUME_DOWN); Consumer.write(MEDIA_VOLUME_DOWN); Consumer.write(MEDIA_VOLUME_DOWN); Consumer.write(MEDIA_VOLUME_DOWN); Consumer.write(MEDIA_VOLUME_DOWN); Volume=Volume-10; if(Volume>100){ Volume=0; } vol_dis.setValue(Volume); vol_val.getValue(&vol_Status); delay(100); } EEPROM.write(0,Volume); } void prev_call(void *ptr){ toggle_button.setValue(0); Consumer.write(MEDIA_PREV); } void toggle_call(void *ptr){ Consumer.write(MEDIA_PLAY_PAUSE); } void next_call(void *ptr){ toggle_button.setValue(0); Consumer.write(MEDIA_NEXT); } /*void page_up_call(void *ptr){ page_val.getValue(&vol_Status); Serial.println("up"); while (vol_Status>0){ Keyboard.write(HID_KEYBOARD_UPARROW); page_val.getValue(&vol_Status); delay(50); } }*/ /*void page_down_call(void *ptr){ page_val.getValue(&vol_Status); Serial.println("down"); while (vol_Status>0){ Keyboard.write(HID_KEYBOARD_DOWNARROW); page_val.getValue(&vol_Status); delay(50); } }*/ void win_lock_call(void *ptr){ Keyboard.press(KEY_LEFT_WINDOWS); Keyboard.press(KEY_L); Keyboard.releaseAll(); } void win_unlock_call(void *ptr){ uint32_t win_value; win_val.getValue(&win_value); Keyboard.press(KEY_DOWN_ARROW); Keyboard.releaseAll(); while(win_value>0){ win_val.getValue(&win_value); Keyboard.press(KEY_DOWN_ARROW); Keyboard.releaseAll(); } Keyboard.print("YOUR PIN"); } void mute_button_call(void *ptr){ Keyboard.press(HID_KEYBOARD_LEFT_CONTROL); Keyboard.press(KEYPAD_DOT); Keyboard.releaseAll(); } void read_it(){ if (Serial.available() > 0) { mySt = Serial.readStringUntil("\n"); myString=mySt.substring(0,mySt.length()-1); } info.setText(myString.c_str()); } //---------------------------------------------------------------------- void setup() { nexInit(); Serial1.begin(115200); Volume=EEPROM.read(0); Consumer.begin(); Keyboard.begin(); Mouse.begin(); vol_up.attachPush(vol_upPopCallback, &vol_up); vol_down.attachPush(vol_downPopCallback, &vol_down); prev_button.attachPop(prev_call, &prev_button); toggle_button.attachPop(toggle_call, &toggle_button); next_button.attachPop(next_call, &next_button); //page_up.attachPush(page_up_call, &page_up); //page_down.attachPush(page_down_call, &page_down); win_lock.attachPop(win_lock_call, &win_lock); win_unlock.attachPush(win_unlock_call, &win_unlock); mute_button.attachPush(mute_button_call, &mute_button); vol_dis.setValue(Volume); for (uint32_t i = 0; i <= 200; i++) { delay(5); Consumer.write(MEDIA_VOLUME_DOWN); } vol_dis.setValue(Volume); delay(100); for (uint32_t i = 1; i <= Volume/2; i++) { delay(5); Consumer.write(MEDIA_VOLUME_UP); } vol_dis.setValue(Volume); } // void loop() { nexLoop(nex_listen_list); read_it_action.check(); }