@@ -85,6 +85,7 @@ Arduino_AlvikCarrier::Arduino_AlvikCarrier(){
8585
8686int Arduino_AlvikCarrier::begin (){
8787 beginLeds ();
88+ pinMode (NANO_CHK,INPUT_PULLDOWN);
8889
8990 serial->begin (UART_BAUD);
9091 serial->flush ();
@@ -254,6 +255,7 @@ void Arduino_AlvikCarrier::disconnectExternalI2C(){
254255/* *****************************************************************************************************/
255256
256257int Arduino_AlvikCarrier::beginBMS (){
258+ while (digitalRead (NANO_CHK)==HIGH){}
257259 bms->begin ();
258260 return 0 ;
259261}
@@ -432,17 +434,55 @@ bool Arduino_AlvikCarrier::getTouchKey(const uint8_t key){
432434 return false ;
433435}
434436
435- uint8_t Arduino_AlvikCarrier::getTouchKeys (){
437+ uint8_t Arduino_AlvikCarrier::getTouchKeys (const bool single_touch ){
436438 touch_value=0 ;
437439 if (getAnyTouchPressed ()){
438440 touch_value|=1 ;
439- touch_value|=getTouchOk ()<<1 ;
440- touch_value|=getTouchDelete ()<<2 ;
441- touch_value|=getTouchCenter ()<<3 ;
442- touch_value|=getTouchUp ()<<4 ;
443- touch_value|=getTouchLeft ()<<5 ;
444- touch_value|=getTouchDown ()<<6 ;
445- touch_value|=getTouchRight ()<<7 ;
441+ if (!single_touch){
442+ touch_value|=getTouchOk ()<<1 ;
443+ touch_value|=getTouchDelete ()<<2 ;
444+ touch_value|=getTouchCenter ()<<3 ;
445+ touch_value|=getTouchUp ()<<4 ;
446+ touch_value|=getTouchLeft ()<<5 ;
447+ touch_value|=getTouchDown ()<<6 ;
448+ touch_value|=getTouchRight ()<<7 ;
449+ }
450+ else {
451+ if (getTouchOk ()){
452+ touch_value|=1 <<1 ;
453+ }else {
454+ if (getTouchDelete ()){
455+ touch_value|=1 <<2 ;
456+ }
457+ else {
458+ if (getTouchCenter ()){
459+ touch_value|=1 <<3 ;
460+ }
461+ else {
462+ if (getTouchLeft ()){
463+ touch_value|=1 <<5 ;
464+ }
465+ else {
466+ if (getTouchDown ()){
467+ touch_value|=1 <<6 ;
468+ }
469+ else {
470+ if (getTouchRight ()){
471+ touch_value|=1 <<7 ;
472+ }
473+ else {
474+ if (getTouchUp ()){
475+ touch_value|=1 <<4 ;
476+ }
477+ }
478+ }
479+
480+ }
481+ }
482+ }
483+ }
484+ }
485+
446486 }
447487 return touch_value;
448488}
@@ -693,7 +733,7 @@ void Arduino_AlvikCarrier::updateKinematics(){
693733 if (kinematics_movement==MOVEMENT_ROTATE){
694734 rotate_pid->update (kinematics->getTheta ());
695735 drive (0 , round (rotate_pid->getControlOutput ()/10.0 )*10 );
696- if (abs (rotate_pid->getError ())<ROTATE_THREASHOLD ){
736+ if (abs (rotate_pid->getError ())<ROTATE_THRESHOLD ){
697737 kinematics_achieved=true ;
698738 disableKinematicsMovement ();
699739 drive (0 ,0 );
@@ -702,7 +742,7 @@ void Arduino_AlvikCarrier::updateKinematics(){
702742 if (kinematics_movement==MOVEMENT_MOVE){
703743 move_pid->update ((kinematics->getTravel ()-previous_travel)*move_direction);
704744 drive (round (move_pid->getControlOutput ()/10.0 )*10 , 0 );
705- if (abs (move_pid->getError ())<MOVE_THREADSHOLD ){
745+ if (abs (move_pid->getError ())<MOVE_THRESHOLD ){
706746 kinematics_achieved=true ;
707747 disableKinematicsMovement ();
708748 drive (0 ,0 );
@@ -892,4 +932,21 @@ bool Arduino_AlvikCarrier::isLifted(){
892932 else {
893933 return false ;
894934 }
935+ }
936+
937+
938+
939+ /* *****************************************************************************************************/
940+ /* Utilities */
941+ /* *****************************************************************************************************/
942+
943+ void Arduino_AlvikCarrier::getSerialNumber (char * sn){
944+ uint32_t id[3 ];
945+ id[0 ] = HAL_GetUIDw0 ();
946+ id[1 ] = HAL_GetUIDw1 ();
947+ id[2 ] = HAL_GetUIDw2 ();
948+ uint32_t top = id[0 ]+id[2 ];
949+ uint16_t bottom = (id[1 ]&0xFFFF0000 )>>16 ;
950+ sprintf (sn," %08lx" , top);
951+ sprintf (sn+8 ," %x" ,bottom);
895952}
0 commit comments